ControlLogix and CompactLogix Datalogging to CSV File

TAS_Banner_PAC_A

Log to CSV file on CompactFlash or SecureDigitalA couple of years ago, prior to the release of Studio 5000 v21, Rockwell demonstrated a future feature for it's new “multi-core” programmable automation controllers. This new feature was a very robust, controller based data logging system.

Unfortunately, since that demo a couple of years back nothing more has been hear about this feature. Well, at least I haven't been able to find anything out despite my efforts. However, I can confirm it's not in the soon to be released version 22, which was the originally targeted release.

But even without that new feature there is a way to log CSV files to you CompactLogix or ControlLogix's Compact Flash or SD card. And it's accomplished with a piece of free sample code from Rockwell's own sample code website. Below is a link to the free code in question:

Log to CSV file Samle Code Download

Log to CSV file on CompactFlash or SecureDigital

Log to CSV Slot NumberHaving tested the sample myself, I have to say it works as advertised. Simply changed the code to match your processor model and version (the sample code is version 17,) change one rung to indicate the slot of your processor, and download.

Log to CSV enableThere are two Tags in the program which controls it's behavior. The first Tag is the “logging_enabled” bit, which does just what it says. The second Tag is “max_file_size,” and this is the setpoint that when reached will unlatch the “logging_enabled” bit.

Log to CSV sizeThe output of this program is a CSV file which is easily opened in Microsoft Excel. Once open, you set the first column to the Date format, and the second column to Time format, and you end up with a document which looks just like the example below:

Log to CSV file on CompactFlash or SecureDigital

Unlike the “CF_Read_Write_Example” I mentioned earlier this year, this code is not so much an application example as it is a proof of concept.

In my opinion, to make this code fully functional the following features would need to be added:

  • Easy way to tell which tags are being logged, and add new tags to be logged.
  • Addition of a series of tags to be used as “row 1 headers”
  • Automatically create new files at a predetermined time (midnight)
  • Easy way to specify CSV file naming parameters
  • Automatic deletion of older files after a certain number of files are present, or a percentage of the card had been filled.

That said, if you need to log to your CompactLogix or ControlLogix external CF or SD card, this sample code is a simple and easy to use free solution.

Log to CSV file Samle Code Download

I hope you've found this article about logging to a CompactLogix or ControlLogix external CF or SD card helpful. If you have any questions, comments, or corrections, please don't hesitate to share them with us by using the “post a comment or question” link below.

Sincerely,

Shawn Tierney
Automation Blogger and Trainer
If you enjoyed my article, you may like my affordable courses at TheAutomationSchool.com




Comments:
  1. I found this thread to be very useful. I downloaded the Rockwell logic and put it into my controller, but then what!? I was logging data of nothing essentially. I've played around with this for several days to try to make the logic useful to me and I came up with a couple helpful things I think others might be interested in trying in order to collect specific data (in my case I'm collecting 2 vibration signals and a speed reference of our machine).
    One thing I noticed was that when the memory card was removed and then put back in, the logic seemed to get "stuck" and wouldn't log data anymore. I wrote a small branch of logic to "unlatch" the cfbw01.busy bit since when the memory card is removed and put back in, this bit gets stuck on and never allows the logic sequence to continue, so it doesn't log data. My logic addition will reset this 5 minutes after the memory card has been put back in (see image below).
    And also, I wanted to create a .csv file on a daily basis rather than file size to make organizing our data more useful. I have my logic writing to a single file daily until midnight, then it'll create a new file for the next day and will log until midnight comes around again. In my case, midnight happens to be when the Idt.hour bit hits '6' (this is a work in progress, I'm trying my best to figure out this logic and edit it to be useful to me). Once it hits midnight, it'll finish writing to the one .csv file for the day and create a new one... see image:
    Ultimately, what we want is to log data, our own data. This is done in the Raw2ascii structured text routine. Their first 2 "groups" of logic in this routine are written to log the date and time. That's good, but I also wanted to log my data for the specific date and time stamps that were being logged. I pretty much copied and pasted the first 2 "groups" of logic and edited it to use the bits I wanted to monitor in the PLC, see image:
    With all this being said, I now log the data I want to see, along with meaningless extra stuff that is being written to this .csv file: . The first 5 columns are the Date, Time, Vibration Data, Vibration Data, and Speed. The last several columns are meaningless (where it writes the values 1-10 for each row). I ended up making a macro in Excel to delete these meaningless numbers.
    Like I mentioned, this is still a work in progress, but ultimately what I'd like this logic to do is to ONLY collect the data I want and figure out how to not write the rest of that meaningless stuff to the .csv file. And I'd like to figure out how to write a top row in every .csv file that has all the headers for what each column represents.
    I hope this helps some people, I was unable to find any real examples of how to manipulate Rockwell's logic to make it their own, so I had to give it a try on my own. Btw, I'm an electrical engineer with 3 1/2 years of programming experience, so I'm still fairly new to the world of programming, but hope this helps some people.

