Skip navigation.

Write FreeBSD C program to talk to the Digital Servo controller

Having problems writing a C program to talk to the Digital Servo controller. I can see the serial breakout LED blink when I send the 3 bytes, but the servo doesn't respond. Two things to look into: 1. Is the program working ok, at the correct baud rate (9600b). 2. Is there a serial cable wiring problem. The board only needs two wires. I am sure I have the correct ones, but does the serial port need some sort of feed back, ie. DTR-CTS etc. Note: I am attempting to run my Mark I ASC on FreeBSD. Please forgive any blantent errors in the code, as I know very little about writting C code :-( Here is the 'test' code: #include #include #include #include #include /*Originally it was termio.h*/ #include #include static char *opt_comport="/dev/cuaa0"; int main(int argc, char **argv) { int fd; struct termios options; int synb = 0xFF; // Sync byte int addb = 0x01; // Address Byte int valb = 0x31; // Servo value ( 0-255 ) // ok, lets try opening the com port printf("Opening Com port: %s\n\n", opt_comport); if((fd = open(opt_comport, O_RDWR | O_NOCTTY | O_NDELAY)) < 0) { err(1, "Opening Com Port"); printf("Problems opening %s\n", opt_comport); return (-1); } // set the required com port parrameters options.c_cflag &= ~CSIZE; /* Mask the character size bits */ options.c_cflag |= CS8; /* Select 8 data bits */ options.c_cflag &= ~PARENB; // set no parity options.c_cflag &= ~CSTOPB; // set 1 stop bit options.c_oflag &= ~OPOST; // Raw output tcgetattr(fd, &options); /* * Set the baud rates to 9600... */ cfsetispeed(&options, B9600); cfsetospeed(&options, B9600); /* * Enable the receiver and set local mode... */ options.c_cflag |= (CLOCAL | CREAD); /* * Set the new options for the port... */ tcsetattr(fd, TCSANOW, &options); // ok, lets transmit our 3 bytes to com port 1 if(write(fd, &synb, 1) !=1) err(1, "write"); if(write(fd, &addb, 1) !=1) err(1, "write"); if(write(fd, (int*)&valb, 1) !=1) err(1, "write"); exit(1); };