News:

  • October 18, 2026, 04:10:29 PM

Login with username, password and session length

Author Topic: Exporting UDT Data  (Read 14173 times)

Bolt

  • Hero Member
  • *****
  • Posts: 598
Exporting UDT Data
« on: April 01, 2021, 11:07:13 AM »
Is there an easy(ish) way to get data from a UDT to my PC, say to do some analysis in Excel?  I can't figure out how to "download" the data.  The only thing I can think of is to write a loop to go through the UDT's and write to DMLogger or to SDCard, etc.  Please tell me there's an easier way?

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Re: Exporting UDT Data
« Reply #1 on: April 01, 2021, 11:37:49 AM »
You could put your UDT in a Data Window, right click "trend all", record for a few seconds and save the .csv log file.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: Exporting UDT Data
« Reply #2 on: April 01, 2021, 12:28:54 PM »
In batches, use FILELOG to log the data over time, then use EMAIL instruction to send the .CSV file from the PLC to an email account where you can analyze it, say at the end of each day?  .CSV is opened natively by Excel.  FILELOG even puts the element/tag names as the first line of the file, so Excel can show you what each column actually contain.

OR, use MQTT broker and JSONBUILD with MQTTPUB to "publish" the data "real-time", and have a similar PC based application "subscribing" to those topics, if "batches" is not "real-time" enough.

OR, do you need to do something different?

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Exporting UDT Data
« Reply #3 on: April 01, 2021, 12:51:57 PM »
I have a block of 1024 UDT's.  When certain processes occur, say 30 times a day, it shifts the block down a notch, and records things like Type, StartTime, RunTime, Flow, Flow Rate, Temp, etc.  Now that I have collected data for a while, I would like to analyze things, say comparing today's temp/flow ratio to 2 weeks ago, to find some deviations in the processes.  I could easily do this in Excel, with some filter/sort/graph, but would need to be able to dump the data.  I'm still thinking a LOOP, STRPRINT, EMAIL/DMLOGGER, of some sorts is my best option at this point.  I would of course prefer going File > Export > Memory Data and do it that way!  I guess I could write to a block of strings, and export that as Memory Data.  Would require a process shutdown to be able to create a new StringBlock though.  And take a ton of space that I don't have many left of.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: Exporting UDT Data
« Reply #4 on: April 01, 2021, 01:03:39 PM »
Use the RAM drive of your Do-more using FILELOG, which can be utilized via edge-trigger, not just on a time-interval.  You could use a FOR/NEXT loop to generate the .CSV file, then transfer the file to your PC via Designer (or email it).

Because the event-based FILELOG is edge triggered, you would need to do something with nested FOR/NEXT loops

GenerateDataFile PROGRAM

SG S0
FILEDEL "MyData.csv" OnSuccess JMP S1

SG S1
FOR V0 0 1023  // assume we are doing all of them, just stick the end ID for 1023
FOR V1 0 1  // edge trigger generator
STRE V1 1  // when V1 == 1
FILELOG "MyData.csv"  MyUDT[V0].ParmA, MyUDT[V0].ParmB, MyUDT[V0].ParmC, ...
NEXT
NEXT
JMP S2

SG S2
// then possibly EMAIL, or just use Designer to transfer the file from the RAM drive if EMAIL is not desired
EMAIL MyData.csv OnSuccess JMP S3

SG S3
EXIT

Then in $Main, whenever you need the file generated, do
RUN GenerateDataFile
and look for GenerateDataFile.Done to come on in $Main (after GenerateDataFile EXITs)

No need to do all the heavy lifting in PLC memory - just utilize the RAM drive file system available on ALL Do-more PLCs (only BRX has the SD card, however)

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: Exporting UDT Data
« Reply #5 on: April 01, 2021, 01:55:53 PM »
Sorry - that won't (necessarily) work since FILELOG is an FULLY ASYNC instruction.  You will need a 3rd loop REPEAT UNTIL

SG S1
FOR V0 0 1023  // assume we are doing all of them, just stick the end ID for 1023
  FOR V1 0 1  // edge trigger generator
    RST C100
    REPEAT

      STRE V1 1  // when V1 == 1
      FILELOG "MyData.csv"  MyUDT[V0].ParmA, MyUDT[V0].ParmB, MyUDT[V0].ParmC, ... OnSuccess SET C100
    UNTIL C100

  NEXT
NEXT
JMP S2

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: Exporting UDT Data
« Reply #6 on: April 01, 2021, 02:01:55 PM »
Set GenerateDataFile.TimeSlice to 0 so that the codeblock GenerateDataFile loops yield every scan, to minimize PLC scan hit.

You can actually do that at the top of the GenerateDataFile code-block
MOVE 0 GenerateDataFile.TimeSlice
or tweak the configuration of GenerateDataFile code-block to initially set the .TimeSlice to 0 (default is 100 microseconds)

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Exporting UDT Data
« Reply #7 on: April 01, 2021, 11:08:32 PM »
Sorry - that won't (necessarily) work since FILELOG is an FULLY ASYNC instruction.  You will need a 3rd loop REPEAT UNTIL

SG S1
FOR V0 0 1023  // assume we are doing all of them, just stick the end ID for 1023
  FOR V1 0 1  // edge trigger generator
    RST C100
    REPEAT

      STRE V1 1  // when V1 == 1
      FILELOG "MyData.csv"  MyUDT[V0].ParmA, MyUDT[V0].ParmB, MyUDT[V0].ParmC, ... OnSuccess SET C100
    UNTIL C100

  NEXT
NEXT
JMP S2

Thanks, I got it to work.  After many iterations, I had to abandon the FOR/NEXT loop, it was either skipping every other entry, getting hung up on C100, etc.  I just manually built one with SG's and an INC, and it worked right away.

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Exporting UDT Data
« Reply #8 on: April 01, 2021, 11:10:08 PM »
You can actually do that at the top of the GenerateDataFile code-block
MOVE 0 GenerateDataFile.TimeSlice

Where have you been with this!?  Just last week I checked DEVWRITE and a few others to see if it could be set at runtime.  Here you are with the answer!  Thanks!

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: Exporting UDT Data
« Reply #9 on: April 02, 2021, 08:47:44 AM »
Where have you been with this!?  Just last week I checked DEVWRITE and a few others to see if it could be set at runtime.  Here you are with the answer!  Thanks!

Yeah, the configuration just specifies the INITIAL (i.e. Program to Run) value of the .TimeSlice.  You can always control it at runtime, e.g. Data View or in logic or HMI or ....  You could even tweak it in code as loops are running - ha!

...
MOVE 0 MyProgram.TimeSlice  // during this phase, yield every time through the loop
FOR
// work
NEXT
...
MOVE 200 MyProgram.TimeSlice  // during this phase, we can do more work during the scan, so bump it up to 200 microseconds
FOR
// other work
NEXT

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: Exporting UDT Data
« Reply #10 on: April 21, 2021, 01:34:09 PM »
Well, here's a very viable solution (which I answered in another forum topic):
from Memory View, you can export a block of (UDT) structures to a .csv file