read DB by prosim lib in macro

MAHER

Member
Join Date
Jul 2007
Location
CAIRO
Posts
82
Hello

iam trying to read DB by using prosim lib inside excell macro.
I added it in macro
i can get cpu status but
i couldn't use readDBValue method " i got error ( expected function or variable )

Please advise what should i do.

Thanks in advance,
Maher
 
A simplyfied example using a class module (called "PlcsimClass" in this example) for S7Prosim.
Code:
' Add reference to s7wspsmx.dll
Option Explicit

Private WithEvents S7ProSim As S7PROSIMLib.S7ProSim

Private bConnectionError As Boolean
Private lLastError As Long

Public Sub Connect()
    Set S7ProSim = New S7PROSIMLib.S7ProSim
    bConnectionError = False
    S7ProSim.Connect
    S7ProSim.SetScanMode (1) '1=ContinuousScan
    If bConnectionError Then
        MsgBox "Connection to Plcsim failed!"
        Debug.Print "Error: Connection to Plcsim failed!"
    End If
End Sub

Public Sub Disconnect()
    S7ProSim.Disconnect
    Set S7ProSim = Nothing
End Sub

Public Function ReadWordFromDatablock(dbNumber, byteIndex)
    Dim retval As Variant
    Call S7ProSim.ReadDataBlockValue(dbNumber, byteIndex, 0, 3, retval)
    ReadWordFromDatablock = retval
End Function

Private Sub S7ProSim_PauseStateChanged(ByVal NewState As String)
    DoEvents
End Sub

Private Sub S7ProSim_ScanFinished(ByVal ScanInfo As Variant)
    DoEvents
End Sub

Private Sub S7ProSim_PLCSimStateChanged(ByVal NewState As String)
    DoEvents
End Sub

Private Sub S7ProSim_ConnectionError(ByVal ControlEngine As String, ByVal error As Long)
    DoEvents
    bConnectionError = True
    lLastError = error
End Sub

Private Sub S7ProSim_ScanModeChanged(ByVal NewState As String)
    DoEvents
End Sub
And using this class with
Code:
Public Sub Test()
    Dim val As Variant
    Set p = New PlcsimClass
    p.Connect
    val = p.ReadWordFromDatablock(100, 4)
    Debug.Print "val = " & val
    p.Disconnect
End Sub
The third parameter of ReadDataBlockValue() is the value from the enum "PointDataTypeConstants". 3 stands for S7_Word, for other values see documentation of S7ProSim.
 
thank you for your support Thomas

but i tried to run this code but the macro is hanging ( braeking down )

i dont why, could you give me a detailed steps for using it may be i am doing something wrong

thanks for your cooperation.

Regards,
Maher
 
I've attached a sample Excel file with this code.
Maybe you have to renew the vba project reference to s7wspsmx.dll if you are using a 64 bit OS.
 

Similar Topics

When I try to write a PIW to a simulated PLC in PLCSIM, I get a Data Type Error. Code...
Replies
14
Views
9,189
Hi, The hardware is: Click Plc model # CO-O1DD1-O HMI model # S3ML-R magnetic-inductive flow meter model # FMM100-1001. I will set the flow meter...
Replies
4
Views
165
Is there a way to use the FAL instruction to do +=2 instead of +=1? I have an array that is organized with alternating "data" and "flag" values...
Replies
5
Views
127
Hi everyone i have a customer, who wants to show an alarm on the machine, if the I/O forces are enabled and set, on at ControlLogix L81E with...
Replies
3
Views
266
Hi Iam using monitouch hmi(V9 soft) with omron plc cj2m (CX programmer). In this I want to read a data from hmi to plc. The data was like...
Replies
0
Views
104
Back
Top Bottom