I have to confess that I am too dumb to get the C-code right. My disgust for C probably is not helping much either.
Anyway, I grabbed together a bunch of sample code of which I think it is going into the right direction, but still, it does not work:
In Max, I am doing this:
Anyway, I grabbed together a bunch of sample code of which I think it is going into the right direction, but still, it does not work:
#include <stdio.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> #include <errno.h> #include <paths.h> #include <termios.h> #include <sysexits.h> #include <sys/param.h> #include <sys/select.h> #include <sys/time.h> #include <time.h> #include <CoreFoundation/CoreFoundation.h> #include <IOKit/IOKitLib.h> #include <IOKit/serial/IOSerialKeys.h> #include<IOKit/IOBSD.h> #define B460800 0010004 int MyOpenSerialPort() { int fd = -1; struct termios options; fd = open( "/dev/tty.NXT_1" , O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd == -1) { return -1; } tcgetattr(fd, &options); options.c_iflag = INPCK; options.c_lflag = 0; options.c_oflag = 0; options.c_cc[VMIN] = 1; options.c_cc[VTIME] = 2000; options.c_cflag |= CS8 ; cfsetspeed(&options, B460800); tcsetattr( fd, TCSANOW, &options ); ioctl(fd, TIOCSDTR); int handshake = TIOCM_DTR | TIOCM_RTS | TIOCM_CTS | TIOCM_DSR; ioctl(fd, TIOCMSET, &handshake); return fd; } int MyCloseSerialPort( int fd ) { return close( fd ); }
In Max, I am doing this:
Import "term.c" Extern Function MyOpenSerialPort:Int( cPort:String ) Function MyCloseSerialPort:Int( fd:Int ) End Extern Print MyOpenSerialPort( "/dev/tty.NXT_1" ) NXTWrite:TStream = WriteStream( "/dev/tty.NXT_1" ) If Not NXTWrite Print "Failed to open write stream." End End If NXTRead:TStream = ReadStream( "/dev/tty.NXT_1" ) If Not NXTRead Print "Failed to open read stream." End End If WriteShort( NXTWrite, $06 ) WriteByte( NXTWrite, $00 ) WriteByte( NXTWrite, $03 ) WriteShort( NXTWrite, 4000 ) WriteShort( NXTWrite, 600 ) FlushStream( NXTWrite )