Hi all,
first of all, i want you to know that i'm a complete newbie to VB .NET. I just find it fascinating what the possibilities are, that's why im trying to learn it a little bit.
Now, for the explanation of my problem. I'm trying to create a piece of software that connects to a PLC (Siemens S7-300) through TCP and then fetches data every 2 seconds.
The TCP connection is not a problem, that works fine. I also can send and read data to/from the PLC. The problem now is that i want to get/send the data every 2 seconds. (for visualization purposes).
At the moment my read actions are attached to a button.
The code is like:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Algemeen.ReadTCP()
TextBox2.Text = Algemeen.myReadBuffer(0).ToString("x2")
End Sub
And the code in ReadTCP is
Shared Sub ReadTCP()
If TCPClient.Connected = True Then
Algemeen.Stream = TCPClient.GetStream()
If Algemeen.Stream.CanRead = True Then
Algemeen.Stream.BeginRead(Algemeen.myReadBuffer, 0, 1024, New AsyncCallback(AddressOf ReadCallback), Algemeen.Stream)
End If
End If
End Sub
I've already experimented with stream.dataavailable but had no succes so far.
Is there anyone here who could help me on the right way? I'm not asking for a solution, because i want to learn it the hard way. But if someone could give me directions where i need to begin
to accomplish this, it would be wonderful!!!
Tnx in advance
Nico
first of all, i want you to know that i'm a complete newbie to VB .NET. I just find it fascinating what the possibilities are, that's why im trying to learn it a little bit.
Now, for the explanation of my problem. I'm trying to create a piece of software that connects to a PLC (Siemens S7-300) through TCP and then fetches data every 2 seconds.
The TCP connection is not a problem, that works fine. I also can send and read data to/from the PLC. The problem now is that i want to get/send the data every 2 seconds. (for visualization purposes).
At the moment my read actions are attached to a button.
The code is like:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Algemeen.ReadTCP()
TextBox2.Text = Algemeen.myReadBuffer(0).ToString("x2")
End Sub
And the code in ReadTCP is
Shared Sub ReadTCP()
If TCPClient.Connected = True Then
Algemeen.Stream = TCPClient.GetStream()
If Algemeen.Stream.CanRead = True Then
Algemeen.Stream.BeginRead(Algemeen.myReadBuffer, 0, 1024, New AsyncCallback(AddressOf ReadCallback), Algemeen.Stream)
End If
End If
End Sub
I've already experimented with stream.dataavailable but had no succes so far.
Is there anyone here who could help me on the right way? I'm not asking for a solution, because i want to learn it the hard way. But if someone could give me directions where i need to begin
to accomplish this, it would be wonderful!!!
Tnx in advance
Nico