beautypg.com

Yokogawa PR300 Power and Energy Meter User Manual

Page 107

background image

< 6. Modbus/TCP Communication Protocol>

6-13

IM 77C01E01-10E

Example of the Program Created Using Visual-BASIC Version 6.0

In this sample program, command sending and response receiving are carried out by the
method for connection and sending and SendData method of Winsock control.

Preparation

Since this sample program uses Winsock control, it is necessary to assign the
Microsoft Winsock Control component. Refer to the user’s manual of Visual-Basic for
how to assign the component.

Sample Program

Normal status check, error processing and retry processing are omitted for this proce-
dure.

The program does not operate by the procedure described in this section only. Please
make it reference at the time of actual application creation.

‘Variable declaration

Option Explicit

Dim strSendData As String

‘Sending data

Dim strReceive As String

‘Received data

Dim binChrs(11) As Byte

‘Binary data

Dim iFlag As Integer

‘Flag of wait for completion

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

Private Sub cmdSend1()

‘Procedure to connect with PR300 by TCP/IP and to create/send data.

‘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 to be connected

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