<p>Model of the printer is unknown, got it as present, probably something generic cartesian on arduino mega and ramps boards stitched together and with marlin firmware.</p>

<p>I've used accepted answer from here to try moving this thing from terminal.
<a href="https://3dprinting.stackexchange.com/questions/3112/how-to-directly-send-g-code-to-printer-from-a-linux-terminal">How to directly send G-code to printer from a Linux terminal?</a></p>

<p>My first attempt to get access to low-level printer interface looked like that: </p>

<pre><code>./baud.py &lt;&gt; /dev/ttyACM0 250000
tail -f /dev/ttyACM0 &amp;
cat &gt; /dev/ttyACM0
</code></pre>

<p>First it was fine: i've entered g-code, printer executed it and returned an ok message into my terminal.</p>

<p>Then i've turned the printer off and on again and repeated the whole process, but now <code>tail -f</code> didn't output anything and printer LCD displayed garbage in the status line after I ran the command.</p>

<p>I've also noticed that printer controller reboots every time the serial port is accessed, not sure if it happened in the first time when everything worked well.</p>

<p>The output of <code>cat /dev/ttyACM0</code> after baud setting is a bit weird too - and there's garbage in the status line instead of standard "%printername% ready" as well:</p>

<pre><code>start
echo:Marlin1.0.0
echo: Last Updated: May 20 2017 18:12:04 | Author: (none, default config)
Compiled: May 20 2017
echo: Free Memory: 3763  PlannerBufferBytes: 1232
echo:Hardcoded Default Settings Loaded
echo:Steps per unit:
echo:  M92 X80.00 Y80.00 Z3200.00 E97.94
echo:Maximum feedrates (mm/s):
echo:  M203 X50.00 Y50.00 Z2.50 E25.00
echo:Maximum Acceleration (mm/s2):
echo:  M201 X750 Y750 Z100 E10000
echo:Acceleration: S=acceleration, T=retract acceleration
echo:  M204 S500.00 T500.00
echo:Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s),  Z=maximum Z jerk (mm/s),  E=maximum E jerk (mm/s)
echo:  M205 S0.00 T0.00 B20000 X20.00 Z1.00 E5.00
echo:Home offset (mm):
echo:  M206 X0.00 Y0.00 Z0.00
echo:PID settings:
echo:   M301 P22.20 I1.08 D114.00
echo:SD init fail
echo:Unknown command: "starto"
ok
echo:Unknown command: "SD init failstartuthor"
ok
echo:Unknown command: " (none, default config)50.00 Z2.50 E2rBy00.00 Y0.00 Z0.00echo"
ok
echo:Unknown command: "Unknown command"
ok
echo:Unknown command: " "starto"own comm"
ok
echo:Unknown command: "aximum XY jerk (mm/s),  Z=maximum Z jerk (mm/s),  E=maximum E jerk (mm/s)echo"
ok
echo:Unknown command: "PID settings"
ok
echo:Unknown command: "okechecho"
ok
</code></pre>

<p>The "SD init fail" line and everything after it appears when sensor data appears on the LCD, there's a delay before that during which the LCD is empty.</p>

<p>If you send commands to printer using something like <code>echo "G0 X10" &gt; /dev/ttyACM0</code>, it executes them only on next serial port accessing (and therefore reboot) - or doesn't execute at all.</p>

<p>The interesting part is that Cura "Monitor" tab can actually manipulate the caret and the Cura itself can print things in general - but i want to be able to do it manually.</p>

[{'answer_id': 5385, 'author': 'mac', 'author_id': 9134, 'author_profile': 'https://3dprinting.stackexchange.com/users/9134', 'pm_score': 1, 'selected': False, 'text': '<p>Mine is a wild guess, but judging from:</p>\n\n<pre><code>echo:Unknown command: "starto"\nok\necho:Unknown command: "SD init failstartuthor"\nok\necho:Unknown command: " (none, default config)50.00 Z2.50 E2rBy00.00 Y0.00 Z0.00echo"\nok\necho:Unknown command: "Unknown command"\nok\necho:Unknown command: " "starto"own comm"\nok\necho:Unknown command: "aximum XY jerk (mm/s),  Z=maximum Z jerk (mm/s),  E=maximum E jerk (mm/s)echo"\nok\necho:Unknown command: "PID settings"\nok\n</code></pre>\n\n<p><strong>It looks like you may be looping back the output of your printer as an input to itself</strong>.  I am very suspicious of your line: <code>tail -f /dev/ttyACM0 &amp;</code> as that seems to indicate your are trying to perform other actions in the same terminal window after you started to monitor the serial connection.</p>\n\n<p>If this is the case, you should definitively <strong>open the monitor in a <em>separate</em> terminal</strong> (<code>tail -f /dev/ttyACM0</code>) and feed the input in a different one (note that yo must not use the final <code>&amp;</code>).</p>\n\n<p>Finally, you probably want to use <code>cat &gt;&gt; /dev/ttyACM0</code> instead of <code>cat &gt; /dev/ttyACM0</code> as you want to append your commands without truncating the existing stream.</p>\n'}, {'answer_id': 5386, 'author': 'Karashevich B.', 'author_id': 9824, 'author_profile': 'https://3dprinting.stackexchange.com/users/9824', 'pm_score': 1, 'selected': True, 'text': '<p>That\'s weird but i\'ve got some code from here: <a href="https://stackoverflow.com/questions/6947413/how-to-open-read-and-write-from-serial-port-in-c">https://stackoverflow.com/questions/6947413/how-to-open-read-and-write-from-serial-port-in-c</a> , changed it a little, removed few lines, ran it - and my port started working just fine. Here\'s the complete code (for Linux of course).</p>\n\n<p>I guess that was the c_lflag line that solved the problem.</p>\n\n<pre><code>#include &lt;asm/termios.h&gt;\n#include &lt;stropts.h&gt;\n#include &lt;unistd.h&gt;\n#include &lt;fcntl.h&gt;\n#include &lt;string.h&gt;\n\nint set_interface_attribs (int fd) {\n    struct termios2 tty;\n    memset (&amp;tty, 0, sizeof tty);\n    ioctl(fd, TCGETS2, &amp;tty);\n    tty.c_cflag&amp;=~CBAUD;\n    tty.c_cflag|=BOTHER;\n    tty.c_ispeed=tty.c_ospeed=250000;\n    tty.c_cflag = (tty.c_cflag &amp; ~CSIZE) | CS8;\n    tty.c_iflag &amp;= ~IGNBRK;\n    tty.c_lflag = 0;\n    tty.c_oflag = 0;\n    tty.c_cc[VMIN]  = 0;\n    tty.c_cc[VTIME] = 5;\n    tty.c_iflag &amp;= ~(IXON | IXOFF | IXANY);\n    tty.c_cflag |= (CLOCAL | CREAD);\n    tty.c_cflag &amp;= ~(PARENB | PARODD);\n    tty.c_cflag &amp;= ~CSTOPB;\n    tty.c_cflag &amp;= ~CRTSCTS;\n    ioctl(fd, TCSETS2, &amp;tty);\n    return 0;\n}\n\nint main() {\n    int fd=open("/dev/ttyACM0",O_RDWR|O_NOCTTY|O_SYNC);\n    set_interface_attribs(fd);\n    close(fd);\n    return 0;\n}\n</code></pre>\n'}]
['https://3dprinting.stackexchange.com/questions/5382', 'https://3dprinting.stackexchange.com', 'https://3dprinting.stackexchange.com/users/9824/']