B&B Electronics MODSCAN32 - Manual User Manual
Page 92

92
Visual Basic Example
An example Visual Basic project is included with the mbslvocx distribution zip file. This example, 
(Project1), was designed using Visual Basic 5.0 and consists of a single VBA form containing standard text 
controls representing two arrays of modbus data. Defined are twenty HOLDING REGISTERS and thirty 
STATUS COILS which may be read/written from a modbus master.
 
Default settings for the example application operate on COM Port number 1 at 9600 Baud, 8 Data bits, 1 
Stop Bit and no parity. Node address 1 and RTU Transmission mode is used. These default settings are 
easily customized by accessing the modbus_slave property page during design time
 
Operation of the Project1 example begins by opening the selected COM port when the form is loaded and 
defing two blocks of data for access via the connection. If the user changes any data via an edit control, the 
changes are automatically reflected in the data as presented to the modbus master. Project1 uses the 
DataWrittenFromMaster event to redraw the edit controls if the data is changed via the modbus connection. 
 
‘ Public Declarations 
‘ Data to be made accessible via modbus 
 
Dim MyData1(20) As Integer 
Dim MyData2(30 As Integer 
 
‘ Interface & Data Handle Definitions 
 
Dim Interface As Long 
Dim Data1 As Long 
Dim Data2 As Long 
 
‘ Procedure to update the displayed Register values 
 
Public Sub Refresh_Regs() 
 
for i = 0 to 19
Text1(i) = MyData1(i)
Next i
End Sub 
 
‘ Procedure to update display Coil values 
 
Public Sub Refresh_Coils() 
 
for i = 0 to 29
Check1(i).Value = MyData2(i)
Next i
End Sub 
 
‘ If user changes a coil value, update MyArray2 
 
Private Sub Check1_Click (Index As Integer) 
 
MyData2(Index) = Check1(Index).Value
End Sub 
 
‘ If user changes a Register value, update MyData1 
 
Private Sub Text1_Change (Index As Integer) 
 
MyData1(Index) = Text1(Index).Text
End Sub 
 
‘ Open the Interface and create the points 
