hzeller / gcode-cli

Simple command line tool to send gcode to serial 3D printer/CNC machine.
41 stars 6 forks source link

Compatibility with Mac #7

Open Divide-By-0 opened 10 months ago

Divide-By-0 commented 10 months ago

Currently, the code fails on Mac. We edited a few libraries:

#ifdef __linux__
#include <asm/termbits.h>
#elif defined(__APPLE__)
#include <termios.h>
#endif

But we still get this error on Mac:

 ./gcode-cli test.gcode /dev/tty.usbmodem14401 
libc++abi: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc
Abort trap: 6

Do you know what might cause this and how to fix this?

hzeller commented 10 months ago

Can you run this in a debugger and then report where the exception is happening ? With gdb, that would be:

gdb --args ./gcode-cli test.gcode /dev/tty.usbmodem14401
# then in gdb, type 'run'
# once it crashes, type 'bt'

(For maximum usefulness of the stacktrace, change the -O2 in the Makefile to -O0 -g)

There is one place where gcode-cli allocates a moderate buffer of 1 MiB size, which shouldn't be a problem, but maybe it is ? You'd see a crash when it allocates a buffer with it. You can try reducing the number in the following line to 1 << 19 or even 1 << 18

https://github.com/hzeller/gcode-cli/blob/c750865940a0d7bd2220edbc448b00b77cdf562a/main.cc#L169

... or maybe it is some other issue, which we'll see in the stacktrace.

hzeller commented 10 months ago

I've now also added a CI to compile on Mac. Had to change some code to not use a function that only exists on GNU systems. It compiles now on Mac, but of course this does not explain yet the crash you see.

hzeller commented 4 months ago

Did you ever get to run it through a debugger @Divide-By-0 ?

Divide-By-0 commented 4 months ago

Did you ever get to run it through a debugger @Divide-By-0 ?

Hey, we ended up finishing our project via just manually sending commands back and forth over the channel. The main notable thing that was non-standard might have been the 250K baud rate?

hzeller commented 4 months ago

Interesting, B250000 is not something provided by termios typically, so a connect-string with /dev/myterm,b250000 probaby would've error'ed out and complained about that.

Anyway, I am now changing it so that it provides all constants mentioned in my manpage not only the 'popular' speeds (for the TERMIOS case) and report an error if something failed there.

It would still not really explain the crash you have seen, but I also don't have a Mac to test.

hzeller commented 4 months ago

It looks like there is a way to set arbitrary speeds on the Mac, at least this is what I found online and implemented in https://github.com/hzeller/gcode-cli/commit/b2c306b8c7e0bd45fdf2085830cb63817070ea39

If you have time to test this on your machine, that would be great!