2 Old Comments:

  1. Thanks Shawn! I am currently building a machine utilizing this feature right now. I, too, have been successful writing to the CF in CSV format and agree with your comments about the additions that would make this code awesome. If you figure out a way to do the “row 1 headers”, please let me know. Thanks again!

  2. Morning Adam,

    I had a great email exchange with the author of this code and he seemed very interested in adding some of the new features discussed above.

    If I hear anything additional I’ll post it here,

    Have a great day,

    Shawn Tierney

    If you enjoyed reading my article you may also like my affordable training courses at TheAutomationSchool.com

  3. Hey Shawn,

    This article is awesome! Thanks so much! I am very very new to programming in controllogix and have built my own program. I only need two integers recorded and I’ve managed to get this program to work on my compactlogix but i’ve looked through the entire program and can’t seem to find where to put my tags to be recorded. I also need to keep my values as integers instead of strings and the instructions say to use the DTOS function but I think its not as simple as changing RTOS to DTOS wherever its found. I think some of the code could be done away with for my purposes. Could you give me some guidance? I feel like I’m missing something really simple.

    Thanks!

    Alex

  4. Alex,

    Thank you very much for your comment.

    Unfortunately, I’m traveling and won’t have a chance to take a look at your code question about this Rockwell sample in the immediate future 🙁

    But, if you figure it out I think everyone here would love to hear what you find!

    Sincerely,

    Shawn Tierney

    If you enjoyed reading my article you may also like my affordable training courses at TheAutomationSchool.com

  5. Una consulta, que cambios deberia hacer en el programa para que registre solo al generar un pulso ? porfavor, necesito saberlo

  6. I want to know what changes should I make to record only to take a pulse and not complete with previous data

  7. Francisco,

    Thank you very much for your comment.

    Unfortunately, I’m traveling and won’t have a chance to take a look at your code question about this Rockwell sample in the immediate future.

    Sincerely,

    Shawn Tierney

    If you enjoyed reading my article you may also like my affordable training courses at TheAutomationSchool.com

  8. Thanks Shawn,

    That’s what i was wanting to do, i am new at this world of PLC programming and i try to understand the code reading all its lines but there are some things that i dont know but apart from that i didnt see where it shows what kind of data is logging or as @Alex says how can i pick some tags to be logged, or i am confusing the code’s purpose.
    I will apreciate if you can help me.

    Jorge

  9. Good morning Jorge,

    It’s true this sample code is not the easiest to use, and I’m still several weeks away from being able to look at it again 🙁

    In the mean time, you may wish to contact your local Rockwell rep or Rockwell support to see if they can help?

    Sincerely,

    Shawn Tierney

    PS – When I do get back to this topic I’ll update this article with a link to any new content

  10. I know this is a big ask but does anyone have the CF_Read_Write_Example saved for a compactlogix (1769-L32 or 1769-L35) I only have the mini version of RSLogix5000 and nearly all of the examples are for controllogix which cant be opened by mini.

    I tried my rep but no joy. Any help would be appreciated.

  11. Good morning Milkeuk,

    I think I have it somewhere and will look… would you be willing to trade me a cup of coffee for it? (I love coffee!)

    Sincerely,

    Shawn Tierney

    If you enjoyed reading my article you may also like my affordable training courses at TheAutomationSchool.com

  12. I couldn’t buy you a coffee and not get you a Danish as well, enjoy.

    Looking forward to trying the data logging, let me know when you have it.

    Thanks Shawn.

  13. Thank you very much mikeuk!!!

    Will try to get it for by Monday – do you have a version preference? The file in this article comes in v17, but the Read Write you mention comes in many versions…

    Thanks again,

    Shawn Tierney

  14. Good day Shawn,

    In my application I only need to save data to the sd card right before the Plc malfunction or is shut down. Is there a bit that turns on right before the Plc is shut down? Something like the S:FS but for the “last scan”? Do you have any other suggestion to accomplish this?

    Thanks in advance.

  15. Good morning Jose,

    Since many of the Compact and ControlLogix processors Rockwell made have no power storage, I don’t believe it’s possible for them to do anything when power turns off as they’ll have no power to keep running.

    However, since all the new models do have a supercap built-in, it’s feasible that they could add this feature in the future.

    That said, here’s a few options you could use today:

    1) Fault Routine

    All Rockwell’s PLC’s allow the user to write a fault routine which will run once when a fault occurs.

    This can be very helpful when you want to record certain tag values when a math overflow or other trappable fault occurs.

    2) UPS

    If you have to record data when power is turned off, a small UPS with output contact wired into the PLC is one way to achieve this.

    Setup the UPS so when power is lost it opens its contact, wire the contact into an input module on the PLC, and write a program so when the PLC sees the contact open it records the data you need.

    3) Continuous logging / Log on change

    The obvious and least efficient option is just to record the needed data every PLC scan.

    This would definitely catch the data before a fault or powerdown.

    It may also make sense to only log the data when it changes as all non-volatile memory (SD, CF, etc) has a maximum number of times it can be written to.

    Hope this helps!

    Shawn Tierney

    If you enjoyed reading my article you may also like my affordable training courses at TheAutomationSchool.com

  16. A rudimentary approach can be taken by continuously storing and overwriting the data in a buffer tag(s) for each scan. Upon shutdown or fault, the S:FS bit can be used to write the buffer when it powers up. This essentially captures the data before the processor stopped.

    The only downside to this is that the information can only be retrieved after the processor powers back up.

  17. Hello Shawn,

    Very interesting article. Like Mikeuk, I also have only the mini version of controllogix. Is it possible to get a copy of the file you sent to Mikeuk?

    Regards,
    Dan

  18. Good morning Dan,

    Sure – just use the contact link at the top of the site to send me your request,

    Sincerely,

    Shawn Tierney

    If you enjoyed reading my article you may also like my affordable training courses at TheAutomationSchool.com

  19. Hello Shawn,

    First, thank you. this code is very good and i like this article.

    I tried to set up this type of system without ever succeeding. I tried unsuccessfully CR_read and CF_write functions. Your code will really help me.

    I just have a few questions:
    – I do not understand the use of CF_del.PRE in CF_FunctionsProgram function. Can you enlighten me this detail?

    – If I understood correctly. you flash stores data. When the quantity of bytes is greater than a threshold. you exported and write at that time. You activate the delete function “oldeslogfiles” only when there are more than 10 CSV file?

    -After Export, I can change in the CSV file, the cells of the date, but not this time. I have not proposed cell formats ‘h: mm: ss.000’. Is there an intermediate solution?

    Thank you in advance for your answers.

    I can run the software on a 1769_L33ER PLC.

Comments are closed.