I'm working with a Siemens PLC SIMATIC S7-200
and also a VB.NET
program to communicate with it (and using libnodave
library for that).
I am quite familiar with all this, but I can't figure out a couple of things and I'm hoping some of you could help me. Let me try to explain:
After establish all comunications
Public POSERL As libnodave.daveOSserialType
Public PINRTF As libnodave.daveInterface
Public PCNCTR As libnodave.daveConnection
Public PRES00 As Integer = 0
Public Sub M02SUB000()
POSERL.rfd = libnodave.setPort("COM1", 9600, AscW("E"))
PRES00 = POSERL.rfd
PINRTF = New libnodave.daveInterface(POSERL, "IF1", 0, libnodave.daveProtoPPI, libnodave.daveSpeed93k)
PINRTF.setTimeout(1000000)
PCNCTR = New libnodave.daveConnection(PINRTF, 2, 0, 0)
End Sub
I try to read the byte M0
with the following:
Public PRES01 As Integer = 0
Public PBUF01() As Byte
Public PM0 As Byte
Public PFLG00 As Boolean = False
Public PFLG01 As Boolean = False
Public PFLG02 As Boolean = False
'...
Public PFLG07 As Boolean = False
Public Sub M02SUB001()
PRES01 = PCNCTR.readBytes(libnodave.daveFlags, 0, 0, 1, PBUF01)
If PRES01 = 0 Then
PM0 = Str(PCNCTR.getS8)
If M02FNC000(PM0, 0) Then PFLG00 = True Else PFLG00 = False
If M02FNC000(PM0, 1) Then PFLG01 = True Else PFLG01 = False
If M02FNC000(PM0, 2) Then PFLG02 = True Else PFLG02 = False
'...
If M02FNC000(PM0, 7) Then PFLG07 = True Else PFLG07 = False
End If
End Sub
Public Function M02FNC001(ByVal InByte As Byte, ByVal InBit As Byte) As Boolean
Return ((InByte And (2 ^ InBit)) > 0)
End Function
Here is where I get an error (on some circumstances). I pinpointed the problem to the PCNCTR.getS8
code which is -81
. How can I turn -81
to a byte?? I'm using M02FNC001
function to do it, but this is the part I don't understand so well.
So, to clear some things up, is -81
a normal value for the output of PCNCTR.getS8
? And, if so, how can I transform it to a byte?
Thanks.