Searching \ for '[OT]: C++/Serial port read/write??' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/io/serials.htm?key=serial
Search entire site for: 'C++/Serial port read/write??'.

Exact match. Not showing close matches.
PICList Thread
'[OT]: C++/Serial port read/write??'
2005\02\27@134702 by Ale[x] Garbino

picon face
I'm done with all the PIC side of code, which I tought would be the hard
part to learn. Until I tried reading the serial port!

I assumed a simple:
ofstream serial ("/dev/ttyS1", ios::out | ios::app);
if ( !serial.is_open() ) {
 cout << "Can't open serial port" << endl;
 return 0;
 }
serial << "Hello";

Would do the trick, but although echo & cat works fine from the command
line, the serial port doesn't react the same.

I'm trying to write a bit of code that reads a byte stream and through
appropriate bitwise manipulation, gets the relevant information I need. I
also wanted to write a simulator that writes properly-formatted bytes to the
other serial port, so with the use of a null-modem cable I could make sure
my program was working fine.

Does anyone have some simple way to read/write the serial port??

-Alex



More details:
I'm running 2.6.x, on a Gentoo linux box, with the latest glibc, and using
gcc to compile.

I've been looking all over the place, and nowhere does it seem anyone has a
decent way to interact with the serial port.
There is the
www.linuxdocs.org/HOWTOs/Serial-Programming-HOWTO/
which has about a page of complicated code to do something that should be
simple (after all, the setserial command/serial kernel driver already does
all the baud/parity stuff!!).

http://cpp.snippets.org/browser.php
Makes a separate class...


groups-beta.google.com/group/comp.lang.c++.moderated/browse_thread/thread/adb3fc9386015236/fbacf9c056983538?q=serial&_done=%2Fgroup%2Fcomp.lang.c%2B%2B.moderated%2Fsearch%3Fq%3Dserial%26start%3D10%26&_doneTitle=Back+to+Search&&d#fbacf9c056983538
reads to a stream buffer, but doesn't work when I run it...

There is also this:
http://www.erlenstar.demon.co.uk/unix/faq_4.html#SEC49

And I also found something with outb similar to :

#include <stdio.h>
#include <unistd.h> /* needed for ioperm() */
#include <sys/io.h> /* for outb() and inb(), from another site */
//   #include <asm/io.h> /* for outb() and inb() */

  int main(void)
  {
  if (iopl(3)) {
       printf("Sorry, you were not able to gain access to the ports\n");
       printf("You must be root to run this program\n");
       return 0;
       }
  outb(34324,0x03f8); /* Sends 0011 0010 to the Data Port */
  return 0;
  }


2005\02\27@140415 by Ake Hedman

flavicon
face
Hi,
I have a class I usually use for serial communication on Windows/Linux. I can send it of list to you if you want it.

Regards
/Ake


Ale[x] Garbino wrote:

{Quote hidden}

--  ---
Ake Hedman (YAP - Yet Another Programmer)
eurosource, Brattbergavägen 17, 820 50 LOS, Sweden
Phone: (46) 657 413430 Cellular: (46) 73 84 84 102
Company home: http://www.eurosource.se      Kryddor/Te/Kaffe: http://www.brattberg.com
Personal homepage: http://www.eurosource.se/akhe
Automated home: http://www.vscp.org

2005\02\27@150320 by Ale[x] Garbino

picon face
Please do!
Alex

From: Ake Hedman &lt;spam_OUTakheTakeThisOuTspameurosource.se&gt;
Reply-To: &quot;Microcontroller discussion list - Public.&quot; &lt;.....piclistKILLspamspam@spam@mit.edu&gt;
To: &quot;Microcontroller discussion list - Public.&quot; &lt;piclistspamKILLspammit.edu&gt;
Subject: Re: [OT]: C++/Serial port read/write??
Date: Sun, 27 Feb 2005 20:03:57 +0100

Hi,
I have a class I usually use for serial communication on Windows/Linux. I can send it of list to you if you want it.

Regards
/Ake


Ale[x] Garbino wrote:

