Ok,
I have done some more thorough testing and it seems that there might be a buffer issue. I was able to talk to both boards and drive all four motors with the rx lines connected, but! I had to write the commands several times to successfully get the message across. Should I be sending null bits to clear the buffers? I made sure to keep an eye on the boards status light, which did not flicker every time my program was supposed to be sending off a packet.
Ideas??
I'm using the C code that was posted here a while back for testing... writing my full driver at the moment in C++
Code:
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
int fd;
int setSpeed();
int main(int argc, char **argv) {
unsigned char sCmd[256];
unsigned char encbuf[64];
ssize_t enc;
char c;
// Open the port and initialize //
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1) {
perror("open_port: Unable to open /dev/ttyUSB0 - ");
return 1;
} else {
fcntl(fd, F_SETFL, 0);
}
InitPort(fd);
cCmd[0] = 0;
// Address, Cmd, Value, CHK SUM //
// int Speed = 100;
// Motor 1 //
sCmd[0] = 129;
sCmd[1] = 0;
sCmd[2] = 90;
//sCmd[2] = ((Speed >> 0) & 0xFF);
//sCmd[3] = ((Speed >> 8) & 0xFF);
//sCmd[4] = ((Speed >> 16) & 0xFF);
//sCmd[5] = ((Speed >> 24) & 0xFF);
//sCmd[6] = (sCmd[0]+sCmd[1]+sCmd[2]+sCmd[3]+sCmd[4]+sCmd[5]) & 0x7F;
sCmd[3] = (sCmd[0] + sCmd[1] + sCmd[2]) & 0x7F;
// Error checking //
printf("This is: %x\n",sCmd[0]);
printf("This is: %x\n",sCmd[1]);
printf("This is: %x\n",sCmd[2]);
printf("This is: %x\n",sCmd[3]);
//printf("This is: %x\n",sCmd[4]);
//printf("This is: %x\n",sCmd[5]);
//printf("This is: %x\n",sCmd[6]);
/////////////////////////////////
// write data to the port //
if (!writeport(fd, sCmd, 7)) {
printf("write failed\n");
close(fd);
return 1;
}
}
int writeport(int fd, char * chars, int NBytes) {
int n = write(fd, chars, NBytes);
if (n < 0) {
fputs("write failed!\n", stderr);
return 0;
}
return 1;
}
int InitPort(int fd) {
struct termios config;
config.c_iflag &= ~(IGNBRK | BRKINT | ICRNL | INLCR | PARMRK | INPCK | ISTRIP | IXON);
config.c_oflag = 0;
//
// No line processing:
// echo off, echo newline off, canonical mode off,
// extended input processing off, signal chars off
//
config.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
//
// Turn off character processing
// clear current char size mask, no parity checking,
// no output processing, force 8 bit input
//
config.c_cflag &= ~(CSIZE | PARENB);
config.c_cflag |= CS8;
config.c_cflag |= (CLOCAL | CREAD);
//
// One input byte is enough to return from read()
// Inter-character timer off
//
config.c_cc[VMIN] = 1;
config.c_cc[VTIME] = 0;
//
// Communication speed (simple version, using the predefined
// constants)
//
if(cfsetispeed(&config, B9600) < 0 || cfsetospeed(&config, B9600) < 0)
printf("Baud not set \n " );
//
// Finally, apply the configuration
//
if(tcsetattr(fd, TCSAFLUSH, &config) < 0)
printf( "Config Not Applied \n");
return 1;
}