Yokogawa PR300 Power and Energy Meter User Manual

Page 109

Advertising
background image

<Toc> <Ind>

< 6. Modbus/TCP Communication Protocol>

6-15

IM 77C01E01-10E

‘Create sending data

strSendData =

"

123400000006020300000002

"

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 (02:Station 02)

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

Winsock1.SendData binChrs

‘Send command

End Sub

‘=====================================================================

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

‘Receive data from PR300 and cut connection with PR300.

Dim binData() As Byte

Dim iCount As Integer

Dim strCher As String

‘Receive data

Winsock1.GetData binData

‘Receive command

‘Binary change

Text

For iCount = 0 To bytesTotal -1

strCher = Right(Hex(binData(iCount)), 2)

‘Change every byte into a

character string.

If Len(strCher) = 1 Then

strReceive = strReceive + “0” + Mid(strCher, 1, 1)

‘Add 0 if it becomes one

character after change

Else

strReceive = strReceive + strCher

End If

Next iCount

‘Cut TCP connection

Winsock1.Close

End Sub

Advertising