<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Guides on LinuxCNC gRPC</title><link>https://doug.sh/docs/linuxcnc-grpc/guides/</link><description>Recent content in Guides on LinuxCNC gRPC</description><generator>Hugo</generator><language>en</language><atom:link href="https://doug.sh/docs/linuxcnc-grpc/guides/index.xml" rel="self" type="application/rss+xml"/><item><title>Sending commands and waiting</title><link>https://doug.sh/docs/linuxcnc-grpc/guides/commands/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doug.sh/docs/linuxcnc-grpc/guides/commands/</guid><description>&lt;p&gt;This page says what the answers of &lt;code&gt;SendCommand&lt;/code&gt; and &lt;code&gt;WaitComplete&lt;/code&gt; mean. Their fields are&#10;in the &lt;a href="https://doug.sh/docs/linuxcnc-grpc/api-reference/linuxcnc-service/#sendcommand"&gt;API reference&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;The usual sequence:&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;Set the mode or teleop the command needs and wait for it (&lt;a href="#sequencing"&gt;Sequencing&lt;/a&gt;).&lt;/li&gt;&#10;&lt;li&gt;Send the command and check &lt;code&gt;status&lt;/code&gt;. On &lt;code&gt;RCS_ERROR&lt;/code&gt;,&#10;&lt;a href="#not_sent-says-when-a-retry-is-safe"&gt;&lt;code&gt;not_sent&lt;/code&gt;&lt;/a&gt; says whether a retry is safe.&lt;/li&gt;&#10;&lt;li&gt;Check the response&amp;rsquo;s &lt;code&gt;connection_id&lt;/code&gt;, then call &lt;code&gt;WaitComplete&lt;/code&gt; with its &lt;code&gt;linuxcnc_serial&lt;/code&gt;&#10;(&lt;a href="#with-linuxcnc_serial-one-command"&gt;one command&lt;/a&gt;).&lt;/li&gt;&#10;&lt;li&gt;Confirm the result from a fresh status (&lt;a href="#what-the-answer-means"&gt;What the answer means&lt;/a&gt;).&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;h2 id="sendcommand-answers-when-the-command-is-dispatched"&gt;&lt;code&gt;SendCommand&lt;/code&gt; answers when the command is dispatched&lt;a class="anchor" href="#sendcommand-answers-when-the-command-is-dispatched" aria-label="Link"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;code&gt;RCS_DONE&lt;/code&gt; from &lt;code&gt;SendCommand&lt;/code&gt; means &amp;ldquo;dispatched&amp;rdquo;, not &amp;ldquo;finished&amp;rdquo;. An MDI move or a homing&#10;sequence is usually still running when the response arrives. To know when it has finished,&#10;call &lt;a href="#waitcomplete"&gt;&lt;code&gt;WaitComplete&lt;/code&gt;&lt;/a&gt; and confirm from the status.&lt;/p&gt;</description></item><item><title>Stops go first</title><link>https://doug.sh/docs/linuxcnc-grpc/guides/stops/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doug.sh/docs/linuxcnc-grpc/guides/stops/</guid><description>&lt;p&gt;A stop is a command that can only stop something: &lt;code&gt;state&lt;/code&gt; &lt;code&gt;STATE_ESTOP&lt;/code&gt; or&#10;&lt;code&gt;STATE_OFF&lt;/code&gt;, &lt;code&gt;program&lt;/code&gt; &lt;code&gt;abort&lt;/code&gt; or &lt;code&gt;pause&lt;/code&gt;, &lt;code&gt;jog&lt;/code&gt; &lt;code&gt;JOG_STOP&lt;/code&gt; and &lt;code&gt;spindle&lt;/code&gt;&#10;&lt;code&gt;SPINDLE_CMD_OFF&lt;/code&gt;. Nothing else counts. Brake engage is not a stop, because&#10;braking a turning spindle is not plainly harmless. An override set to zero is&#10;not one either.&lt;/p&gt;&#10;&lt;p&gt;LinuxCNC has one command queue for all its clients, and nothing overtakes a&#10;message once it is written there. The server decides only which of the&#10;messages it has not written yet goes next. It sends stops first and refuses&#10;the commands a stop overtakes.&lt;/p&gt;</description></item><item><title>Errors and reasons</title><link>https://doug.sh/docs/linuxcnc-grpc/guides/errors/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doug.sh/docs/linuxcnc-grpc/guides/errors/</guid><description>&lt;p&gt;The server answers a failed RPC with a gRPC status code. For four conditions it also sends&#10;the trailing metadata entry &lt;code&gt;linuxcnc-grpc-reason&lt;/code&gt;, so a client can act on the condition&#10;without parsing the message. A 1.0 server sends no such entry.&lt;/p&gt;&#10;&lt;p&gt;A command LinuxCNC or the server refuses is not a gRPC error: &lt;code&gt;SendCommand&lt;/code&gt; answers normally&#10;with &lt;code&gt;RCS_ERROR&lt;/code&gt; and a message, for example &amp;ldquo;Too many commands are waiting; the command was&#10;not sent&amp;rdquo; with &lt;code&gt;not_sent&lt;/code&gt; true. &lt;a href="https://doug.sh/docs/linuxcnc-grpc/guides/commands/#rcs_error-from-sendcommand"&gt;&lt;code&gt;RCS_ERROR&lt;/code&gt; from &lt;code&gt;SendCommand&lt;/code&gt;&lt;/a&gt;&#10;lists the causes and when &lt;code&gt;not_sent&lt;/code&gt; makes a retry safe.&lt;/p&gt;</description></item><item><title>Error messages and the GUI</title><link>https://doug.sh/docs/linuxcnc-grpc/guides/error-messages/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doug.sh/docs/linuxcnc-grpc/guides/error-messages/</guid><description>&lt;p&gt;LinuxCNC&amp;rsquo;s error channel is one queue, and reading a message removes it. Each operator or&#10;NML error message goes to exactly one reader: the machine&amp;rsquo;s GUI or the server, never both.&#10;Nothing can look at a message without taking it or put it back, so the server cannot read&#10;invisibly. It reads in one place, shares what it read with every client, and lets you choose&#10;whether it reads at all.&lt;/p&gt;</description></item><item><title>Telling servers and connections apart</title><link>https://doug.sh/docs/linuxcnc-grpc/guides/identity/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doug.sh/docs/linuxcnc-grpc/guides/identity/</guid><description>&lt;p&gt;LinuxCNC&amp;rsquo;s command serials and the server&amp;rsquo;s error &lt;code&gt;sequence&lt;/code&gt; numbers start again after a&#10;restart, so a number alone cannot say which LinuxCNC or which server it came from. Two&#10;values can. Both are opaque strings: compare them, do not parse them. A server older than&#10;these fields sends them empty.&lt;/p&gt;&#10;&lt;h2 id="server_instance-and-connection_id"&gt;&lt;code&gt;server_instance&lt;/code&gt; and &lt;code&gt;connection_id&lt;/code&gt;&lt;a class="anchor" href="#server_instance-and-connection_id" aria-label="Link"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;code&gt;ServerInfo.server_instance&lt;/code&gt; is random per server, one per process for the &lt;code&gt;linuxcnc-grpc&lt;/code&gt;&#10;command. It changes whenever the server is restarted.&lt;/p&gt;</description></item><item><title>Examples guide</title><link>https://doug.sh/docs/linuxcnc-grpc/guides/examples/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doug.sh/docs/linuxcnc-grpc/guides/examples/</guid><description>&lt;p&gt;The repository has six example programs, each in Python, Go, Node.js and Rust. This page shows&#10;what each one does, how to run it, the few lines that matter and what it prints. The full&#10;programs are in &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/tree/main/examples"&gt;&lt;code&gt;examples/&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;&#10;&lt;table&gt;&#10;&#9;&lt;thead&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;Example&lt;/th&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;What it does&lt;/th&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;Source&lt;/th&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&lt;/thead&gt;&#10;&#9;&lt;tbody&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="#get_status"&gt;&lt;code&gt;get_status&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Reads the machine status once and prints it&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/python/get_status.py"&gt;Python&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/go/cmd/get_status/main.go"&gt;Go&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/node/get_status.ts"&gt;Node.js&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/rust/src/bin/get_status.rs"&gt;Rust&lt;/a&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="#stream_status"&gt;&lt;code&gt;stream_status&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Streams live status updates for a display&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/python/stream_status.py"&gt;Python&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/go/cmd/stream_status/main.go"&gt;Go&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/node/stream_status.ts"&gt;Node.js&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/rust/src/bin/stream_status.rs"&gt;Rust&lt;/a&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="#jog_axis"&gt;&lt;code&gt;jog_axis&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Jogs X by a fixed increment, then jogs Y continuously for half a second&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/python/jog_axis.py"&gt;Python&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/go/cmd/jog_axis/main.go"&gt;Go&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/node/jog_axis.ts"&gt;Node.js&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/rust/src/bin/jog_axis.rs"&gt;Rust&lt;/a&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="#mdi_command"&gt;&lt;code&gt;mdi_command&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Runs MDI G-code, one command or an interactive session&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/python/mdi_command.py"&gt;Python&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/go/cmd/mdi_command/main.go"&gt;Go&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/node/mdi_command.ts"&gt;Node.js&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/rust/src/bin/mdi_command.rs"&gt;Rust&lt;/a&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="#hal_query"&gt;&lt;code&gt;hal_query&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Queries HAL pins, signals, parameters and components, or watches values&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/python/hal_query.py"&gt;Python&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/go/cmd/hal_query/main.go"&gt;Go&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/node/hal_query.ts"&gt;Node.js&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/rust/src/bin/hal_query.rs"&gt;Rust&lt;/a&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="#upload_file"&gt;&lt;code&gt;upload_file&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Uploads a sample G-code file and lists the files; deletes it only with &lt;code&gt;--cleanup&lt;/code&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/python/upload_file.py"&gt;Python&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/go/cmd/upload_file/main.go"&gt;Go&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/node/upload_file.ts"&gt;Node.js&lt;/a&gt;, &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/rust/src/bin/upload_file.rs"&gt;Rust&lt;/a&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;blockquote class='book-hint warning'&gt;&#10;&lt;p&gt;&lt;code&gt;jog_axis&lt;/code&gt; and &lt;code&gt;mdi_command&lt;/code&gt; move the machine. They never take it out of E-stop, power it&#10;on or home it, but they do change its mode and move axes. Never run untested code on a&#10;machine with a workpiece or near people. The complete rules the motion examples follow are&#10;in the &lt;a href="https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/README.md#what-the-motion-examples-do-and-do-not-do"&gt;examples README&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;</description></item><item><title>Monitor a job and send alerts</title><link>https://doug.sh/docs/linuxcnc-grpc/guides/job-monitor/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doug.sh/docs/linuxcnc-grpc/guides/job-monitor/</guid><description>&lt;p&gt;&lt;code&gt;job_monitor.py&lt;/code&gt; is a Python program that watches one machine and reports what its jobs do. It&#10;prints a line for each event, and can POST each one as JSON to a webhook, for a chat channel or&#10;a phone notification. It sends no commands. It needs a server of version 1.1 or newer.&lt;/p&gt;&#10;&lt;h2 id="before-you-start"&gt;Before you start&lt;a class="anchor" href="#before-you-start" aria-label="Link"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;a href="https://doug.sh/docs/linuxcnc-grpc/get-started/server-setup/#start-the-server"&gt;Start the server&lt;/a&gt; on the LinuxCNC machine,&#10;bound to &lt;code&gt;127.0.0.1&lt;/code&gt;. On the computer that runs the monitor, install the Python client and&#10;open an SSH tunnel, which runs until you stop it:&lt;/p&gt;</description></item><item><title>Log HAL values to CSV and Prometheus</title><link>https://doug.sh/docs/linuxcnc-grpc/guides/hal-logging/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doug.sh/docs/linuxcnc-grpc/guides/hal-logging/</guid><description>&lt;p&gt;&lt;code&gt;hal_logger.py&lt;/code&gt; is a Python program that writes chosen HAL values to a CSV file as they change.&#10;It uses one &lt;a href="https://doug.sh/docs/linuxcnc-grpc/api-reference/hal-service/#watchvalues"&gt;WatchValues&lt;/a&gt; stream, reconnects when&#10;the server goes away, and can serve the latest values to Prometheus. It sends no commands.&lt;/p&gt;&#10;&lt;h2 id="before-you-start"&gt;Before you start&lt;a class="anchor" href="#before-you-start" aria-label="Link"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;You need the server running on the LinuxCNC machine, bound to &lt;code&gt;127.0.0.1&lt;/code&gt; (see&#10;&lt;a href="https://doug.sh/docs/linuxcnc-grpc/get-started/server-setup/"&gt;Install and start the server&lt;/a&gt;), and Python 3.10 or newer on&#10;the computer that logs. If that is another computer, open an SSH tunnel, which runs until you&#10;stop it:&lt;/p&gt;</description></item><item><title>Use cases</title><link>https://doug.sh/docs/linuxcnc-grpc/guides/use-cases/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doug.sh/docs/linuxcnc-grpc/guides/use-cases/</guid><description>&lt;p&gt;What you can build on the server, with the RPCs each case uses and the thing to watch out for.&#10;Every case shares two facts. The server has no authentication or TLS, so anyone who reaches the&#10;port can send any command, even when your own client only reads (see&#10;&lt;a href="https://doug.sh/docs/linuxcnc-grpc/server/#security-considerations"&gt;Security considerations&lt;/a&gt;). And the status is&#10;sampled at an interval, so none of this is a real-time interface.&lt;/p&gt;&#10;&lt;h2 id="dashboards"&gt;Dashboards&lt;a class="anchor" href="#dashboards" aria-label="Link"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;A dashboard shows the state of one machine or of many: position, the program and its line,&#10;feed override and spindle speed, and whether the machine is on. Each machine runs its own server, and the&#10;dashboard opens one connection per machine.&lt;/p&gt;</description></item><item><title>FAQ</title><link>https://doug.sh/docs/linuxcnc-grpc/guides/faq/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doug.sh/docs/linuxcnc-grpc/guides/faq/</guid><description>&lt;h2 id="network"&gt;Is it safe on a network?&lt;a class="anchor" href="#network" aria-label="Link"&gt;&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Not on its own. The server has no authentication and no TLS, so anyone who can reach the port&#10;can jog the machine, run a program, and upload or delete files. Bind it to &lt;code&gt;127.0.0.1&lt;/code&gt; and&#10;connect through an SSH tunnel, or use it only on a trusted, isolated LAN. Without &lt;code&gt;--host&lt;/code&gt; the&#10;server listens on all interfaces, so pass &lt;code&gt;--host&lt;/code&gt; every time. See&#10;&lt;a href="https://doug.sh/docs/linuxcnc-grpc/server/#security-considerations"&gt;Security considerations&lt;/a&gt;.&lt;/p&gt;</description></item></channel></rss>