(1st posted this in the wrong forum - reposting here)
New to Maestro. I have a working setup using a Maestro 6 where it drives a Hobbywing motor controller and a motor. I have this working on a Windows PC running the Maestro Control Center program, but I need to get this working on a Mac mini from a C program.
When I plug the Maestro’s USB cable into the Mac, OS X auto-creates 2 serial devices, /dev/cu.usbmodem00026231 and /dev/cu.usbmodem00026233. The documentation says the lower numbered device is the command port. My C program can open the device, set tty attributes on it, and write to it, but the motor never moves. I can see the green LED on the Maestro flicker, so I know data is coming into the Maestro over the USB line, but nothing happens.
Here is my (very) short but complete C program. It uses the ‘mini SSC protocol’ and is based on the sample code in the documentation.
Thanks for your help!
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
int main(int argc, const char * argv[])
{
////////////////////////////////////////////////////////
// Open the Maestro's virtual serial port
const char * device = "/dev/cu.usbmodem00026231"; // Mac OS X cmd port
int fd = open(device, O_RDWR | O_NOCTTY);
if (fd == -1) {
perror(device);
return -1;
}
////////////////////////////////////////////////////////
// Set the serial port's attributes and baud rate
speed_t baudRate = B9600;
struct termios options;
tcgetattr(fd, &options);
options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
options.c_oflag &= ~(ONLCR | OCRNL);
cfsetspeed( &options, baudRate );
tcsetattr(fd, TCSANOW, &options);
////////////////////////////////////////////////////////
// Command the servo
unsigned char val = 0;
for (val=0x00;val<0xFF;val++) {
unsigned char command[] = {0xFF, 0x00, val};
if ( write(fd, command, sizeof(command)) == -1) {
perror("error writing");
return -1;
}
}
close(fd);
return 0;
}