PLC values sending to a PC

K

Thread Starter

khkertje

Hello,

I have to make a program in VB 2005 that reads short values that I send from a PLC with Modbus TCP/IP.
The PLC has an IP address and also a port number.
Does somebody have a code so I can read the values in VB 2005 so I can show that on a screen and save those values?

Thanx.
 
<p>I think I need to use this code from that side:
<pre>
using (TcpClient client = new TcpClient("127.0.0.1", 502))
{
ModbusIpMaster master = ModbusIpMaster.CreateTcp(client);

// read five input values
ushort startAddress = 100;
ushort numInputs = 5;
bool[] inputs = master.ReadInputs(startAddress, numInputs);

for (int i = 0; i < numInputs; i++)
Console.WriteLine("Input {0}={1}", startAddress + i, inputs ? 1 : 0);
}

// output:
// Input 100=0
// Input 101=0
// Input 102=0
// Input 103=0
// Input 104=0
</pre>

<p>And I made this:
<pre>
orts System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.IO

Module Module1

Sub Main()

Dim client As TcpClient = New TcpClient("192.168.131.44", 502)

'code for modbus

Dim startAddress As Short = 3000
Dim numInputs As Short = 100
Dim i As Integer = 0
'code for read inputs

If i < numInputs Then
Console.WriteLine("Input {0}= {1}")
'the rest of the code to write the values
Return
End If

End Sub

End Module
</pre>

<p>As you see there are a few things I can't find.
Can someone help me with the missing code?
 
Top