I have a program that sends and receives data from pc to OMRON E5EK digital controller (I am using VB .NET), and I have a problem in receiving data from the controller. I suppose that I wrote the correct command, and yet it gives '??' response, when the correct one should give @ character at the beginning of the response and end with CR (Carriage Return).
Here is my program:
Public Class Form1
Dim TX, RXD, FCS As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MSComm1.Settings = "9600,E,7,2"
MSComm1.CommPort = 4
MSComm1.PortOpen = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
TX = "@001000000"
Call GetFCS()
txtRequest.Text = TX + FCS + "*"
Call communicate()
txtResponse.Text = RXD
End Sub
Private Sub GetFCS()
Dim L As Integer
Dim A As String
Dim TJ As String
L = Len(TX)
A = 0
For J = 1 To L
TJ = Mid(TX, J, 1)
A = Asc(TJ) Xor A
Next J
FCS = Hex(A)
If Len(FCS) = 1 Then FCS = "0" + FCS
End Sub
Private Sub communicate()
Try
RXD = ""
MSComm1.Output = TX
RXD = MSComm1.Input
Catch ex As Exception
RXD = "Communication Error"
End Try
End Sub
End Class
Can anybody help me to fix this problem? Thank you!