&gt;I'm done with all the PIC side of code, which I tought would be the
&gt;hard part to learn. Until I tried reading the serial port!
&gt;
&gt;I assumed a simple:
&gt;ofstream serial (&quot;/dev/ttyS1&quot;, ios::out | ios::app);
&gt;if ( !serial.is_open() ) {
&gt;  cout &lt;&lt; &quot;Can't open serial port&quot; &lt;&lt; endl;
&gt;  return 0;
&gt;  }
&gt;serial &lt;&lt; &quot;Hello&quot;;
&gt;
&gt;Would do the trick, but although echo &amp; cat works fine from the
&gt;command line, the serial port doesn't react the same.
&gt;
&gt;I'm trying to write a bit of code that reads a byte stream and
&gt;through appropriate bitwise manipulation, gets the relevant
&gt;information I need. I also wanted to write a simulator that writes
&gt;properly-formatted bytes to the other serial port, so with the use
&gt;of a null-modem cable I could make sure my program was working fine.
&gt;
&gt;Does anyone have some simple way to read/write the serial port??
&gt;
&gt;-Alex
&gt;
&gt;
&gt;
&gt;More details:
&gt;I'm running 2.6.x, on a Gentoo linux box, with the latest glibc, and
&gt;using gcc to compile.
&gt;
&gt;I've been looking all over the place, and nowhere does it seem
&gt;anyone has a decent way to interact with the serial port.
&gt;There is the
&gt;www.linuxdocs.org/HOWTOs/Serial-Programming-HOWTO/
&gt;which has about a page of complicated code to do something that
&gt;should be simple (after all, the setserial command/serial kernel
&gt;driver already does all the baud/parity stuff!!).
&gt;
&gt;http://cpp.snippets.org/browser.php
&gt;Makes a separate class...
&gt;
&gt;
&gt;groups-beta.google.com/group/comp.lang.c++.moderated/browse_thread/thread/adb3fc9386015236/fbacf9c056983538?q=serial&amp;_done=%2Fgroup%2Fcomp.lang.c%2B%2B.moderated%2Fsearch%3Fq%3Dserial%26start%3D10%26&amp;_doneTitle=Back+to+Search&amp;&amp;d#fbacf9c056983538
&gt;
&gt;reads to a stream buffer, but doesn't work when I run it...
&gt;
&gt;There is also this:
&gt;www.erlenstar.demon.co.uk/unix/faq_4.html#SEC49
&gt;
&gt;And I also found something with outb similar to :
&gt;
&gt;#include &lt;stdio.h&gt;
&gt;#include &lt;unistd.h&gt; /* needed for ioperm() */
&gt;#include &lt;sys/io.h&gt; /* for outb() and inb(), from another site */
&gt;//   #include &lt;asm/io.h&gt; /* for outb() and inb() */
&gt;
&gt;   int main(void)
&gt;   {
&gt;   if (iopl(3)) {
&gt;        printf(&quot;Sorry, you were not able to gain access to the
&gt;ports\n&quot;);
&gt;        printf(&quot;You must be root to run this program\n&quot;);
&gt;        return 0;
&gt;        }
&gt;   outb(34324,0x03f8); /* Sends 0011 0010 to the Data Port */
&gt;   return 0;
&gt;   }
&gt;
&gt;


--
---
Ake Hedman (YAP - Yet Another Programmer)
eurosource, Brattbergavägen 17, 820 50 LOS, Sweden
Phone: (46) 657 413430 Cellular: (46) 73 84 84 102
Company home: http://www.eurosource.se      Kryddor/Te/Kaffe: http://www.brattberg.com
Personal homepage: http://www.eurosource.se/akhe
Automated home: http://www.vscp.org


'[OT]: C++/Serial port read/write??'
2005\03\01@034315 by Peter L. Peres
picon face


On Sun, 27 Feb 2005, Ale[x] Garbino wrote:

{Quote hidden}

use setserial to set the speed and set option low_latency for the used
serial port.

then use stty clocal cread cs8 raw crtscts on that port, then run your
program. C++ io also has buffering and such which you may want to turn
off.

Most of these settings can be set using ioctls on linux.

Peter

More... (looser matching)
- Last day of these posts
- In 2005 , 2006 only
- Today
- New search...