ControlLogix and CompactLogix Datalogging to CSV File

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.

There are two Tags in the program

Log to CSV enable

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.

The output of this program is a CSV file Log to CSV sizewhich 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.


Shawn Tierney
Automation Instructor and Blogger (post views: 13,930 views)

Enjoy the benefits of membership!
Check out my affordable courses:
Ask me questions by clicking here to go to the comments link
Have an industrial automation news tip? Share it with us here


Click HERE to scroll down to view or leave comments

Forum 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.

25 Blog Comments

  1. 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?


    • Good morning Dan,

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


      Shawn Tierney

      Find my articles or comments helpful? Check out my courses here.
      Support our site to disable ads, get free downloads, & more here.
      Have a news tip? Share it with us here.

  2. 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.

    • Good morning Lefty,

      I’m unable to offer free support for the above Rockwell sample code.

      That said, if you’d like to hire me for an hour or two to help use this form here to contact me:


      Shawn Tierney

      Find my articles or comments helpful? Check out my courses here.
      Support our site to disable ads, get free downloads, & more here.
      Have a news tip? Share it with us here.

Leave A Blog Reply Here

Please enter your blog comment!
Please enter your name here