senthil@spk
Member
Hi,
I am trying to communicate with PLC5 through VB.Net using DF1 protocol. To start with I am trying to get the plc to echo the data what I send. Here is the code that I am trying,
Dim DLE, STX, ETX, BCC As Byte
Dim DST, SRC As Byte
Dim TNSH, TNSL As Byte
Dim CMD, STS, FNC As Byte
Dim DATA As Byte
Dim R1, R2 As Byte
DLE = &H10
STX = &H2
DST = &H1
SRC = &H0
CMD = &H6
STS = &H0
TNSL = &H5
TNSH = &H0
FNC = &H0
DATA = &H64
ETX = &H3
BCC = &H9B
Dim TS() As Byte = {DLE, STX, DST, CMD, STS, TNSH, TNSL, FNC, DATA, ETX, BCC}
R1 = &H0
R2 = &H0
Dim RS() As Byte = {R1, R2}
Dim RS232 As New IO.Ports.SerialPort
RS232.PortName = "COM3"
RS232.BaudRate = 19200
RS232.DataBits = 8
RS232.StopBits = IO.Ports.StopBits.One
RS232.Parity = IO.Ports.Parity.None
If (RS232.IsOpen = False) Then
RS232.Open()
End If
RS232.Write(TS, 0, 10)
Threading.Thread.Sleep(500)
RS232.Read(RS, 0, 1)
RS232.Close()
MsgBox(RS(0).ToString)
MsgBox(RS(1).ToString)
I am trying to get the inital acknowledgement from the plc, but when the control comes to the read, it times out, without any reply.
I will appreciate if anybody who have experience with DF1 can help me out to find what I am doing wrong.
Thanks for the help in advance.
Regards.
I am trying to communicate with PLC5 through VB.Net using DF1 protocol. To start with I am trying to get the plc to echo the data what I send. Here is the code that I am trying,
Dim DLE, STX, ETX, BCC As Byte
Dim DST, SRC As Byte
Dim TNSH, TNSL As Byte
Dim CMD, STS, FNC As Byte
Dim DATA As Byte
Dim R1, R2 As Byte
DLE = &H10
STX = &H2
DST = &H1
SRC = &H0
CMD = &H6
STS = &H0
TNSL = &H5
TNSH = &H0
FNC = &H0
DATA = &H64
ETX = &H3
BCC = &H9B
Dim TS() As Byte = {DLE, STX, DST, CMD, STS, TNSH, TNSL, FNC, DATA, ETX, BCC}
R1 = &H0
R2 = &H0
Dim RS() As Byte = {R1, R2}
Dim RS232 As New IO.Ports.SerialPort
RS232.PortName = "COM3"
RS232.BaudRate = 19200
RS232.DataBits = 8
RS232.StopBits = IO.Ports.StopBits.One
RS232.Parity = IO.Ports.Parity.None
If (RS232.IsOpen = False) Then
RS232.Open()
End If
RS232.Write(TS, 0, 10)
Threading.Thread.Sleep(500)
RS232.Read(RS, 0, 1)
RS232.Close()
MsgBox(RS(0).ToString)
MsgBox(RS(1).ToString)
I am trying to get the inital acknowledgement from the plc, but when the control comes to the read, it times out, without any reply.
I will appreciate if anybody who have experience with DF1 can help me out to find what I am doing wrong.
Thanks for the help in advance.
Regards.