News:

  • October 13, 2025, 07:43:36 AM

Login with username, password and session length

Author Topic: Import data from CSV  (Read 1218 times)

ksasikumar

  • Full Member
  • ***
  • Posts: 33
Import data from CSV
« on: April 04, 2022, 08:45:08 PM »
I know that this topic has been discussed previously, but I was wondering if there is any way to import data from a CSV file on the SD card of a BRX PLC into the PLC's memory element. There are methods to do this, such as using FileRead to parse through the file, but this seems cumbersome in the long run. The File -> Import feature would be perfect for my application, but it seems to be only available when a user is actively on the Do-More software. Is there anyway this can be done as part of the ladder logic?

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3761
    • Host Engineering
Re: Import data from CSV
« Reply #1 on: April 05, 2022, 09:25:09 AM »
You got it right when you said you have to do 1.FILEOPEN 2.FILEREAD 3.PARSE 4.FILECLOSE, doing 2 and 3 until you reach the end of the file

I highly recommend doing this in a separate PROGRAM Stage-based block.

BobO wrote a sample here.  That will get you started with the basics.
https://forum.hosteng.com/index.php?topic=2818.msg22666#msg22666

You will need to tweak it to parse the CSV.  Here's a TASK code block example that tokenizes a string of CSV text (what you will be reading from one of the stages above) into an array of STRINGS, then another TASK that converts that array of STRINGs to their numeric equivalent.  You could probably stick these in a SUBROUTINE (not a TASK) then just CALL it from FILEREAD OnSuccess Stage.  Just tweak the SUBROUTINE to utilize the same STRING from the FILEREAD instruction.
https://forum.hosteng.com/index.php?topic=3303.0