IMDTouchKnowledge BaseShop main store

Troubleshooting

Reading a USB datalog from an HMI in the CODESYS runtime

HMI and touchscreens Published 7 min read

Short answer

Yes, when the panel's CODESYS runtime exposes the USB storage to the application. Prove it in three steps: confirm the HMI writes the datalog to the drive, confirm the runtime mounts the drive and read its assigned path, then open a known test file with the documented file library before reading the datalog. A failure at one step says nothing about the next.

On this page
  1. The three-layer test in order
  2. Layer 1 — the HMI must write the datalog first
  3. Layer 2 — the runtime must mount the drive
  4. Layer 3 — open a known test file before the datalog
  5. Worked example: proving the read path on a cMT3071 with a 29-byte test file
  6. Sharing the drive between the HMI and the runtime
  7. Questions asked

Yes — the CODESYS application on the panel can read the USB datalog, but only once three separate things are true: the HMI writes the file, the runtime mounts the drive, and the documented file interface opens a file on that mount. USB working at the HMI level proves none of the three, which is why "the log is on the drive but my code cannot open it" is the normal first symptom rather than evidence of a fault. This walkthrough uses a Weintek cMT3071 with the built-in CODESYS runtime as the case, works the layers in order, and finishes with a test file of known content that proves the read path before the datalog is touched.

The three-layer test in order #

Diagnose USB datalog access as three stacked layers and test them in sequence. A failure at one layer tells you nothing about the layers above it, so nothing downstream gets tested until the current layer passes.

  1. The HMI writes the datalog. Watch the drive through the HMI's own file view or export function until a log file exists, grows with new records, and you have written down its exact name and folder.
  2. The runtime mounts the drive. With the USB device inserted, read the mount path from the runtime's device file list, not from the HMI. The two stacks can name the same drive differently.
  3. The documented file library opens a file. Open a small file of known content, read a bounded number of bytes, check the returned count, and close the handle on every path. The CAA File library is the standard interface where the runtime provides it, and the library documentation for your panel build is the standard you code against: it fixes the path syntax, the handle rules and the status returns. Anything outside that documentation is undocumented on this device.

Stop at the first layer that fails and fix it there. Do not debug parsing, tags or the datalog format while a lower layer is unproven.

Layer 1 — the HMI must write the datalog first #

The datalog's name, folder, format and rotation all come from the HMI's logging configuration. Treat them as measured values you read off the panel, never as strings you guess in code. Watch the drive through the HMI's own file browser or export workflow:

What you see on the drive What it means Next move
Log file present, size grows as records are added HMI logging and the USB write path work Go to layer 2
No file, or the size never changes Logging destination, trigger or write failure on the HMI side Fix the HMI logging configuration before testing any code
File present under a different name or folder The runtime must address the actual location Record the exact name and folder and use those

If the file never appears, that is an upstream logging problem, not a CODESYS fault, and no amount of runtime debugging will create it. While you are proving where logged data lands, the same discipline applies to history kept on the panel itself — see verifying HMI historical trend retention before committing.

Layer 2 — the runtime must mount the drive #

The HMI firmware and the CODESYS runtime are separate software stacks over one USB port. The HMI logging to the drive proves the port and the media; it does not prove the runtime can see the filesystem. With the drive inserted, open the device's file list in the engineering environment: on controllers with runtime file access, the USB device and its files appear there, and the entry disappears when you pull the drive. That insert-and-remove cycle is the cheapest mount test there is.

  • Mount entry present: copy the path exactly as the runtime reports it and use that string in the application. Do not transplant a path from the HMI.
  • No mount entry while the HMI still logs: removable-media access for the runtime is a vendor-integration question — whether that runtime build exposes the media, through which library, and at which path. Until the answer is yes, move the data with a documented export from the HMI instead.
  • Entry appears intermittently: check the connector, the media condition and the runtime diagnostics before blaming the application.

If your way out to the data is the network rather than a USB stick, the comparable layered failure is why HMI SFTP cannot see the SD card data log files.

Layer 3 — open a known test file before the datalog #

Never make the production datalog your first file operation on a new path. Prove the interface with a file whose entire content you control:

  1. Put a small text file of known content on the drive from a PC, or write it from the runtime if writes are supported.
  2. Open it with the documented file function and carry the status return into a variable you can watch.
  3. Read a bounded number of bytes and check the count that comes back.
  4. Close the handle on every path, success or failure — an abandoned handle can hold the mount busy.
  5. Compare the characters read back against what you wrote, byte for byte.

All five pass, and the same open-read-close sequence gets pointed at the datalog. If the test file works and the datalog does not, the fault is above the USB layer: the name or folder in the code does not match what the HMI wrote, or the read landed mid-record while the HMI was appending.

