Author Topic: Ethernet Modbus write  (Read 3464 times)

TimWilborne

  • Newbie
  • *
  • Posts: 9
    • View Profile
Ethernet Modbus write
« on: January 21, 2016, 08:19:17 PM »
I think I've missed something simple.  I've mainly played with monitoring on some live control system until now but today I setup a test PLC to try to learn more and while I can read an address, 400400, over modbus.  I don't seem to be able to write to it.  I've tried a MultiStateSelector and a SelectorSwitch with no luck.  Is there something I need to do to enable writing?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Ethernet Modbus write
« Reply #1 on: January 21, 2016, 10:19:41 PM »
- Add a BasicLabel to the form
- Set PLCAddressKeypad to 400400
- Set PLCAddressValue to 400400
- Run the application
- Click on the BasicLabel

Any control with PLCAddressKeypad will give you a pop up keypad if a valid address is put in that property.

TimWilborne

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Ethernet Modbus write
« Reply #2 on: January 22, 2016, 08:53:31 PM »
Hi Archie.  Sorry for the delay.  I'm still not sure I have the notifications setup right for your forum.  I tested your suggestions and they work great, but is there a way to simply click a button and change a value from 0 to 2?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Ethernet Modbus write
« Reply #3 on: January 23, 2016, 01:52:04 AM »
I tested your suggestions and they work great, but is there a way to simply click a button and change a value from 0 to 2?
Yes, set the OutputType of a BasicButton to WriteValue, then set ValueToWrite

TimWilborne

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Ethernet Modbus write
« Reply #4 on: January 23, 2016, 12:19:38 PM »
Ok I'm starting to get the hang of this.  Next I'd like to reconstruct an HOA I use.  I have a functional HOA, now I would dress it up a little.  Attached is an image of my HOA. 

1.  I would like the text above the HOA to come from some central text location. 
2.  I would like the background color of the button which is currently selected.  If it is in hand, then the hand background is yellow and the others are the screen background color.  If it is in off, the the off background is blue and the others are the screen background color.  And if it is in auto the the auto background is green and the others are the screen background.
3.  Now is where my wish list may get too deep.  Let's say I have 16 outputs.  I only want to make one HOA screen.  And the next and previous buttons would increment and decrement an index number.  This index number would be used to lookup the text above the HOA, determine where the HOAs should write, etc.

What's your thoughts on being able to do this in the AdvancedHMI?

This is completely an experiment for learning based off of other HMIs I've done so if I am way off track on how this should be done in the AdvancedHMI let me know.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Ethernet Modbus write
« Reply #5 on: January 25, 2016, 07:57:27 PM »
If this were me, I would let the PLC do most of the leg work. This is how I would go about it:

- Create an integer register to represent the current selected HOA
- The label at the top would be a MessageDisplayByValue pointing to the register
- Then create 2 boolean registers, one for incrementing and one for decrementing the value above
- Use BasicButtons for Previous and Next with each pointing to the 2 bits defined above

- Create another integer register to represent HOA state
- Use a MultiStateIndicator and add 3 states (Hand, Off, Auto)
- Set PLCAddressValue and PLCAddressClick to that register

In the PLC, as the current selected HOA value changes, the PLC program would move the values of the appropriate HOA state into the register used by the HMI.

TimWilborne

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Ethernet Modbus write
« Reply #6 on: January 30, 2016, 09:57:14 AM »
I've done some evaluating of this and I think you are right, this is a simpler approach.  How about the variable text?  I think I'm missing something simple such as setting up a simple text file that the text can be looked up based off of the same HOA index value.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Ethernet Modbus write
« Reply #7 on: January 30, 2016, 12:36:32 PM »
How about the variable text?  I think I'm missing something simple such as setting up a simple text file that the text can be looked up based off of the same HOA index value.
The MessageDisplayByValue has a Property named IniFileName. A simple text file with the text display definitions can be created, then specified in the IniFileName. This thread gives and example of it's use:

http://advancedhmi.com/forum/index.php?topic=1014.msg5315#msg5315

TimWilborne

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Ethernet Modbus write
« Reply #8 on: January 30, 2016, 01:47:55 PM »
I think I'm understanding, but let me give an example.  In the attached image "Setting00" is a variable string stored in the HMI that describes the setting, then you have the value which is a variable from the PLC then you have the units which is a variable string stored in the HMI.  So for setting 00 I need string SettingText[0], real Setting[0], and SettingUnit[0].

If I'm understanding the display message by value correctly then it wouldn't work unless I could have variable text for the setting value inside the txt file.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Ethernet Modbus write
« Reply #9 on: January 30, 2016, 07:55:28 PM »
This one is a bit different than the HOA example. It sounds like you want to create a "generic" application that is configured through some INI files. The best approach would probably be to create a text file with the configuration then read it on startup and stuff the values into the control properties.

Something along these lines:
Code: [Select]
        Using sw As New System.IO.StreamReader("Configurarion.txt")
            Label1.Text = sw.ReadLine
            Label2.Text = sw.ReadLine
.
.
.
        End Using

TimWilborne

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Ethernet Modbus write
« Reply #10 on: February 01, 2016, 01:16:50 PM »
That's more of what I'm looking for.  But instead of it having to match line by line, would there be a way to search for the variable in the configuration.txt file?  So that the line in the txt could be 'SettingUnit[0]=" minutes"'

rbelknap

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Re: Ethernet Modbus write
« Reply #11 on: February 01, 2016, 03:20:12 PM »
You could use a dictionary object to help with this.

You would add everything in the txt file to the dictionary object and then search the dictionary object for whatever you're looking for.

Something like this:(I'm using a text file for my modbus addressing.)

Code: [Select]
   'Declare the Dictionary for all PAC Tags
    Public ModbusAddressLookup As New Dictionary(Of String, String)
In the load routine:
Code: [Select]
                    'put all of the tagnames in the Dictionary object in Upper case to prevent mismatch due to case
                    ModbusAddressLookup.Add(myRow("Tag Name").ToString.ToUpper, MOD_Prefix & myRow("MODBUS Start Address"))

a Simple Lookup routine:
Code: [Select]
  Private Function LookupModbusAddr(TagName As String) As String
        'Translate the Tagname to the modbus address.
        Dim value As String = ""
        'Make sure we lookup all tags in upper case
        If (ModbusAddressLookup.TryGetValue(TagName.ToUpper, value)) Then
            Return value
        End If
        Return TagName
    End Function

Hope this helps.


TimWilborne

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Ethernet Modbus write
« Reply #12 on: February 03, 2016, 07:29:43 AM »
That is more what I was looking for.  Let me do some experimenting.  Thanks!