Com port : Choose the port which you want to communicate.
Baudrate: Parity: Data Bit: Stop Bit: Choose appropriate baudrate for the devices communicate with.
Rcv Time out: The maximum time between sending query to the partner and receiving complete data from it(milisecond). If data receive completed before this period it doesn't wait and executes next process.
Charecter Timeout: Starts working with the first came character after query sent. Every new comer character resets period. When received data number do not increase at this period it decides the string receiving completed. Then starts the operating on the string. Unless you specify the Baudrate to small this period should be stay at 1 ms.
Send Start Delay: Delay time before sending new query after receiving data from the device(milisecond). This function completely concerned with your device. Some devices internal operations takes long time and their communications can be slow. Other case can be that not need high speed communication.
Send String: Modbus algorithm is made up from sending query from master device and respond this query from slave device. Send String is the sent query. This query converts with a specific system then added crc16 and sent through serial port. Sample:0,3,1,18, Program detects the numbers separated by comma.First number "0" is the slave device address. Second number "3" is the fuction code.(It is used as reading a value in the Modbus algorithm) Third "1" is the start address for the reading. Last "18" is the number of registers(variable) to read. Directy value entering to here is disabled. Because it is possible to enter erroneous value. By clicking here the window at the bottom opens and provides entering values correctly. Besides you can reach here and all other values from the software you used ActiveX with. This will be explained Modbus Rtu ActiveX Inputs/Outputs section.
When click on Send string this window opens:
When query created at this window by clicking ok button query transfers send string window automaticaly.
Slave Adress: Enter the device address wanted to communicate.
Function: Function code that requested from the slave device in accordance with Modbus protocol.
Code 1 = Reading Discrate coil requested data.
Code 2 = Reading Discrate input requested data.
Code 3 = Reading Analog holding requested data.
Code 4 = Reading Analog input requested data.
Code 5 = Single coil data writing.
Code 6 = Single analog register data writing
Code 15 = Multiple coil data writing.
Code 16 = Multiple analog register data writing
Start Address: Slave device register start address.
Number of Registers: Indicates register number at the function code 1,2,3,4,15 and 16. This can not be used at function code 5 and 6.
Send String: Data that wanted to send at Function code 6 and 16 can be entered here. When clicked here the window at the bottom will open. At Function code 1,2,3 ve 4 cannot be used.
<- Sub: Erases 1 register from the string that will be sent.
Add ->: Adds 1 register to string which will be sent.
Clear: Erases the string which will be sent completely.
The data wanted to be sent at the Function code 5 can be entered here.When clicked here the window at the bottom will open.
Binary single digit sending function. You can determine the number as 0 or 1 by clicking buttons.
The data wanted to be sent at the Function code 15 can be entered here.When clicked here the window at the bottom will open.
Sends multiple binary digits You can add digits by selecting as 0 or 1.
All 0 Makes all bits 0.
All 1 Makes all bits 1.
<- Sub Erases last variable from the messaging table.
Add -> Adds created variable to the messaging table.
Clear Clears all messaging table.
Send lenght: You can see the data byte number that you want to send at the Function code 5, 6, 15 and 16.
The respond of the query we created above and sent to the slave device is shown here. This is the complete string without crc16. It varies according to function code at the query. For example: 0, 3, 1, 10, response of the query would be 0(Slave address), 3(function code), 20(total data byte number),0(1st.variable),0(2nd variable), 0(3rd variable), 0(4th variable), 0(5th variable), 0(6th variable), 0(7th variable), 0(8th variable), 0(9th variable), 0(10th variable). Green number next to Receive string box is the number of data received correctly. Red number is the erronoeus data number.
Send and Receive button
Sends single query receives single reply.
Automatic Send-Rcv
Continuously send and receives query when Checkbox selected.
Modbus Rtu ActiveX Property
Port_name :
Baudrate :
Parity :
Data_bits :
Stop_bits :
Rcv_timeout :
Char_timeout :
Send_start_delay :
Send_string :
Send_crc16 :
Receive_string :
Rcv_crc16 :
Status_box :
Auto_send_rcv :
Send_receive_button :
Value_status : 1 (true) = Receive complate. 0 (false) = Receive Error.
Receive_complete :
Receive_error :
Good_rcv_cnt :
Bad_rcv_cnt :
Event'lar:
Event rcv_complete(ByVal sender As Object, ByVal e As String)
Event rcv_error(ByVal sender As Object, ByVal e As String)
Event:
Private Sub rcv_error(ByVal sender As Object, ByVal e As String) Handles _ Modbus_rtu1.rcv_error
End Sub
Private Sub rcv_complete(ByVal sender As Object, ByVal e As String) Handles Modbus_rtu1.rcv_complete
Try
Dim str_sp() As String
Dim Value(10) As Integer
str_sp = Split(e, ",")
If str_sp(1) > 4 Then Exit Sub 'Function code output
Dim i As Integer
If str_sp(1) > 2 Then 'Function Code
'Analog Variable
For i = 3 To str_sp.Length - 2
If IsNumeric(str_sp(i)) = True Then
Value(i - 3) = str_sp(i)
End If
Next
Else
'Discrate Variable
For i = 3 To str_sp.Length - 2
If IsNumeric(str_sp(i)) = True Then
Dim read_value As Integer = str_sp(i)
Dim byt As Byte() = BitConverter.GetBytes(read_value)
Dim bit As New BitArray(byt)
Dim i2 As Integer
For i2 = 0 To 7
Value(i - 3) = bit(i2)
Next
End If
Next
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub