I install USB driver on my laptop, my COM seems to be well installed but when i send command in HEX format i only receive echo, and the pololu TRex Configurator tool can’t connect to the TRex, the message is : Could not detect a TRex motor controler on port COM4.
The LED FeedBack are correct, the Blue for power and the RED for Serial are turn ON. I do not know what I 've missed, any ideas ?
If I used “TReXConfigurator_1_0_0_5.application” instead of “TReXConfigurator.application” everything works fine.
I have one more question. Do you any C API to control the motor. With methods like moveForward(10) which will connect to the network, set an accelaration and send it ?
float _targetSpeed;
int _targetAngle;
float _targetDistance;
float _currentDistance;
int _isParked;
int fd = 0;
int w = 0;
char err[100];
struct termios settings;
void main()
{
/* Config port settings*/
fd = open("/dev/ttyUSB0",O_RDWR);// | O_NOCTTY | O_NDELAY
if(fd < 0)
{
perror("open port: Unable to open ttyUSB0 --- \n");
strcpy(err,"open port: Unable to open ttyUSB0 --- \n");
}
else
{ printf("Open Success\n");
}
tcgetattr(fd, &settings);
cfsetospeed(&settings, BAUD); /* baud rate */
settings.c_cflag &= PARENB; /* no parity */
settings.c_cflag &= CSTOPB; /* 1 stop bit */
settings.c_cflag &= CSIZE;
settings.c_cflag |= CS8 | CLOCAL; /* 8 bits */
//settings.c_lflag = ICANON; /* canonical mode */
//settings.c_oflag &= OPOST; /* raw output */
tcsetattr(fd, TCSANOW, &settings); /* apply the settings */
tcflush(fd, TCOFLUSH);
int var;
var = 0x83;
w = write (fd,"0xC5",2); //Accelerate motor 1
printf("Sent w = %d", w);
w = write (fd,"0x7F",2); //Accelerate motor 1
//char buf [100];
//int n = read (fd, buf, sizeof buf);
//printf("A recu w = %d", n);
close(fd);
}[/code]
I see that the green led turn on when packet are received and w = 2 but nothing append for the acceleration. I have try without “” and using &var, Any ideas ?
It looks like you are sending ASCII data instead of sending binary bytes, and that you have the number of bytes incorrectly set to 2. Instead of trying to send something like this:
You should write the byte like this:
Also, it looks like you might be using the &= operator in a way is not appropriate. You should take a look at the equivalent code in this C code example, and use it as a starting point for writing your own code.