Author Topic: Store IP Addresses in a .txt file  (Read 2583 times)

billerl

  • Newbie
  • *
  • Posts: 15
    • View Profile
Store IP Addresses in a .txt file
« on: July 20, 2017, 11:56:01 AM »

First of all, let me thank you for this awesome software package. I am a newbie, so there is probably an easy answer to this, I just don't know it. If I've done something wrong in posting this question, just let me know and I'll know not to do it again. - Thanks



With this code I can change my IP address to whatever I want, and it works fine.[size=78%] [/size]


 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        ModbusTCPCom1.IPAddress = TextBox2.Text

    End Sub
----------------------------------------------------------------------
But if I read the IP address in from a .txt file, it does not work.







Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim search As String
        Dim fileReader As String


        search = TextBox1.Text
        If TextBox1.Text = "" Then


        Else
            fileName = search
        End If
        Try
            fileReader = My.Computer.FileSystem.ReadAllText("C:\folder\" & fileName & ".txt")


            TextBox2.Text = fileReader


            [/size]ModbusTCPCom1.IPAddress = TextBox2.Text
        Catch
            MsgBox("Entry Not Valid")
        End Try
    End Sub


-------------------------------------------------------------------------------------------------
If I use
 PilotLight1.Text = ModbusTCPCom1.IPAddress
it flashes the correct IP address, but also flashes "Com Error -999. No Values Returned from Driver"


Any idea what I'm doing wrong?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI

billerl

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Store IP Addresses in a .txt file
« Reply #2 on: July 20, 2017, 01:27:04 PM »
That is closer to what I want to do. I'd like to use only one driver and just change the IP address based on a selection made from the form.

So how do I accomplish what I'm essentially doing below (that doesn't work)

 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        ModbusTCPCom1.IniFileSection = Driver2

    End Sub

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Store IP Addresses in a .txt file
« Reply #3 on: July 20, 2017, 07:57:49 PM »
The INI file is only read once on startup, so changing the information does not trigger it to update. However, you can force it to like this:

ModbusTCPCom1.IniFileSection = Driver2
ModbusTCPCom1.EndInit()

billerl

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Store IP Addresses in a .txt file
« Reply #4 on: July 21, 2017, 08:27:45 AM »
That works if I make Driver2 a string "Driver2" and it works perfectly in Debug mode.
When i Publish the project I keep getting an error:
"INI File-Unable to locate PLCConfig.ini"
Should I be defining a path like Application.StartupPath for PLCConfig.ini somewhere?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Store IP Addresses in a .txt file
« Reply #5 on: July 21, 2017, 08:50:31 AM »
That is yet another reason why I heavily discourage the use of Publish. Instead use this method:


http://advancedhmi.com/forum/index.php?topic=14.msg9616#msg9616

billerl

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Store IP Addresses in a .txt file
« Reply #6 on: July 21, 2017, 09:18:12 AM »
Perfect!

Thanks Archie - your help has been greatly appreciated.

PS - I do try to search thru the forum for questions before I make a post, I just don't seem to be searching the correct subjects.