Overview
The Sinumerik 840D controller does not provide a direct, NC-part-program equivalent to the Fanuc DPRNT / POPEN / PCLOS instruction set for streaming formatted ASCII strings out of the RS232 (COM1/COM2) port in real time. Engineers migrating Fanuc post-processors, macro-based probing routines, or DNC telemetry to 840D must therefore select an indirect path: NC-side file write, HMI/PCU50-side script, PLC-side FB, or a vendor-supplied probe print utility. Each path has distinct timing, hardware, and operator-panel constraints that must be matched to the application (in-cycle gauging, tool-life logging, bar-code reading, DNC machine-condition reports, etc.).
This reference documents the constraints behind the missing DPRNT, the available Siemens-documented workarounds, the hardware topology of the 840D serial ports, and a step-by-step implementation of the PCU50 / HMI Advanced logfile method which is the most common production workaround.
Why There Is No DPRNT Equivalent in 840D
On Fanuc Series 0i / 30i / 31i / 32i, DPRNT ["TEXT", variable] writes a formatted string into the I/O channel currently selected by POPEN and closes the channel with PCLOS. The string is delivered to the channel byte-by-byte during program execution, which makes it suitable for in-cycle marking, gauging probes, and DNC reporting.
The Sinumerik 840D NCK architecture does not expose the serial port as an NC-side file descriptor. The COM1 / COM2 ports on the 840D HMI (PCU20, PCU50, PCU70, or HT8) are owned by the Windows / HMI-Advanced runtime, not by the NCK. As a result, the NC interpreter has no syntax to push characters to a UART. Siemens documents the serial interface exclusively for:
- NC data backup / restore (archive of TEACH, INI, MPF, SPF files)
- RS232 DNC mode for streaming long part programs
- Connection of an external keyboard or barcode reader on certain HMI variants
The official Siemens answer is that no NC instruction is supported for arbitrary user-string output to RS232. The original 840D sl forum thread confirms this: "there is facility of NC data backup through Serial port… I am not aware of any Siemens supported method to send data to a serial port from an NC part program."
WRITE / DEF INT / file construct and assume the NCK will spool it to COM1. The NCK's WRITE instruction writes to an NC-side logical file system (active workpiece, cycles directory, or _N_ archive) that is reachable only through HMI / network shares, not through the UART.RS232 Hardware Topology on Sinumerik 840D
Before selecting a workaround, confirm which physical serial port exists on the target HMI. The 840D controller family spans several operator-panel generations and the COM port availability differs.
| HMI / PCU variant | COM1 (9-pin D-sub) | COM2 (25-pin or 9-pin) | Notes |
|---|---|---|---|
| PCU20 (HMI-Embedded) | Yes (services) | Optional | COM1 typically reserved for RS232 NC commissioning |
| PCU50 (HMI-Advanced, WinXP) | Yes | Yes | Standard target for user-side RS232 |
| PCU50.3 (WinXP embedded) | Yes | Yes | Default on 840D sl line |
| PCU70 (HMI-Advanced, Win7) | Yes | Yes | Same port mapping as PCU50.3 |
| HT8 handheld terminal | No | No | No serial; use MPI/PROFINET only |
| TCU / thin client | Indirect | Indirect | Serial is hosted on PCU, not TCU |
The COM port on PCU50 / PCU50.3 / PCU70 is a standard Windows COM resource. In HMI-Advanced, the port can be opened from a VB script, a C/C++ HMI application, or a Siemens-supplied OEM DLL using the Win32 CreateFile("COM1:9600,N,8,1") API.
Available Data-Output Paths Compared
| Method | Where it runs | Latency | Real-time in cycle | Hardware needed |
|---|---|---|---|---|
Fanuc-style DPRNT
|
— | — | — | Not available on 840D |
NCK WRITE to local file |
NCK | 50–200 ms per line | Yes (file buffered) | None |
HMI VB script via MSComm or SerialPort
|
HMI/PCU | 1 cycle of HMI tick (~200 ms) | Limited by HMI scan | PCU50 / PCU50.3 / PCU70 with COM port |
| PLC FB on S7-300/400 writing to CP340 / CP341 | PLC | OB1 cycle (1–10 ms) | Yes (deterministic) | CP340/341 module + second UART |
| PROFINET / Ethernet TCP to external gateway | PLC + gateway | OB1 cycle + link | Yes | External RS232-Ethernet converter |
| Renishaw OMP / RFP probe print utility | Probe HMI app | Event-driven | Yes (on probe trigger) | Renishaw probe + interface + OMP60/RFP |
| DNC mode (RS232 stream) | HMI | Per block | Yes, but input only | PCU with COM port |
Path 1 — HMI-Advanced VB Script on PCU50 / PCU50.3
Prerequisites
- Sinumerik 840D with HMI-Advanced (PCU50 / PCU50.3 / PCU70)
- Operator rights to install OEM HMI scripts (Sinumerik Operate / HMI-Advanced access level ≥ 3, manufacturer password)
- Available COM1 or COM2 on the PCU
- Cross-over or null-modem cable to receiver (DTE/DCE must match)
- Siemens documentation set: Programming Manual SINUMERIK 840D sl / 840Di sl, Fundamentals and HMI-Advanced Configuration Manual
NC-side: write a record file
From the part program, append a structured line to a log file. The 840D NC syntax for appending is:
; MPF or SPF, any 840D part program
DEF INT _RET
DEF REAL _X_MEAS = 123.456
DEF STRING[80] _LINE = ""
_LINE = "MEAS," << _X_MEAS << ",HELLO!"
_RET = WRITE(_LINE, "//NC:/LOG/REPORT.DAT")
On 840D sl, the logical path //NC:/LOG/REPORT.DAT resolves to C:\dh\nc.dir\log\report.dat on the PCU (active file system), or to the NC card user area on NCU 710/720. The file grows indefinitely unless you implement a rotation scheme in the HMI script.
HMI side: VB script forwarding to COM1
Place the following VBS in the HMI-Advanced project (typically C:\dh\cus\hmisl\scripts\serial_out.vbs) and reference it from a horizontal soft key or a screen cycle event:
' serial_out.vbs — HMI-Advanced, PCU50/PCU50.3
Option Explicit
Const FILE_PATH = "C:\dh\nc.dir\log\report.dat"
Const COM_PORT = "COM1"
Const BAUD = 9600
Dim fso, ts, f, sLastLine, sLine, msComm
Set fso = CreateObject("Scripting.FileSystemObject")
Set msComm = CreateObject("MSCommLib.MSComm")
With msComm
.CommPort = 1 ' COM1
.Settings = BAUD & ",N,8,1"
.RThreshold = 0
.PortOpen = True
End With
Do
If fso.FileExists(FILE_PATH) Then
Set ts = fso.OpenTextFile(FILE_PATH, 1, False) ' read
Do While Not ts.AtEndOfStream
sLine = ts.ReadLine
If sLine <> sLastLine Then
msComm.Output = sLine & vbCrLf
sLastLine = sLine
End If
Loop
ts.Close
End If
WScript.Sleep 200 ' 5 Hz poll, below HMI tick
Loop
Register the script as a Windows service or as a HMI-Advanced startup task (OEM setup). The receiver (label printer, line scan, or DNC host) sees each line as it appears, with effective latency of 200–500 ms — sufficient for tool-life logs, spindle-load reports, and out-of-cycle marking.
Path 2 — PLC FB on S7-300/400 via CP340 / CP341
If the 840D is paired with an S7-300 (or S7-400) PLC and a CP340 (ASCII) or CP341 (modular ASCII / 3964R) module is mounted in the rack, the PLC can build and transmit an RS232 frame deterministically from an OB1 cycle. The NC part program sets an interface signal (e.g., a $AC_MEAS_TYPE or a freely assigned M-function / GUD flag) that the PLC reads and converts to a string for the CP340/CP341 send buffer.
PLC ladder outline (S7-300 / STEP 7 V5.x)
- Configure the CP340/CP341 in HW Config: protocol = ASCII, baud 9600, 8-N-1, no handshake (or XON/XOFF if the receiver requires).
- Use FB P_SND_RK / FB P_RCV_RK (or the STEP 7 V13+ "PtP" library
Send_P2P) for ASCII send. - Map a 32-byte DB (e.g., DB850.DBB0..31) to a GUD in the NCK; have the part program populate it with formatted ASCII via
WRITEor via a custom cycle. - Trigger the PLC send on rising edge of a handshake flag from the NCK.
This path delivers < 10 ms latency and is the only one Siemens will sign off on for in-cycle production use.
Path 3 — Renishaw Probe Print Utility
For probing applications, Renishaw supplies an OMP / RFP print option for the 840D that streams probe results to a serial printer from the HMI. The original forum discussion states: "Renishaw claims to offer a print option for their probe software for the 840D that sends data to a serial printer." The print utility runs on the HMI side (Renishaw OMV / Reporter software) and outputs each measured feature to a configured COM port when the probe cycle completes. It is the closest out-of-the-box analogue to a DPRNT-style probe log on 840D.
Verify on the Renishaw installation that the target COM port is the one wired to your printer or DNC collector, and that the string format matches your downstream parser (Renishaw defaults to CSV with feature ID, X, Y, Z, D, TIR columns).
Path 4 — Ethernet / PROFINET to External RS232 Gateway
When the PCU has no free COM port, route the data over the plant network to a Comtrol, Moxa, or Siemens SCALANCE industrial gateway. The 840D side uses the HMI's Ethernet port or a CP343 / CP443 module on the PLC. The gateway exposes the downstream serial port as a TCP socket on the receiver. HMI scripts (Path 1) connect via MSWinsockLib.Winsock instead of MSComm; PLC code uses TCON / TSEND (S7-300/400 Open Communication blocks).
This path is preferred on 840D sl with HMI-Operate where direct COM access from a VB script is increasingly restricted by Windows UAC.
Comparison: Fanuc DPRNT vs Sinumerik 840D Equivalents
| Function | Fanuc | Sinumerik 840D |
|---|---|---|
| Open channel | POPEN |
None — use Windows MSComm.PortOpen = True on HMI |
| Write formatted string | DPRNT["TEXT"<<var] |
None — use NC WRITE + HMI script / PLC FB |
| Close channel | PCLOS |
None — MSComm.PortOpen = False on HMI |
| Channel select (ch=1..4) | Parameter I/O CH + DPRNT |
Select COM port in HW config / registry |
| Trigger to PLC | Direct | Use M-function, GUD, or $AC_MEAS_TYPE |
| In-cycle real-time output | Yes | Only via PLC + CP340/CP341 (Path 2) |
Step-by-Step: PCU50 HMI Script Implementation
- Confirm HMI part. Open Service & Commissioning → System → HMI Information on the operator panel and record the PCU part number (6FC5210-0DA20-0AA0 etc.). Only PCU50 / PCU50.3 / PCU70 / PCU70.3 support full Windows scripting.
- Validate COM1 hardware. Connect a serial terminal (e.g., PuTTY at 9600/8/N/1) to COM1, send a test string, verify loopback. Use a null-modem cable if the receiver is DTE.
-
Create the NC log file path. From the part program, run
WRITE("TEST", "//NC:/LOG/REPORT.DAT")once; verify with Start-up → File Manager that/LOG/REPORT.DATis created in the active file system. -
Install the VB script to
C:\dh\cus\hmisl\scripts\serial_out.vbson the PCU. -
Register the script in the HMI-Advanced startup sequence: edit
C:\dh\hmisl\ini\hmistart.iniand addTaskCreate("SerialOut", "wscript.exe", "C:\dh\cus\hmisl\scripts\serial_out.vbs")under the [STARTUP] section. Restart the HMI runtime. -
Verify with a part-program test. Run an MPF that executes
WRITE("HELLO!", "//NC:/LOG/REPORT.DAT")and confirm that the line "HELLO!" appears on the PuTTY terminal within ~500 ms. -
Validate cycle / production use. Run the actual measuring / marking cycle and capture the full output stream for at least one hour. Check that the script does not lose lines, that the file does not grow unbounded (implement log rotation: rename
REPORT.DATtoREPORT_YYMMDD.BAKat midnight), and that the receiver (DNC host / label printer) does not overrun the 9600-baud buffer.
Verification Checklist
- Output string matches NC-side format exactly (no extra CR/LF or missing parity bit).
- No line loss under worst-case 100-record burst at 200 ms per record.
- Latency between NCK
WRITEand COM1 byte-out is < 1 s for HMI script, < 50 ms for PLC path. - Receiver reports no framing errors over 24 h continuous run.
- Log file on the NC side is rotated or trimmed to prevent disk full.
- PCU reboot or HMI-Advanced crash correctly restarts the script (HMI start-up sequence validated).
Troubleshooting Matrix
| Symptom | Likely cause | Action |
|---|---|---|
| No data at receiver | Wrong COM port, wrong baud, or null-modem missing | Loopback test with PuTTY on the PCU itself |
| Script starts but no output | NCK WRITE path returns error 73 (file locked) or 78 (no rights) |
Check Operator Panel → Diagnostics → NC; ensure //NC:/LOG/ exists; check CF card for read-only |
| Latency > 2 s | WScript.Sleep too long, or HMI overloaded by other OEM apps | Drop sleep to 50 ms; remove anti-virus scan on the log path |
| Garbled characters | Parity / stop-bit mismatch, or PCU locale mismatch | Force ASCII mode in MSComm.Settings = "9600,N,8,1"; confirm receiver parity |
| Script crashes after 1 h | File handle leak, or log file renamed out from under the script | Reopen the file handle on each pass; add On Error Resume Next + Err.Clear |
| HMI Operate (not HMI-Advanced) | MSCOMM unavailable, Win7+ UAC blocks script write | Migrate to PROFINET gateway (Path 4) or run script as service with admin token |
Field-Commissioning Notes
- Siemens' 840D sl Commissioning Manual (6FC5397-0BP10-3AA0) and the HMI-Advanced Configuration Manual both confirm that the serial port is reserved for NC data backup, DNC streaming, and OEM use. They do not document an NC-side
DPRNTinstruction. - Renishaw OMV / Reporter for 840D ships with a sample .DEF file that maps probe cycles to a configured COM port — use it as a working reference even if your end device is not a printer.
- For multi-channel systems (NCU 720 with two channels), the per-channel GUD space is independent; declare a unique log file name per channel to avoid interleaved output.
- If you are migrating Fanuc post-processors that emit
DPRNT, the cleanest path is to keep the post-processor emitting a file (e.g., a network share\\PCU50\hmisl\dprnt\OUT.txt) and have the HMI script forward it; this lets the post-processor remain unmodified. - For safety-class applications, the PLC + CP341 path is the only one that allows a category-3 / SIL-2 controlled output; the HMI script path is non-safety.
Limitations and Edge Cases
-
No
DPRNTin NC syntax. Do not rely on undocumented behaviour or non-Siemens tools; the NCK build will fail to parse it. -
HMI Operate vs HMI-Advanced. On HMI Operate (PCU50.5 / PCU70.5 with Win7 embedded), the classic MSComm approach is fragile; prefer a Python or C# service that uses
System.IO.Ports.SerialPort, or move to PROFINET. - Real-time in-cycle output is unsupported via HMI script. If the application needs deterministic in-cycle response (e.g., a post-process measurement triggering an immediate actuator), use the PLC + CP340/CP341 path with the NCK handshake via a user-defined M-function or GUD flag.
-
File-based output is asynchronous. The NCK
WRITEmay not flush before the next block; add aSTOPREif the next block depends on the file being committed. - Disk full on PCU. The 840D PCU disk is small; always implement log rotation and monitor free space from the HMI diagnostic screen.
Selecting the Right Path
-
Out-of-cycle logs, tool-life, machine-condition reports, slow events: NC
WRITE+ HMI VB script (Path 1) — simplest, no extra hardware. - In-cycle real-time probe / gauging with deterministic latency: PLC + CP340/CP341 (Path 2).
- Probing only, on a Renishaw-equipped machine: Renishaw OMV print utility (Path 3).
- PCU without free COM, or HMI Operate (Win7+): PROFINET / Ethernet gateway (Path 4).
Is there a direct DPRNT instruction in Sinumerik 840D part programs?
No. Siemens does not provide a NC-part-program instruction that streams formatted ASCII to the RS232 port. The HMI side owns the COM ports on PCU50 / PCU50.3 / PCU70; the NCK has no path to push bytes to a UART.
Which HMI hardware supports a real RS232 user port?
PCU50, PCU50.3, PCU70, and PCU70.3 with HMI-Advanced or HMI-Operate expose COM1 (9-pin D-sub) and COM2. PCU20 (HMI-Embedded) has limited COM availability and is not recommended for the VB-script workaround. HT8 handheld terminals have no serial port.
What is the closest equivalent to Fanuc DPRNT for Renishaw probes on 840D?
Renishaw OMV / Reporter for 840D includes a print option that streams measured features to a configured serial port. It is the closest out-of-the-box equivalent for probe logging only, and is documented in the Renishaw OMP / RFP installation manual for 840D.
How do I send RS232 data in real time, in cycle, on 840D?
Use the PLC + CP340/CP341 path. Have the NC part program set a GUD or trigger an M-function, the PLC reads the trigger in OB1 (1–10 ms), builds a string, and calls the CP340/CP341 send FB. Latency is < 50 ms and is deterministic.
Can I just open a serial port from the NCK with WRITE?
No. The NCK WRITE instruction writes only to NC-side logical files (//NC:/, //PLC:/, //DRIVE:/). It cannot target a Windows COM port. The COM port is a Windows resource owned by the HMI runtime, not the NCK.