Author Topic: Reading array of UDTs gives unexpected results  (Read 3313 times)

bosko1978

  • Newbie
  • *
  • Posts: 13
    • View Profile
Reading array of UDTs gives unexpected results
« on: May 25, 2015, 02:01:16 PM »
Hello I'm reading an array of UDTs that has 7 DINTs (each one holds Year, month, day, hour, minute, second) and then a float for a value.  This UDT is 1440 elements long.  I need to read in all the values and then put them in a CSV file.  I've got it all working except the fact that I can only get it to read as DINTs which makes my float value be split up.  This also wouldn't be a huge problem since I can put it back together in VB.net.  So that's the first problem.  The second one is that I'm doing a read starting at GWTUVDAI_CV.LOG[0].  The read thinks that the number of elements is 1440 (which is actually the array size) but that doesn't include everything that's inside the UDT as well.  So the length should be:
1440 * the length of each UDT which if we're using DINTs is 9 (7 for the DINTs and 2 for the float).  The problem is the .Read() function won't let me read more than 1440 elements which means it's really only reading up to array element 160 and not reading my entire array.  please have a look at my attachment.

thanks

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: Reading array of UDTs gives unexpected results
« Reply #1 on: May 25, 2015, 04:17:31 PM »
The CLX driver cannot read complex data types directly. To read all of your elements in the UDT, you would have to read through each UDT element with a separate read like this:

Dim values() as string
For i=0 to 143
  Values=EthernetIPforCLXCom1.Read("GWTUVDAI.LOG[" & i & "].DataTime[0]",7)

  '* Convert and write to data file

Next

bosko1978

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Reading array of UDTs gives unexpected results
« Reply #2 on: May 25, 2015, 06:42:36 PM »
thanks Archie.  That was what I immediately tried to do as well, however it doesn't work well because I get PLC not responding errors in at some random point in the for loop.  I don't know if it's hitting it too fast or what... I tried adding a pause in between the reads of 200ms but it will still fail at times.  Any other suggestions?

Edit:  perhaps there is a way to extend the timeout?
« Last Edit: May 25, 2015, 06:53:41 PM by bosko1978 »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: Reading array of UDTs gives unexpected results
« Reply #3 on: May 25, 2015, 07:33:19 PM »
What version of the software are you using?

bosko1978

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Reading array of UDTs gives unexpected results
« Reply #4 on: May 26, 2015, 03:28:06 PM »
I'm using 398j.  It's completely random how many of the for loop iterations it will get through before it eventually gets a "No response from PLC" exception.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: Reading array of UDTs gives unexpected results
« Reply #5 on: May 26, 2015, 06:11:43 PM »
I tried to replicate this using this code:

        Dim v() As String
        For i = 0 To 1439
            v = EthernetIPforCLXCom1.Read("Values[" & i & "].DateTime[0]", 7)
            Console.WriteLine(i & "-" & v(0))
        Next


It completed for me 3 times in a row. It took 22 seconds to complete, but it never errored.

Can you do a WireShark capture during the read? Do you have any other software communicating with the PLC? That code will send the next packet less than 1ms after the response form the previous was received, so its sending a lot of data quickly.

bosko1978

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Reading array of UDTs gives unexpected results
« Reply #6 on: May 27, 2015, 08:57:53 AM »
I'm installing wireshark right now.  Yes there is a wonderware InTouch application talking to this PLC, and there's PLC to PLC communication going on as well.  Is there a way to slow down other than the one I mentioned before?  Is there a way to extend the timeout?

bosko1978

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Reading array of UDTs gives unexpected results
« Reply #7 on: May 27, 2015, 09:14:08 AM »
I'm new to wireshark.  Is there any way to look just at the PLC comms, or any perticular steps for troubleshooting?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: Reading array of UDTs gives unexpected results
« Reply #8 on: May 27, 2015, 09:24:07 AM »
In the filter at the top, enter this:

ip.addr==192.168.0.1

with it being set to the IP address of your PLC

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: Reading array of UDTs gives unexpected results
« Reply #9 on: May 27, 2015, 09:27:12 AM »
Wireshark will reveal what is truly happening, but my guess is either the PLC is being overwhelmed with requests and skips a response or the response is getting lost on the network.

One of the timeout periods is set for 15 seconds, so I doubt extending that would help.

bosko1978

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Reading array of UDTs gives unexpected results
« Reply #10 on: May 27, 2015, 10:59:03 AM »
Thanks Archie.  I decided to do catch the error, and then retry in the code.  That seems to work fine. 

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: Reading array of UDTs gives unexpected results
« Reply #11 on: May 27, 2015, 11:20:57 AM »
Thanks Archie.  I decided to do catch the error, and then retry in the code.  That seems to work fine.
That was going to be my recommendation if the WireShark capture showed missing responses.

How long is it taking to read all of the elements?

bosko1978

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Reading array of UDTs gives unexpected results
« Reply #12 on: May 27, 2015, 12:17:08 PM »
It takes upwards of a minute.  I'm doing this over a WAN so I'm not surprised.  Thanks again for your help and all your hard work in creating AdvancedHMI.