6-14
<Toc> <Ind>
< 6. Modbus/TCP Communication Protocol>
IM 77C01E01-10E
‘Create sending data
strSendData =
"
123400000006010300000002
"
‘
Sending command character string
‘
‘
‘
‘
‘
‘
‘
‘
Number of D registers (0002:2)
D register start number (0000:D0001)
Function code (03:Reads data from multiple D registers)
Station number of PR300 (01:Station 01)
Number of sending data bytes after station number (0006:6 bytes)
Protocol ID (0000:Fixed)
Transaction ID (1234:Arbitrary 2-byte value)
‘Text
→
Binary change
For iCount = 1 To 12
strCher = “&H” + Mid(strSendData, 2 * iCount - 1, 2)
‘Fetch 2 characters and change them into
hexadecimal notation.
binChrs(iCount - 1) = CByte(Val(strCher))
‘Change them into numerical values.
Next iCount
‘
‘Send sending data
Winsock1.SendData binChrs
‘Send command
‘
End Sub
‘=====================================================================
Private Sub cmdSend2()
‘Procedure to send command to PR300 connected to RS-485 line with PR300 as gateway.
‘
‘Variable declaration
Dim iCount As Integer
Dim strCher As String
‘
‘Set properties of Winsock control
Winsock1.Protocol = sckTCPProtocol
‘TCP protocol
Winsock1.RemoteHost = “192.168.1.1”
‘IP address of PR300 as gateway
Winsock1.RemotePort = 502
‘Port of Modbus/TCP to be used
‘
‘Request TCP connection of PR300
Winsock1.Connect
‘Request TCP connection
Do Until Winsock1.State = sckConnected
‘ Wait for the completion of connection
iFlag = DoEvents()
Loop
‘
Содержание PR300
Страница 141: ......