App. - 27 App. - 27
MELSEC-Q
APPENDIX
(2) Sample program
The following sample program reads D0 to D4 (five points) of the target PLC
using the logical station number.
(a) When Visual Basic
ยฎ
is used
1) Screen example (Form1)
Command1
' Connect to the communication line.
Command2
' Read the device data.
Command3
' Cut the communication line.
Text1
' Enter the logical station number.
ACT control (ActEasy IF)
' ACT control for utility setting type
2) Program example
Private Sub Command1_Click()
'
' Connection
'
Dim rtn As Long
' Get LogicalstationNumber
ActEasyIF1. ActLogicalStationNumber = Val(Text1.Text)
' Connection
rtn = ActEasyIF1. Open()
If rtn = 0 Then
MsgBox "The connection was successful"
Else
MsgBox "Connection Error:" & Hex(rtn)
End If
End Sub
Private Sub Command2_Click()
'
' Read
'
Dim rtn As Long
Dim idata(5) As Integer
' D0-D4 are read
rtn = ActEasyIF1. ReadDeviceBlock2 ("D0", 5, idata(0))
If rtn = 0 Then
MsgBox "D0-D5 = " & idata(0) & ", " & idata(1) & ", " & idata(2) & ", " & idata(3) & "," & idata(4)
Else
MsgBox "Read Error:" & Hex(rtn)
End If
End Sub