Worked example: proving the read path on a cMT3071 with a 29-byte test file #

Inputs. The hardware is the reader's own case: a cMT3071 touchscreen with the built-in CODESYS runtime, a USB device the HMI already logs to, and a datalog whose name and folder were recorded in layer 1. The one input created here is the test content: a single ASCII line, CODESYS-USB-TEST,0123456789, terminated with CR and LF.

Rule in words. The read path is proven only when the read returns exactly the number of bytes written and the identical characters. Any open error, or any other count, locates the fault in the mount, the path or the handle — below the format layer — and the sequence stops there.

Arithmetic. The label CODESYS-USB-TEST is 16 characters: 7 in CODESYS, 2 hyphens, 3 in USB, 4 in TEST. Add 1 comma and 10 digits: 16 + 1 + 10 = 27 characters. ASCII stores 1 byte per character, and CR and LF add 2 more: 27 + 2 = 29 bytes on the media, provided the file is saved as plain ASCII or UTF-8 without a byte-order mark — a UTF-8 BOM would add 3 bytes and make it 32, so save without one.

Result. The write puts 29 bytes on the drive; the read-back through the documented file function returns 29 bytes and the same characters.

Decision. Counts equal and characters identical: the USB read path is proven, and the same open-read-close sequence now runs against the datalog — read its first complete line, split it on its delimiter, and compare one field against the value currently shown on the HMI screen. That field matches, and you can bind the parsed values to application tags. An open error, or any count other than 29: stop at this layer and fix the mount or path, and leave the parsing code alone, because nothing above this layer has been tested yet.

Sharing the drive between the HMI and the runtime #

The HMI owns the active datalog: creation, naming, rotation and deletion come from its logging configuration. Two rules follow.

  • Reading while the HMI appends can deliver a partial last record. Read files the HMI has closed or rotated, or use the HMI's export or copy function to produce a finished file for the runtime to process.
  • If the runtime writes to the drive, it writes to its own separately named file: open or create it, check the write status, close the handle, then read it back through the same interface to confirm.

Treat the datalog as production data: never test write behavior against the active log, because a runtime write can corrupt the only copy.

Questions asked

Can I just copy the USB path the HMI shows into my CODESYS code?

No. The HMI firmware and the CODESYS runtime mount the same port through separate software stacks, and the path strings they use can differ. Read the mount path from the runtime's own device file view with the drive inserted, and use that exact string. If the runtime reports no mount while the HMI still logs to the drive, removable-media access for the runtime is a question for the panel manufacturer, not something a different path will fix.

The test file reads back fine but the datalog will not open. What does that tell me?

The USB read path is good and the fault sits above it: the filename or folder in your code does not match what the HMI actually wrote, the file is being rotated at the moment you open it, or the read arrives mid-record while the HMI appends. Re-copy the exact name from the HMI, read only closed or exported files, and compare one field of the first complete line against the value on the screen before parsing further.

Can CODESYS write to the USB drive as well as read it?

Yes, to its own file. Open or create a separately named file with the documented file library, check the write status, close the handle, then read the file back through the same interface to confirm it. Never write the HMI's active datalog: the HMI owns that file's creation, naming and rotation, and a runtime write can corrupt the only copy of production data.

What exactly do I ask the panel vendor when the runtime shows no USB mount?

Ask whether the CODESYS runtime build on that specific panel model exposes removable media to the application, which file library it supports, and the documented mount path to use. HMI-level USB support does not answer this; the runtime integration does. Until the answer is yes, move the data with the HMI's documented export function or a network transfer rather than an undocumented path.

Keep reading

  • How-to

    Verifying HMI Historical Trend Retention Before Committing

    An 8-hour trend sampled every 5 minutes spans 96 intervals — 97 stored points if both endpoints are kept — so the panel needs a historical buffer of at least 97 samples per tag that repopulates the trend after screen changes. Verify the buffer depth, the interval setting, and restoration behavior on the bench before you build the screens.

    HMI and touchscreens

  • Troubleshooting

    Why HMI SFTP Cannot See the SD Card Data Log Files

    On a PanelView Plus 7 Series B terminal, the SFTP service publishes internal storage only; the SD card and USB drives never appear to a remote client. A data log whose path root is removable media cannot be retrieved remotely until you redirect it to internal storage or copy it at the terminal with the file explorer application.

    HMI and touchscreens

  • Troubleshooting

    Connecting a CompactLogix PLC to an HMI over EtherNet/IP

    A CIP transport unsupported fault on a Generic Ethernet/IP module in a CompactLogix project means the connection was built the wrong way around. For HMI tag access, delete the module, select the panel's Rockwell PLC driver, point it at the controller IP, and rebuild the tags — no assembly instances, I/O sizes, or EDS file.

    HMI and touchscreens