From 5dfb7c6d4a48bbf408bdbf2e28d11684d8b6625b Mon Sep 17 00:00:00 2001 From: John Lewin Date: Wed, 9 May 2018 15:22:31 -0700 Subject: [PATCH] Add missing SerialHelper files --- .../SerialHelper/SetSerial.c | 60 +++++++++++++++++++ MatterControl.Printing/SerialHelper/build.sh | 11 ++++ 2 files changed, 71 insertions(+) create mode 100644 MatterControl.Printing/SerialHelper/SetSerial.c create mode 100644 MatterControl.Printing/SerialHelper/build.sh diff --git a/MatterControl.Printing/SerialHelper/SetSerial.c b/MatterControl.Printing/SerialHelper/SetSerial.c new file mode 100644 index 000000000..77b82d6cb --- /dev/null +++ b/MatterControl.Printing/SerialHelper/SetSerial.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include + +int ioctl(int d, int request, ...); + +int set_baud (char *devfile, int baud); + +int set_baud(char *devfile, int baud) +{ + +#ifndef __linux__ + return 0; +#endif + + struct termios2 t; + int fd; + + fd = open(devfile, O_RDWR | O_NOCTTY | O_NDELAY); + + if (fd == -1) + { + fprintf(stderr, "error opening %s: %s", devfile, strerror(errno)); + return 2; + } + + if (ioctl(fd, TCGETS2, &t)) + { + perror("TCGETS2"); + return 3; + } + + printf("SetSerial: Reported speed before update %d\n", t.c_ospeed); + + t.c_cflag &= ~CBAUD; + t.c_cflag |= BOTHER; + t.c_ispeed = baud; + t.c_ospeed = baud; + + if (ioctl(fd, TCSETS2, &t)) + { + perror("TCSETS2"); + return 4; + } + + if (ioctl(fd, TCGETS2, &t)) + { + perror("TCGETS2"); + return 5; + } + + + //close(fd); + + printf("SetSerial: Reported speed after update %d\n", t.c_ospeed); + return 0; +} diff --git a/MatterControl.Printing/SerialHelper/build.sh b/MatterControl.Printing/SerialHelper/build.sh new file mode 100644 index 000000000..ed4d66339 --- /dev/null +++ b/MatterControl.Printing/SerialHelper/build.sh @@ -0,0 +1,11 @@ +# Build libSetSerial.so +gcc -m32 -shared -fPIC SetSerial.c -o libSetSerial.so -v +gcc -shared -fPIC SetSerial.c -o libSetSerial -v + +# Create path if needed +mkdir -p ../../../../bin/Debug/ +mkdir -p ../../../../bin/Release/ + +# Copy to MatterControl build directories +cp libSetSerial* ../../../../bin/Debug/ +cp libSetSerial* ../../../../bin/Release/