Author Topic: Modbus Addressing  (Read 30375 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Modbus Addressing
« on: May 18, 2015, 04:01:07 PM »
Some hints when using Modbus with AdvancedHMI.....

The most common addressing is supported such as:

40001
00001
10001

The default are signed integers, but you can force it to use unsigned by preceding the address by a "U". For example:

U40001

32 bit integers and 32 bit floating point are also supported by using the following prefixes:

F40001
L40001

Keep in mind that you are using 4 bytes, so L40001 may overlap L40002. Based on the device you are using. The consecutive 32 bit values may be L40001 and L40003

If you want to force a particular function number, then specify the function followed by a ":". for example:

3:0001


As of version 3.99b, a new prefix is supported for BCD. For example:

B40001
« Last Edit: July 11, 2016, 08:36:44 AM by Archie »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Modbus Addressing
« Reply #1 on: May 29, 2015, 10:57:58 PM »
Here is a YouTube video which provides general information on Modbus:

https://www.youtube.com/watch?v=k993tAFRLSE

Intended for those, like myself, who would like to understand Modbus a bit better and most of the Archie's points stated above.
« Last Edit: August 06, 2015, 03:27:46 PM by Godra »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Modbus Addressing
« Reply #2 on: May 31, 2015, 11:31:45 AM »
That is actually a good video. I recommend anyone using Modbus to watch the video.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Modbus Addressing
« Reply #3 on: September 02, 2015, 08:32:00 PM »
For those who might be interested, here is a small program for ModbusRTU Slave simulation.

It is somewhat similar to MOD RSSim program but is far from being as functional (and definitely shouldn't be used as a replacement).

The program is using nModbus libraries, which were included as embedded resource so the program could be used as standalone. The slave DataStore can be used offline to set values (before making a connection).

The attached picture shows AHMI being used as master to poll this program (com0com was also used to create paired ports COM2 used by the program, and COM6 used by the AHMI).

See this topic for full solution:

https://www.advancedhmi.com/forum/index.php?topic=2567.0
« Last Edit: January 13, 2020, 11:59:22 PM by Godra »

DougLyons

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Modbus Addressing
« Reply #4 on: September 05, 2015, 04:49:51 PM »
Godra,

On my Windows 7 64-bit laptop the program will not fully display.
See the attached picture for what I get. Also, I am not able to stretch the form to be able to see any more.

I am running the desktop with Medium Text if this might make a difference.
Also double-clicking brings us a Set Cell that and the value cannot be seen.

Doug Lyons
« Last Edit: September 05, 2015, 04:56:31 PM by DougLyons »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Modbus Addressing
« Reply #5 on: September 05, 2015, 05:21:58 PM »
Setting the text size back to 100% should bring the output screen closer to what it should be (check the attached pictures).
I have not tried running it in compatible mode for Windows XP but you can definitely try that.

Solutions have been posted so download and modify whatever you need adjusted. You could possibly just comment out the MaximumSize in the Form1_Load sub in the "Private Methods" region: Me.MaximumSize = New Size(580, 650) to be able to manually re-size the form or just do so in DesignMode and adjust the values.
The same applies for Me.formEditValue.MaximumSize = New Size(160, 54) in the same sub.
« Last Edit: September 05, 2015, 07:00:13 PM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Modbus Addressing
« Reply #6 on: September 05, 2015, 06:53:44 PM »
Doug,

Here is a version for 64-bit Windows that you can try.

Let me know if it works.
« Last Edit: September 16, 2015, 01:49:38 PM by Godra »

DougLyons

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Modbus Addressing
« Reply #7 on: September 05, 2015, 09:06:03 PM »
Godra,

The new 64-bit version now shows all of the main window. The Set Cell popup is still very small like before.
I did not realize that your dropbox links included the solution files for this application until you mentioned it above.
Now I have downloaded them and I will open and experiment with them shortly.

Thanks very much for your suggestions and speedy reply. I always enjoy finding a new Modbus tool.

Doug Lyons

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Modbus Addressing
« Reply #8 on: September 07, 2015, 12:18:09 AM »
Doug,

If you might be interested in getting the Set Value form like it is in attached picture, then just modify the part of the code inside the Form1_Load sub to this:

Code: [Select]
        Me.formButtonOK.DialogResult = vbOKOnly
        Me.formButtonOK.Text = "OK"
        Me.formEditValue.Name = "Set Value"
        Me.formEditValue.Text = "Set Value"
        Me.formEditValue.BackgroundImage = My.Resources.DarkBlue
        Me.formEditValue.Icon = My.Resources.ModbusRTU
        Me.formEditValue.BackgroundImageLayout = ImageLayout.Stretch
        Me.formEditValue.AutoScaleMode = Windows.Forms.AutoScaleMode.None
        Me.formEditValue.MaximumSize = New Size(180, 100)
        Me.formEditValue.MinimumSize = New Size(180, 100)
        Me.formEditValue.StartPosition = Windows.Forms.FormStartPosition.CenterParent
        Me.formEditValue.MinimizeBox = False
        Me.formEditValue.MaximizeBox = False
        Me.formEditValue.SizeGripStyle = Windows.Forms.SizeGripStyle.Hide
        Me.formEditValue.Controls.Add(formTextbox)
        Me.formEditValue.Controls.Add(formButtonOK)
        Me.formTextbox.Size = New Size(60, 25)
        Me.formButtonOK.Size = New Size(52, 25)
        Me.formTextbox.Location = New Point(25, 25)
        Me.formButtonOK.Location = New Point(Me.formTextbox.Width + 45, 23)
        Me.formTextbox.MaxLength = 5
        Me.formButtonOK.UseVisualStyleBackColor = True
        Me.formButtonOK.BringToFront()

You can always adjust the numbers to fit properly on your screen.

Also, once you are to have a working solution for your computer then see if you can post it for other people to be able to download.
« Last Edit: September 07, 2015, 12:42:03 AM by Godra »

DougLyons

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Modbus Addressing-Slave Simulator
« Reply #9 on: September 08, 2015, 12:02:22 AM »
Godra,

I made very few changes to get it to display properly on my Windows 7 machine.
Here are the actual lines that I changed in the Form1_Load Subroutine:

Line 186:
Code: [Select]
        Me.MaximumSize = New Size(800, 850)
Lines 266 & 267:
Code: [Select]
        Me.formEditValue.Size = New Size(200, 75)
        Me.formEditValue.MaximumSize = New Size(200, 80)

Line 276:
Code: [Select]
        Me.formButtonOK.Size = New Size(52, 25)

It should be possible to check the Windows version and if 7 or greater then make the above changes.
If I get a chance I will try and look into this and post the revised code.

One other change I made was to the four DataGridView controls. I changed the Address column (1) to a Width of 125 on each one.
I used a right-click with "Sent to Back" to cycle through the controls, but there may have been a better way.
Otherwise the complete address range was not shown for me.
Also, I think that the column widths for the Input Registers and Holding Registers could be a bit wider as well but I did not change these.

Thanks for your help with this.

Doug Lyons
« Last Edit: September 08, 2015, 12:23:51 AM by DougLyons »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Modbus Addressing
« Reply #10 on: September 10, 2015, 05:47:32 PM »
I have slightly modified the program to include setting slave ID and showing the selected cell address.

Multiple instances of this program can be run and I have managed to run 1 AHMI application polling 2 slaves on the same computer by using 2 ModbusRTUCom drivers and with slaves having IDs of 1 & 2 (com0com was also used with 2 sets of paired ports).

The solutions have been updated and can be downloaded from the links previously posted.

For those using 64-bit Windows and with text size at Medium & Large (125% & 150%) the x64 version has also been updated and replaced.

Attached here is a standalone exe file of the new version.
« Last Edit: September 16, 2015, 03:56:09 PM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Modbus Addressing
« Reply #11 on: September 13, 2015, 05:45:12 PM »
Doug,

I just noticed the same name as yours in the About box of the MOD RSSim v8.21 program (wouldn't be surprised if it is you).
« Last Edit: September 13, 2015, 05:47:09 PM by Godra »

DougLyons

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Modbus Addressing
« Reply #12 on: September 13, 2015, 09:49:23 PM »
Godra,

Yes, I did contribute back to the Mod_RSsim program with some improvements and fixes to create ModRSsim2.
My contributions were only a very small part added onto the original great program which had the last version as Revision 8.20
I liked the features of this program very much, the but I found several small errors in the code.
The original developer seems to have moved on to other work areas and was not responding to BUG reports or emails.
Therefore I took it upon myself to try and fix the errors that I found and add features such as logging to disk.
The result was what is now on SourceForge as ModRSsim2 and I plan to make changes to it to make this program DPI aware.
This was the result of seeing that your program did not display correctly on my 125% magnified desktop.
My older eyes need a bit of help here and there is even another option to use 150% that should be accounted for.
I have been researching what is required to do this and I believe that I have the basis to proceed.
When I am finished I plan to make proposed suggestions to your program to account for these conditions as well.

Thanks for noticing.

Doug Lyons

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Modbus Addressing
« Reply #13 on: September 16, 2015, 01:56:36 PM »
Doug,

Just discovered that the trick is in setting a blank form's AutoScaleMode property to Dpi and then placing all the controls on the form. When done this way the controls will inherit this behavior. It doesn't work if the property is initially set to Font and then, after controls were placed on the form, changed to Dpi (when done this way the controls seem to retain the initial Font setting).

I tried it on 64-bit Windows with 125% and 150% text settings and it works fine (give it a try).

All the files attached in this topic have been replaced and the solutions have been updated as well.

DougLyons

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Modbus Addressing
« Reply #14 on: September 17, 2015, 12:36:09 AM »
Godra,

Great work. Thanks for sharing.
I will definitely check it out, but it may take me a bit because of other involvements.

Thanks again,

Doug Lyons