ModbusRTUMono driver has been updated again and attached in this post along with DF1Mono driver (they are in this post just in case if I missed some bugs).
New features are String reading/writing as well as Bit reading/writing.
Do note that bit count starts at 0 while character count starts at 1.
Currently, the driver's Subscribe/Read/BeginRead/Write/BeginWrite functions seem to be working properly.
Here are some examples:
ModbusRTUMonoCom1.Subscribe("40001", 2, 250, AddressOf PolledDataReturnedRTU) <- Subscribe to reading of 2 Words starting at address 40001
ModbusRTUMonoCom1.Subscribe("40001.5", 35, 250, AddressOf PolledDataReturnedRTU) <- Subscribe to reading 35 bits starting at bit 5 of address 40001
The above example for Bit reading should work with F, L and U prefixes as well.
Dim v0() As String = ModbusRTUMonoCom1.Read("40001@S20.5", 5) <- Read 5th character of each of 5 consecutive strings (each string 20-character long)
Dim v1() As String = ModbusRTUMonoCom1.Read("40001@S20", 5) <- Read 5 consecutive 20-character long strings (or this as below example)
Dim v1x As String = ModbusRTUMonoCom1.Read("40001@S100") <- Read 100-character long string
Five 20-character long substrings of this string would be equivalent of the example above ie. v1x.Substring(20.20) = v1(1) or
v1x.Substring(20.20) = v2(0) from the example below
Dim v2() As String = ModbusRTUMonoCom1.Read("40001@S100.21.20", 1) <- Read 20-character long substring starting at 21st character of 100-character long string
ModbusRTUMonoCom1.BeginRead("40001@S20.5.3", 5) <- BeginRead of 3-character long substring starting at 5th character of each of 5 consecutive strings (each string 20-character long)
ModbusRTUMonoCom1.Write("40021@S20", "Single String")
ModbusRTUMonoCom1.Write("40021@S20", New String() {"Single String Array"})
ModbusRTUMonoCom1.Write("40021@S20", New String() {"Multiple", "String", "Array"})
ModbusRTUMonoCom1.Write(New ModbusRTUMonoDriver.ModbusMonoAddress("40021@S20"), New String() {"Single String Array"})
ModbusRTUMonoCom1.Write(New ModbusRTUMonoDriver.ModbusMonoAddress("40021@S20"), New String() {"Multiple", "String", "Array"})
ModbusRTUMonoCom1.BeginWrite("40021@S20", 1, New String() {"Single String Array"})
ModbusRTUMonoCom1.BeginWrite("40021@S20", 3, New String() {"Multiple", "String", "Array"})
Each Modbus register holds 2 characters, so a 5-character long string will have to be stored in 3 consecutive 4xxxxx registers. Because of this you should always specify even length string ex. S20 (if you specify it as odd ex. S5 you will still get even number of characters returned).
In order to maintain the correct length, strings are padded with spaces, so use Trim function if needed (ex. Dim str As String = v1(0).Trim where v1() is as described above).
There might be bugs, do report them as well as provide feedback.
Use the attached modified BasicLabel for both Bit/String reading/writing.
Attached is a screenshot that shows string reading with ModRSsim2 program in Windows (com0com paired ports COM1-COM11 were used for this).
Possible "Flicker" related note: try not to subscribe to sub-range of the already subscribed to range (or have any overlapping).
Here is an example:
- 1st BasicLabel control has address of 40001@S20 (this range includes 40001 to 40010 addresses to cover the requested 20-character string)
- 2nd BasicLabel control has address of 40006@S10 (this range includes 40006 to 40010 addresses to cover the requested 10-character string)
This 2nd BasicLabel will probably have flicker because its range is already covered by the range of the 1st BasicLabel.
The correct addressing for the 2nd BasicLabel would be: 40001@S20.11.10
Also try modifying the size of the MaxReadGroupSize property to avoid the flicker or receiving some odd values.