the code on my mac comandline tool looks like this:
#include <iostream>
#include <fcntl.h>
#include <termios.h>
const int BUFFER_SIZE = 8;
int output_buffer[BUFFER_SIZE];
char output_buffer2[BUFFER_SIZE][1];
int sendHDG = 1612;
using namespace std;
void init_port(int *fd, unsigned int baud)
{
struct termios options;
tcgetattr(*fd,&options);
switch(baud)
{
case 9600: cfsetispeed(&options,B9600);
cfsetospeed(&options,B9600);
break;
case 19200: cfsetispeed(&options,B19200);
cfsetospeed(&options,B19200);
break;
case 38400: cfsetispeed(&options,B38400);
cfsetospeed(&options,B38400);
break;
default:cfsetispeed(&options,B9600);
cfsetospeed(&options,B9600);
break;
}
options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
tcsetattr(*fd,TCSANOW,&options);
}
int main()
{
int fd;
fd = open("/dev/tty.usbmodemfa121", O_RDWR | O_NOCTTY | O_NDELAY);
if(fd == -1)
perror("open_port: unable to open port");
init_port(&fd,9600); //set serial port to 9600,8,n,1
write(fd, "12345678", BUFFER_SIZE);
return (0);
}