Author Topic: Mono Serial Drivers - DF1 and ModbusRTU  (Read 283 times)

Godra

  • Hero Member
  • *****
  • Posts: 661
    • View Profile
Mono Serial Drivers - DF1 and ModbusRTU
« on: January 13, 2018, 07:55:46 PM »
***  Provided  AS  IS  ***

There is no support for these drivers but do feel free to report bugs and/or provide feedback.

Purely for experimental purposes targeting Mono environment, possibly a good use for Raspberry Pi users ...
Don't be surprised if your program crashes at any point in time or if it remains stable for hours/days/weeks.

These would generally be the steps to follow in order to use these drivers (there are the latest updated dll files as well as ModbusTCP driver in one of the posts below):

-   Update each AHMI project to target Net Framework 4.5 (I have not seen any issues as a consequence of doing this and I did it because both drivers are targeting the same framework)
-   Add the attached dll files as existing item to the AdvancedHMIDrivers/Support folder and reference them both in each AHMI project
-   Rebuild the solution
-   Add the SerialDf1MonoForSLCMicroCom.vb file as existing item to the AdvancedHMIDrivers/AllenBradley folder
-   Add the ModbusRTUMonoCom.vb file as existing item to the AdvancedHMIDrivers/Modbus folder
-   Rebuild the solution
-       These new drivers should show in the Toolbox

Try using fresh AHMI project for all this or a copy of your existing project.

Check the attached picture for controls which appear to be working properly in Mono (some other controls not shown might work as well). This is a screenshot of my test with Raspberry Pi -> USB2RS232 Cable (USB-1761-CBL-PM02) -> MicroLogix 1100 (DF1 on Channel0). I had these devices communicate for hours and the app never crashed.

The latest uploaded C# version of AHMI has these drivers already included ( http://advancedhmi.com/forum/index.php?topic=1937.0 ).

These drivers work in Windows as well but should never really be used instead of the existing AHMI drivers.

DLL's are created to use common components from the AHMI project so try not to use them as standalone.

« Last Edit: February 16, 2018, 05:09:12 PM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 661
    • View Profile
Re: Mono Serial Drivers - DF1 and ModbusRTU
« Reply #1 on: January 16, 2018, 01:56:18 PM »
Both drivers have been updated to include a new property, BackgroundThreadHoldTime, which will determine how fast the serial port receive buffer is checked for new data.

The value range of this property is 1 to 1000 millisecond (default being 5). It should generally be set to lower or equal of the PollRateOverride value.

You might try adjusting this value if your CPU usage shows as high, or if you have issues synchronizing communication with the device, or if you'd like to experiment...

It should always be sufficient to replace old dll files with new, by adding them as existing items, and rebuild the solution.
« Last Edit: January 16, 2018, 03:12:58 PM by Godra »

seth350

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Mono Serial Drivers - DF1 and ModbusRTU
« Reply #2 on: January 25, 2018, 09:48:57 PM »
Thank for the contribution. I too use AHMI on a Raspberry Pi w/ Mono and know first hand how it can be temperamental.
Are you planning to do any work with the CLGX Ethernet driver? I ask because you mentioned high cpu usage. I also experience that with my app using Ethernet driver. The app will truck along at 4% cpu for a good amount of time, then for some reason go up to 60% and after some time go to 100%.


Godra

  • Hero Member
  • *****
  • Posts: 661
    • View Profile
Re: Mono Serial Drivers - DF1 and ModbusRTU
« Reply #3 on: January 26, 2018, 12:33:04 AM »
Pretty much anything Ethernet related would be Archie's domain and he also seems to prefer Windows based PC's to run AHMI.
His programming skills are far more advanced than mine and unless he makes some changes to AHMI Ethernet drivers there will be no changes done by me.

Since you are using this app in Mono environment that makes it rather difficult to troubleshoot.

I cannot really make any suggestion besides for to try turning off or even removing any unnecessary software from your Pi.

seth350

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Mono Serial Drivers - DF1 and ModbusRTU
« Reply #4 on: January 26, 2018, 06:27:10 AM »
Yeah, Archie and I have had the same discussion. I would much rather use a Windows PC but IT says no.

Godra

  • Hero Member
  • *****
  • Posts: 661
    • View Profile
Re: Mono Serial Drivers - DF1 and ModbusRTU
« Reply #5 on: February 04, 2018, 08:52:23 PM »
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).

These drivers should be seen as an alternative option until Archie considers providing his own.

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.
Also try modifying the size of the MaxReadGroupSize property to avoid the flicker or receiving some odd values.

The correct addressing for the 2nd BasicLabel would be: 40001@S20.11.10

« Last Edit: February 17, 2018, 09:55:21 AM by Godra »

DougLyons

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Mono Serial Drivers - DF1 and ModbusRTU
« Reply #6 on: February 05, 2018, 07:23:19 PM »
The ModRSsim2 program has an option in the "Fmt" section for "char string" and for Godra's above example shown this might work better. It shows the actual ASCII characters. Note that "x20" is a space character. Attached below is an example that illustrates this mode with the same values as above except displayed as "char string". You can even use this mode to enter the "char string" ASCII characters directly.

Godra

  • Hero Member
  • *****
  • Posts: 661
    • View Profile
Re: Mono Serial Drivers - DF1 and ModbusRTU
« Reply #7 on: February 10, 2018, 04:49:15 PM »
The ModbusRTUMono driver was updated again and replaced in the previous post.

It can now read/write Modbus 6xxxx extended registers in the same manner as with 4xxxx registers (store strings  or floats or...).

This was tested with MODRSsim2 simulator program since I don't have access to any Modbus device that supports extended registers.
Even though it works with the simulator, I am not sure if this is the correct way for real Modbus devices.
« Last Edit: February 11, 2018, 08:26:47 PM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 661
    • View Profile
Re: Mono Serial Drivers - DF1 and ModbusRTU
« Reply #8 on: February 12, 2018, 11:42:15 PM »
Attached here is a ModbusTCP driver which has the same features as ModbusRTU driver.

Intended solely for Testing and/or Experimenting purposes in either Windows or Mono environment.

The installation steps are the same as described in the very first post (serial drivers or their dll's do NOT need to be installed unless you need them).

Use fresh AHMI project for this.

For those who might have a Modbus device that supports extended registers, try using 6xxxxx addressing format and do provide a feedback of whether it works.

Also attached is a picture of the test screen with MODRSsim2 simulator program as well as the modified BasicLabel control which was used (this particular BasicLabel can just replace the stock control and doesn't require a separate SubscriptionHandler).

The code of the Modbus.dll file was refined and the file was replaced on February 16, 2018. No additional features were added.
« Last Edit: February 16, 2018, 05:16:41 PM by Godra »