Write bytes to a PLC device

904 Views Asked by At

I'm working around a connection between a PLC device and my companies PC. The PLC is the known Siemens S7-200 and I'm using vb.NET. Probably I should use another language but vb.NET is the one I'm more comfortable with. To do so, I'm also using a PPI protocol through COM1 and LibNoDave library to establish the connection.

The program I'm testing has to have Input 0.0 On, so I attached a switch to make it happen. Also I made a vb console to read (and write) the state of the Inputs and Outputs (as the LED physical indicators on the device) and also the state of the Bit memories:

console

The console reader (LEITOR section - sorry) is working like I intended and all the Q's, I's and M's are correctly lighting up if it is the case.

The problem is, to run the PLC program, I also have to lit up Q 1.1. The Ladder Network that describes this has the following logical map:

Ladder Network

I know I have to use the code:

Public FDS As libnodave.daveOSserialType             'Serial type
Public DI As libnodave.daveInterface                 'Interface
Public DC As libnodave.daveConnection                'Connection
Public lPPI As Integer = 0                           'Local
Public pPPI As Integer = 2                           'PLC
Public RES As Integer = 0                            'Response
Public REP As Integer = 0                            'Response
Public buf(100) As Byte

Sub Code()
    FDS.rfd = libnodave.setPort("COM1", "9600", AscW("E"))
    DI = New libnodave.daveInterface(FDS, "IF1", lPPI, libnodave.daveProtoPPI, libnodave.daveSpeed93k)
    DI.setTimeout(1000000)
    DC = New libnodave.daveConnection(DI, pPPI, 0, 0)
    RES = DC.connectPLC

    'Write on PLC:
    RES = DC.writeBytes(...
End sub

The code is working fine with no errors and an establish connection (until the last RESponse).

Here's the problem: I can lit up the Output 1.1 (on the device and on the console) by doing the following:

    RES = DC.writeBytes(libnodave.daveDB, 1, 1500, 16, buf)

where

    buf = BitConverter.GetBytes(libnodave.daveSwapIed_16(30))

by repeating these two steps five more times (another time with 30 again, two more times with 50 and, finally, another two times with 50).

I'm pretty sure I'm doing something wrong, but there's not a lot of these commands description available online for a guy like me (who's just got started).

Can anyone explain what's going on? And also, How can I lit Q 1.1 with just one step?

0

There are 0 best solutions below