Author Topic: Writing a large number of tag values at once  (Read 1595 times)

timryder

  • Jr. Member
  • **
  • Posts: 83
  • Still trying to figure it out
    • View Profile
Writing a large number of tag values at once
« on: September 12, 2017, 01:12:10 PM »
Doing an application where I need to send down a bunch of Real Numbers to a micro800 plc on a button_press event.

I noticed that there are two different types of Writes for the Com component.  There is plain .Write and then there is .BeginWrite.

I have 32 tags to write down, which in the plc is actually an array of 32 different real numbers. Ex:  PartCoordinatesX[1...32]
also PartCoordinatesY[1...32].

What is the best way to accomplish this? I can loop through until it's done but how do you get a synchronous feed back that the data was sent successfully? Is there any handshake like that? 

OR does the BeginWrite which has arguments of "startAddress, Number of Elements" seem like the better option.  In either case, whats the best course here?  And also is there some synchronous mode to write data into the plc which gives me feedback?

Thanks in advance!
Still just trying to figure out this thing called Life.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5260
    • View Profile
    • AdvancedHMI
Re: Writing a large number of tag values at once
« Reply #1 on: September 12, 2017, 03:29:16 PM »
The BeginWrite is asynchronous meaning that it will queue the request and immediately return to your code. This keeps from holding up the UI thread while the write is being attempted. The down side is that it is up to you to regulate the speed of the writes so you do not overflow the queue. For 32 values being written individually, it would amount to about 320ms which would not be very noticeable to the person clicking the button.

If your values are in an array, it is better to use Write(startAddress, numberOfElements, values()) because it will write them in a single packet which takes only about 10ms. If the UI delay is of concern, I would probably use a Background worker and the Write method. That way it won't hold up the UI and it let's the driver regulate the speed of submitting the write requests.

timryder

  • Jr. Member
  • **
  • Posts: 83
  • Still trying to figure it out
    • View Profile
Re: Writing a large number of tag values at once
« Reply #2 on: September 12, 2017, 03:56:17 PM »
Ok but is there a response or a synchronous mode for writing values to the PLC?
I would be nice if I had a confirmation that the data was written instead of having to write my own sort of handshaking check.
Still just trying to figure out this thing called Life.

timryder

  • Jr. Member
  • **
  • Posts: 83
  • Still trying to figure it out
    • View Profile
Re: Writing a large number of tag values at once
« Reply #3 on: September 12, 2017, 04:05:17 PM »
Here is my exact code.

Code: [Select]
Dim array As Single() = LocalListXPos.ToArray()
EthernetIPforMicro800Com1.Write("PartPositionsX[1]", 32, array)

Where LocalListXPos is just a List object of type Single.

One of the arguments is "startAddress" where i put "PartPositionsX[1]" as this is the first one of the array of 32.  Does the function automatically increment somehow? Will this indeed get all of my x coordinates from my local array down to the PLC in their respective locations?  PartPositionsX[1] - PartPositionsX[32]?

Still just trying to figure out this thing called Life.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5260
    • View Profile
    • AdvancedHMI
Re: Writing a large number of tag values at once
« Reply #4 on: September 12, 2017, 04:23:54 PM »
If the Write returns normally, then it was successful. Otherwise it throws an exception.

timryder

  • Jr. Member
  • **
  • Posts: 83
  • Still trying to figure it out
    • View Profile
Re: Writing a large number of tag values at once
« Reply #5 on: September 13, 2017, 09:47:50 AM »
Thank you for the answer, would you mind answering my second question i posted?

Quote
Here is my exact code.

Code: [Select]
Dim array As Single() = LocalListXPos.ToArray()
EthernetIPforMicro800Com1.Write("PartPositionsX[1]", 32, array)

Where LocalListXPos is just a List object of type Single.

One of the arguments is "startAddress" where i put "PartPositionsX[1]" as this is the first one of the array of 32.  Does the function automatically increment somehow? Will this indeed get all of my x coordinates from my local array down to the PLC in their respective locations?  PartPositionsX[1] - PartPositionsX[32]?

Thanks Archie
Still just trying to figure out this thing called Life.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5260
    • View Profile
    • AdvancedHMI
Re: Writing a large number of tag values at once
« Reply #6 on: September 13, 2017, 05:28:58 PM »
Here is my exact code.

Code: [Select]
Dim array As Single() = LocalListXPos.ToArray()
EthernetIPforMicro800Com1.Write("PartPositionsX[1]", 32, array)

Where LocalListXPos is just a List object of type Single.

One of the arguments is "startAddress" where i put "PartPositionsX[1]" as this is the first one of the array of 32.  Does the function automatically increment somehow? Will this indeed get all of my x coordinates from my local array down to the PLC in their respective locations?  PartPositionsX[1] - PartPositionsX[32]?
Not sure if I am completely understanding the question, so tell me if I am off base. The Write command will pack all of the values into a single packet and send it to the PLC to write all array elements in a single write. The part I am not sure of it whether the Micro800 handles this because that controller does have many limitations.

timryder

  • Jr. Member
  • **
  • Posts: 83
  • Still trying to figure it out
    • View Profile
Re: Writing a large number of tag values at once
« Reply #7 on: September 13, 2017, 06:19:04 PM »
Yeah that pretty much answers it. But also is my assumption of how the function works correct?

You provide the array tag name in the PLC and the starting pointer of the array.

TagName[0] or replace 0 with any number in the array.  Then set the number of elements to write starting with the first argument. Then lastly the local array data which will be written. 

So I'm assuming that the PLC handles distributing the arrayed values in their respective locations based on the arguments?

Right?
Still just trying to figure out this thing called Life.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5260
    • View Profile
    • AdvancedHMI
Re: Writing a large number of tag values at once
« Reply #8 on: September 13, 2017, 06:25:32 PM »
Yes, you are correct