Author Topic: Modbus RTU test screen  (Read 1426 times)

Darrell

  • Full Member
  • ***
  • Posts: 198
  • Electrician / PLC Technician
    • View Profile
Modbus RTU test screen
« on: August 03, 2016, 09:13:05 PM »
I have built a Hmi that I use to read different modbus addresses from time to time on different PLC's
Added code to the button to read the text box and change modbus address in the corresponding PilotLight plc address along with the text label so I know what address is being read to turn on the pilot light ,

PilotLight1.PLCAddressValue = TextBox1.Text
PilotLight1.Text = PilotLight1.PLCAddressValue


my question is how can I easily add a button that would populate all my text boxes at once and increment each one by 1 or .1.      40001 , 40002, or 40001.1 , 40001.2 etc

Darrell
« Last Edit: August 04, 2016, 01:44:22 AM by Darrell »

DanieLoche

  • Guest
Re: Modbus RTU test screen
« Reply #1 on: August 04, 2016, 04:09:09 AM »
You want them to increment regularly once you pressed on the button, or increment only one time, each time you press the button ?

The base is the same, the difference is that in the first case the code will be with a timer, and pressing the button (click event) enables the timer.
In the second option, the code is directly at click event.

You should have to go through all you text boxes. If they are all directly included to your form it's quite simple with a For Each :
Now that you have every text box, I suppose that you have to go to a ToInt (or something like that..), so that you can increment the value. And then put it again as a String (of 5 digits, to be sure to get the 00001 PLC adresses OK too).

Code: [Select]
For Each txtzone in MyForm.Controls
    If txtzone.type Is textboxe.type Then
        Dim Address as Int = Convert.ToInt32(txtzone.text) + 1
        Dim newText =Address.ToString("D5")
        txtzone.txt = newText
    End If
Next txtzone

Darrell

  • Full Member
  • ***
  • Posts: 198
  • Electrician / PLC Technician
    • View Profile
Re: Modbus RTU test screen
« Reply #2 on: August 04, 2016, 01:50:14 PM »
What I would like to do is populate lets say textBox 1 through 15 with a number all at once , but increment each one by 1 or .1 . This HMI will not be left permanently on any machine , it is strictly for someone use to setup and monitor modbus comms during commissioning of systems . Trying to make something that can easily moved around without having to create new HMI's for every one.

Darrell

DanieLoche

  • Guest
Re: Modbus RTU test screen
« Reply #3 on: August 05, 2016, 05:12:22 AM »
Ah okay understand now. :)

It's almost the same principle :
Code: [Select]
Dim baseAddressStr As String = "40000"
For Each txtzone in MyForm.Controls
    If txtzone.type Is textbox.type Then
        Dim newAddressInt as Int = Convert.ToInt32(baseAddress) + 1
        baseAddressStr =Address.ToString("D5")
        txtzone.txt = baseAddress
    End If
Next txtzone

This is going to populate all you text boxes with an adress.
You can add a second button to change those addresses for a .1 increment easily :
Code: [Select]
Dim baseAddress As string = "40000"
For Each txtzone in MyForm.Controls
    If txtzone.type Is textbox.type Then
        Dim Address as Int = Convert.ToInt32(txtzone.text) + 0.1
        txtzone.txt =Address.ToString("D5")
    End If
Next txtzone
« Last Edit: August 05, 2016, 05:13:59 AM by DanieLoche »

Darrell

  • Full Member
  • ***
  • Posts: 198
  • Electrician / PLC Technician
    • View Profile
Re: Modbus RTU test screen
« Reply #4 on: August 05, 2016, 11:23:36 AM »
I get this error and really don't know what it means

DanieLoche

  • Guest
Re: Modbus RTU test screen
« Reply #5 on: August 05, 2016, 11:49:21 AM »
Oh my bad, I should have opened Visual Studio to see the exact methods to call.

Here is the right way to right it :
Code: [Select]
If textzone.GetType = GetType(TextBox) Then
...
End If

... ".Type" do not exist actually. ^_^