0

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.

Pspl
  • 1,398
  • 12
  • 23
  • Show us M02FNC000. BTW: Use better names for you methods and fields. These are very hard to read and confusing. – Marko Juvančič Apr 29 '20 at 08:55
  • @MarkoJuvančič, I'm sorry for the names. The program I'm building is so big and has so many routines and variables, that I needed to apply some kind of code to their names. However I should have changed them to this question purposes. There's no `M02FNC000` function. I corrected the question already. – Pspl May 20 '20 at 17:43
  • You're still calling M02FNC000 :) Change the naming style, there's no way for anyone to be able to maintain this code. Even you can't fix it in a simple snippet. – Marko Juvančič May 25 '20 at 14:42

0 Answers0