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

Godra

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

These drivers should be seen as an alternative option until Archie considers providing his own (<< AHMI drivers from 3.99y+ version have been updated to support Mono so try them first).

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.

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.

Maybe try the updated version of these drivers, found in Reply #5.

« Last Edit: September 18, 2019, 12:30:30 AM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • 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

  • Jr. Member
  • **
  • Posts: 51
    • 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: 1447
    • 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

  • Jr. Member
  • **
  • Posts: 51
    • 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: 1447
    • 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).

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.
« Last Edit: June 22, 2019, 09:39:15 PM by Godra »

DougLyons

  • Jr. Member
  • **
  • Posts: 68
    • 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: 1447
    • 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 6xxxxx 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: April 21, 2018, 01:45:23 PM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • 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).
« Last Edit: March 06, 2018, 11:34:59 PM by Godra »

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: Mono Serial Drivers - DF1 and ModbusRTU
« Reply #9 on: March 03, 2018, 07:49:58 PM »
Nice work , Godra.

I have not gotten back to this yet.
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Mono Serial Drivers - DF1 and ModbusRTU
« Reply #10 on: May 27, 2018, 12:21:23 PM »
For seth350 and anybody else who might like to try it, there is an application called cpulimit which might help with high cpu usage in linux:

https://www.maketecheasier.com/limit-cpu-usage-of-any-process-in-linux/