|
ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
|
Layer: L7 Application ยท Build flags: PC_ENABLE_SIMATIC
Before PROFINET, Siemens controls talked to computers over a serial point-to-point link: 3964R (the byte-oriented link protocol on the S5/S7 PtP CP modules - CP 341 / CP 441 / CP 524 / CP 525) carrying RK512 computer-link telegrams. services/simatic is a zero-heap codec for both; the RS-232 / RS-485 UART is normally the application's.
3964R frames a block as STX <payload, DLE bytes doubled> DLE ETX [BCC] with an interactive handshake - the sender emits STX and waits for the receiver's connect DLE, sends the block, waits for the end DLE/NAK, and retries on timeout; the receiver arbitrates a simultaneous-STX collision by station priority. The "R" variant's BCC is the longitudinal XOR of the block (a doubled DLE pair cancels). RK512 rides inside as a fixed-header SEND (write words) / FETCH (read words) telegram addressing a DB / flag / I-O area, big-endian words, answered by a reaction telegram.
The sketch runs two link stations on one board - A (high priority) and B (low priority) - and cross-wires their byte sinks, so it drives the whole 3964R handshake + an RK512 FETCH round-trip against itself. A completed round increments a counter served at GET /simatic:
On a real installation station A is this device and station B a Siemens PtP CP over an RS-232/RS-485 UART - feed the UART's received bytes to pc_3964r_rx_byte and let the state machine's tx sink write the UART.
The complete sketch is SimaticSerial.ino. The codec is in src/services/fieldbus/simatic/simatic.h; the 3964R handshake, XOR-BCC, QVZ/ZVZ timeouts and the RK512 header follow the Siemens "3964(R) transmission protocol" and "RK 512
computer link" CP-module manuals, cross-checked byte-for-byte against an independent python reference peer (test/servers/peers/simatic_peer.py). Pairs with the HaasMdc machine-tool example. The MELSEC and FANUC FOCAS codecs ship as services (src/services/fieldbus/melsec, src/services/machine_tool/focas) but have no example yet.