|
ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
|
Layer: L7 Application ยท Build flags: PC_ENABLE_HAAS_MDC
Haas CNC mills and lathes answer a small, fully-documented Machine Data Collection (MDC) query set - the ?Q commands - over RS-232 or a raw TCP socket (turned on by Setting 143, default port 5051). It is the cheapest way to pull live machine status (serial, model, mode, active program, run status, parts counter, any macro/system variable) with no vendor middleware. services/haas_mdc is a pure codec for it; the sketch owns the socket.
You send an uppercase ?Q### line; the control replies with a comma-delimited payload framed between STX (0x02) and ETB (0x17), followed by CR LF and a > prompt:
The codec builds the queries and decodes the replies - scanning for the STX/ETB delimiters (never fixed offsets), so read_frame just accumulates bytes through the ETB:
Q500 has two branches (running/idle vs STATUS, BUSY); an unsupported or lowercase command returns UNKNOWN (pc_haas_mdc_is_error). A running G-code program can also push DPRNT(...) lines on the same link - raw CRLF text with no STX/ETB - which pc_haas_mdc_dprnt_line separates from framed Q replies.
Point HAAS_IP at a Haas control with MDC enabled (Setting 143 on, note its port). No machine handy? A small socket server that echoes the <STX>...<ETB>\r\n> frames for each ?Q (the vectors above) works for a dry run.
Flash and watch Serial @ 115200:
The complete sketch is HaasMdc.ino. The codec itself is in src/services/machine_tool/haas_mdc/haas_mdc.h; the request framing, the STX/ETB response wrapper, and the Q100/Q104/Q500/Q600 field layouts are verified against the Haas MDC service manual (Setting 143) and cross-checked byte-for-byte against a production Haas serial adapter. Pairs with the Umati and Fanuc FOCAS machine-tool examples.