Skip to content

PLC Trace to CSV: Record and Analyse with AI

AnyAutomation6 min read

Every commissioning engineer knows the fault that never happens while you watch. The line stops once in twenty cycles, the alarm text says little, and by the time you have the right variables on screen the plant runs fine again. A recording solves that: if every relevant signal is written down with a timestamp, the order of events is there in black and white. In AnyAutomation Studio, the agentic engineering IDE for TIA Portal and CODESYS, you can leave both the recording and the analysis to the AI agent, using the built-in OPC UA client.

Why a recording beats watching

A watch table shows you the present. A fault in a sequence is about the past: which signal changed first, how long a step took, whether the conveyor stopped before or together with the error bit. A recording keeps all of that. It also lets you compare cycles: a good cycle and a bad one side by side show the difference faster than any amount of staring at live values.

Step 1: connect and build the watch table

Open PLC / OPC UA and connect to your controller with your own credentials, or ask the agent to do it. When the server needs a password, the agent can ask you for it in a masked input, so it never ends up in the chat. Then describe what you want to look at:

"Add the line state, the start, stop and reset commands, the speed and error bit of all three conveyors and the throughput of the filling line to the watch table."

The agent searches the address space, reads the structures and adds the rows. You see them appear in the same watch table you would use by hand. For slow analog values it can set a deadband per row, so the recording does not fill up with noise. Adding rows and starting the live updates change nothing on the controller, so they run without a confirmation.

Step 2: choose the recording

Studio offers two recorders, and both produce CSV:

  • The Trace samples up to 8 OPC UA signals at a fixed cycle, for example every 200 ms, and draws them live like an oscilloscope. Evenly spaced samples make it easy to compare one cycle with the next. Set Live Window to All, so every cycle of the run stays in the recording. After you stop it, you can export the recording as CSV.
  • The Data Logger writes every change of value or status in the watch table to a CSV file. It runs as long as the live updates run, and when a file reaches the size you set, it continues in a numbered follow-up file. This is the right choice for many signals, long runs and S7 connections.

Ask for either one in plain words: "Trace the line state, the three conveyor speeds, the error bit of conveyor 2 and the throughput every 200 ms." A trace only reads values, so it starts right away. For the Data Logger, "Log all watch table rows to the file line-run.csv in the open workspace folder" shows a confirmation card with the file and the rows first, and logging begins after you allow it.

Step 3: run the plant through its cycles

Now the plant has to do something. Run a handful of start and stop cycles, the way the plant runs in production. You can trigger them from the HMI, by hand in Studio, or let the agent write the commands:

"Start the line, wait until all conveyors are at speed, stop it again after a minute. Repeat that four times."

A write from the watch table shows a confirmation card that lists the values and names the target, a real controller or a PLCSIM Advanced instance, and you decide whether to allow it once, for the session or always. Try a sequence like this on PLCSIM Advanced or another test system first. While the plant runs, the agent can also watch the table for up to a minute at a time and report every change with its exact time.

Step 4: let the agent read the recording

Stop the recording and ask the question you actually have:

"Read the trace and tell me where one cycle differs from the others. What happened right before the line stopped?"

The agent reads the trace samples directly and works through them cycle by cycle. Take a simulated filling line on PLCSIM Advanced where one cycle gets a stop command for conveyor 2 alone and another cycle a simulated line fault. The findings then read like this:

  • In one cycle conveyor 2 stopped without an error bit, while the line state still said running and the throughput fell to zero.
  • In another cycle the error bit and the fault state came together, and all three conveyors ran down within about three seconds.

The first finding is the kind that rarely shows up on a live screen: no alarm, no fault state, only a conveyor that is no longer moving. In the recording it is a plain comparison of speed and line state at the same timestamp.

Good practice and limits

  • Record a little more than you think you need. A signal you left out is the one you will miss.
  • Use the trace for a few signals that you want evenly sampled, and the Data Logger for many signals or long runs. The trace keeps up to 10,000 samples per recording, or as many as fit into the time window you choose, and it records OPC UA signals only.
  • The agent observes live values in steps of up to a minute. For anything longer, it starts a trace and reads its samples afterwards.
  • Keep the CSV files in your workspace folder. They stay there as evidence after the session, and you can open them in any spreadsheet tool.
  • Only connect to controllers you are authorised to access, and test sequences the agent starts by writing on a simulation first.

Connecting, watch tables, the Data Logger and the agent work the same for a Siemens S7-1500 from a TIA Portal project and for a CODESYS controller with its OPC UA server. The trace has been tested on S7-1500.

Which plan you need

You work with PLC / OPC UA yourself, including watch tables, Data Logger and Trace, from the Pro plan. The agent on the controller, which builds tables, records, writes and analyses for you, is included in Pro+ and Enterprise. The 30-day trial unlocks both.

Read more on the OPC UA client with AI page, and find every step in the manual on PLC / OPC UA, the Data Logger and Trace in the AI chat.

Try it now

Try AnyAutomation Studio free for 30 days

Try the workflows from these articles in your own TIA Portal or CODESYS project.

Free account required: sign in with your email address and a code, then the download starts.

Questions? support@anyautomation.ch