Menu

Topic-icon RS232 return values

  • slauziere
  • slauziere's Avatar Topic Author
14 years 6 months ago #4064768 by slauziere
Replied by slauziere on topic RS232 return values
Thanks for your response, cosma. I will try the asynchronous i/o method.


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
  • slauziere's Avatar Topic Author
14 years 6 months ago #4065285 by slauziere
Replied by slauziere on topic RS232 return values
woohoo!!!

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
  • russell's Avatar
13 years 6 months ago #9738633 by russell
Replied by russell on topic RS232 return values
Ok, I know this thread is pretty old, but maybe someone still knows...

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
  • russell's Avatar
13 years 6 months ago #9738893 by russell
Replied by russell on topic RS232 return values
<font size="2">Ok, I think I got it, how does this look? (obviously all it does is open then close the port, but it compiles with no errors)</font>
#include &lt;stdio.h&gt;   /* Standard input/output definitions */
#include &lt;string.h&gt;  /* String function definitions */
#include &lt;unistd.h&gt;  /* UNIX standard function definitions */
#include &lt;fcntl.h&gt;   /* File control definitions */
#include &lt;errno.h&gt;   /* Error number definitions */
#include &lt;termios.h&gt; /* POSIX terminal control definitions */
#include &lt;stdlib.h&gt;  /* Some random library we found in a book */
#include &lt;sys/ioctl.h&gt;  /*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, &amp;options);

                /*set to 9600 7bit even parity, no flow control*/
                cfsetispeed(&amp;options, B9600);
                cfsetospeed(&amp;options, B9600);

                options.c_cflag |= (CLOCAL | CREAD);
                options.c_cflag |= PARENB;
                options.c_cflag &amp;= ~PARODD;
                options.c_cflag &amp;= ~CSTOPB;
                options.c_cflag &amp;= ~CSIZE;
                options.c_cflag |= CS7;
                options.c_cflag &amp;= ~CRTSCTS;

        options.c_lflag &amp;= ~(ICANON | ECHO | ECHOE | ISIG);    /*non Canonical*/

                tcsetattr(fd, TCSANOW, &amp;options);
                ioctl(fd, TCFLSH, 2);
        }
}

Please Log in or Create an account to join the conversation.

  • russell
  • russell's Avatar
13 years 6 months ago #9776948 by russell
Replied by russell on topic RS232 return values
Quick hint to anyone having problems with this stuff, the roboteq wants carriage returs ("
"), 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
  • slauziere's Avatar Topic Author
13 years 5 months ago #9987833 by slauziere
Replied by slauziere on topic RS232 return values
glad you were able to get it working.

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 </a>

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
  • pablo's Avatar
13 years 2 months ago #12291789 by pablo
Replied by pablo on topic RS232 return values
Thanks for the open_port() code, serial i/o can be a pain.. This works great. After I got my port configured the link from TSA was very helpful:
<a target="_blank" href=" www.tsatechnologies.com/roboteq_api.pdf ">RoboteQ API</a>
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.

Moderators: tonysantoni
Time to create page: 0.146 seconds
Go to top