RS232 return values
- slauziere
- Topic Author
sww wrote: Our linux software ended up working much like what Cosma described. We read into a buffer whenever there are characters on the serial port. The commands are written asnychronously.
I started out trying to time/wait for things to happen, but the code did not work well.
You problem sounds like a software problem with your buffer, not an hardware issue.
Cool, I am glad to hear it is working for you.
I am wanting to run these queries/commands inside of a time-sensitive application, so being able to time the queries and returns would be nice. The time/wait is definitely giving problems, as well as a possible buffer issue. I realized it definitely wasn't a hardware issue (meaing motor controller) after it was working with minicom. I think I can make this work using async i/o however. I am also going to play with canonical vs. non-canonical as well.
Please Log in or Create an account to join the conversation.
- slauziere
- Topic Author
I got it working with the above code, with this line addition to the serial port init.
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
Basically, it needed to be set to non-canonical mode.
I found this link helpful:
www.faqs.org/docs/Linux-HOWTO/Serial-Programming-HOWTO.html
for anyone who might be trying the same thing.
Please Log in or Create an account to join the conversation.
- russell
My robotics club is building a linux robot, and were having some trouble with the communications. I think we are configuring something wrong, so I was playing with the options you use, but I cant seem to the "ioctl(fd, TCFLSH, 2);" working. What .h is that defined in, and are you defining TCFLSH someplace? Or do we even need that line?
Please Log in or Create an account to join the conversation.
- russell
#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 */
#include <stdlib.h> /* Some random library we found in a book */
#include <sys/ioctl.h> /*would seem to have something to do with that ioctl function*/
int fd; /* File descriptor for the port */
int main()
{
open_port();
close(fd);
}
int open_port(void)
{
fd = open("/dev/ttyS0", O_RDWR|O_NDELAY);
if(fd != -1)
{
struct termios options;
tcgetattr(fd, &options);
/*set to 9600 7bit even parity, no flow control*/
cfsetispeed(&options, B9600);
cfsetospeed(&options, B9600);
options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag |= PARENB;
options.c_cflag &= ~PARODD;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS7;
options.c_cflag &= ~CRTSCTS;
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); /*non Canonical*/
tcsetattr(fd, TCSANOW, &options);
ioctl(fd, TCFLSH, 2);
}
}
Please Log in or Create an account to join the conversation.
- russell
"), not the more standard (at least in UNIX) newline ("
"). That seems to have solved all of our problems, I cant believe I didnt think of that sooner.
Please Log in or Create an account to join the conversation.
- slauziere
- Topic Author
post back if you need help with any other gotchas.
And for those curious about the system where the controllers were used, check out our website:
<a target="_blank" href="www.niitek.com">www.niitek.com
the "latest news" section contains the story/summary of the system that uses two Roboteq controllers, one in RC mode and one in RS232 mode.
We have integrated the AX1500s into a similar project now, as well.
-steve
Please Log in or Create an account to join the conversation.
- pablo
<a target="_blank" href="www.tsatechnologies.com/roboteq_api.pdf">RoboteQ API
Although code examples are in VB, the string sequences are the same, info on the "Input Control Modes" diagram let me switch modes easily between RC/RS-232/etc..
cheers,
Pablo Rivera
Please Log in or Create an account to join the conversation.