Please do! Alex From: Ake Hedman <akhe@eurosource.se> Reply-To: "Microcontroller discussion list - Public."=20 <piclist@mit.edu> To: "Microcontroller discussion list - Public."=20 <piclist@mit.edu> 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= =20 can send it of list to you if you want it. Regards /Ake Ale[x] Garbino wrote: >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 >http://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... > > >http://groups-beta.google.com/group/comp.lang.c++.moderated/browse_th= read/thread/adb3fc9386015236/fbacf9c056983538?q=3Dserial&_done=3D%2Fg= roup%2Fcomp.lang.c%2B%2B.moderated%2Fsearch%3Fq%3Dserial%26start%3D10%26&= amp;_doneTitle=3DBack+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; > } > > -- --- Ake Hedman (YAP - Yet Another Programmer) eurosource, Brattbergav=E4gen 17, 820 50 LOS, Sweden Phone: (46) 657 413430 Cellular: (46) 73 84 84 102 Company home: http://www.eurosource.se Kryddor/Te/Kaffe:=20 http://www.brattberg.com Personal homepage: http://www.eurosource.se/akhe Automated home: http://www.vscp.org -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist