Author Topic: Writing a string value to Controllogix tags  (Read 6676 times)

Peter

  • Newbie
  • *
  • Posts: 3
    • View Profile
Writing a string value to Controllogix tags
« on: November 12, 2013, 01:31:26 PM »
Hopefully, this is a simple enough to solve.

I was testing the software and could not find a way to send a string or DINT value to a Controllogix PLC connected via ethernetIP.

Say, I want to write "Hello" to a tag called "Test_String" ; or write "500" to a tag called "Test_Number", when a bit turns on.

I was able to set up communication and read values and display them in a meter control, but how do you write something ?

Thanks.

dmroeder

  • Global Moderator
  • Full Member
  • *****
  • Posts: 208
    • View Profile
Re: Writing a string value to Controllogix tags
« Reply #1 on: November 12, 2013, 02:50:33 PM »
Add a button to your form and double click it to get to the code view (to write something). Add:

Code: [Select]
EthernetIPforCLXCom1.Write("Test_String", "Hello")

edit:  So do you really want to write to a tag in the based on an input from the PLC (like the state of a bit)?  It would seem that the logically this should just take place in the PLC.  Nothing wrong with displaying status with AdvancedHMI, and nothing wrong with Writing data to the PLC with AdvancedHMI.  It just seems like the combination of the two is extra unnecessary work when the PLC could just do it.  Or maybe I'm just misunderstanding what you are trying to accomplish.
« Last Edit: November 12, 2013, 03:04:53 PM by dmroeder »

Peter

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Writing a string value to Controllogix tags
« Reply #2 on: November 12, 2013, 04:08:21 PM »
Thanks! It works!

I need a little addition: (Test_Bool is a controller scoped bit)
Quote
If Test_Bool = 1, then
EthernetIPforCLXCom1.Write("Test_String", "Hello")

Is that possible by any chance ?


I didn't mention the whole idea earlier.
I am logging part data to a database. I have a few basic cameras which save images of the current part to a computer. I need to somehow tie that image to the part data.
To solve this, I want to send the name of the file to the PLC, who ties the filename to the part number in a UDT. This info is then stored to a database.
I could have logged to the database directly from the HMI, but since I don't know how and since that part is being worked on by another programmer, I can't change that too much.
« Last Edit: November 12, 2013, 04:17:20 PM by Peter »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: Writing a string value to Controllogix tags
« Reply #3 on: November 12, 2013, 06:33:34 PM »
You will need to tell it to read the Test_bool from the PLC, so you could do something like this
Code: [Select]
Dim Test_Bool as string
Test_Bool=EthernetIPforCLXCom1.Read("Test_Bool")
If Test_Bool = "True" Then EthernetIPforCLXCom1.Write("Test_String", "Hello")

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: Writing a string value to Controllogix tags
« Reply #4 on: November 12, 2013, 06:49:23 PM »
If you are wanting to watch a bit and write data when it changes, then the DataSubscriber component can do a lot of the leg work for you.

- Add a DataSubscriber to your form from the Toolbox
- Put your bit address in the PLCAddressValue property
- Double click to get to the DataChanged event handler
- Add this code:
Code: [Select]
If e.Values(0) = "True" Then EthernetIPforCLXCom1.Write("Test_String", "Hello")

Peter

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Writing a string value to Controllogix tags
« Reply #5 on: November 12, 2013, 09:37:44 PM »
I understand.
Thanks Archie, I am not good with coding and had no idea what the DataSubscriber control meant until now.