Mitsubishi Electronics MELSEC-F Universal Remote User Manual


 
App - 17
MELSEC-F
APPENDIX
App - 17
Dim RxResponse As String
Dim Temp As String
Dim j As Integer
Dim Dreg(5) As Double
Dim DregStr$
Dim SubHeader$
' IP Address specification
IpAddress = "172.16.56.99"
' Port Number specification
PortNum = 10000
Client = New TcpClient
'Line connection processing
Try
Client.Connect(IpAddress, PortNum)
Catch ex As Exception
MsgBox("Connection with the server failed, and the following code was returned:
"& ex.Message, 0, "connection error")
Exit Sub
End Try
'Read D0 to D4 (5 points) with the A-compatible 1E frame command.
TxCommand = "01ff000a4420000000000500"
Buffer = System.Text.Encoding.Default.GetBytes(TxCommand.ToCharArray)
'Sending a read command
Client.GetStream().Write(Buffer, 0, Buffer.Length)
'Waiting for a response from an Ethernet block
While Not Client.GetStream().DataAvailable()
Application.DoEvents()
End While
If Client.GetStream().DataAvailable() Then
Client.GetStream().Read(InBuff, 0, InBuff.Length)
RxResponse = System.Text.Encoding.Default.GetString(InBuff)
SubHeader = Mid$(RxResponse, 3, 2)
If SubHeader = "00" Then 'Normal response
Temp = "" 'Initialization of an output character string
For j = 0 To 4
DregStr$ = Mid(RxResponse, j * 4 + 5, 4)
Dreg(j) = Val("&H" + DregStr$)
Temp = Temp + Format(Dreg(j), "#####0") + " "
Next
lstOutput.Items.Insert(lstOutput.Items.Count, Temp)
ElseIf SubHeader = "5B" Then ' In an abnormal response, an abnormal code is added.
Temp = "Terminate Code = " & SubHeader & " Error Code = " & Mid$(RxResponse, 5, 2)
lstOutput.Items.Insert(lstOutput.Items.Count, Temp)
Else
Temp = "Terminate Code = " & SubHeader
lstOutput.Items.Insert(lstOutput.Items.Count, Temp)