Author Topic: How to change IP Address in run time  (Read 905 times)

rn

  • Newbie
  • *
  • Posts: 1
    • View Profile
How to change IP Address in run time
« on: November 13, 2019, 03:12:29 AM »

Hi there,
 
Currently, I am working on a SCADA project and one of my client's requirement is to have a run multiple PLCs on HMI screen by writing IP address.

I just want to ask that how can I make the option for writing IP address of PLC in run time on the HMI screen so that he can get connected to the desired PLC

Regards
TAFSOL Technologies Pvt Ltd,


Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: How to change IP Address in run time
« Reply #1 on: November 13, 2019, 08:06:25 PM »
Maybe drop a ComboBox on the form, populate its "Items" collection with predetermined IP addresses, having the first address be the one it connects to when the application starts, then double-click the ComboBox to get to its SelectedIndexChanged event and add code to change the driver's IPAddress, similar to this:

Code: [Select]
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        Me.ModbusTCPCom1.IPAddress = ComboBox1.SelectedItem
    End Sub

You might also add some code to the MainForm Load event:

Code: [Select]
    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'Either
        Me.ComboBox1.SelectedIndex = 0

        'Or
        For Each item In Me.ComboBox1.Items
            If item.ToString = Me.ModbusTCPCom1.IPAddress Then
                Me.ComboBox1.SelectedIndex = Me.ComboBox1.Items.IndexOf(item)
            End If
        Next
    End Sub
« Last Edit: November 13, 2019, 08:19:39 PM by Godra »