![]() |
|
#1
|
|||
|
|||
Serial Port CommunicationHi,
I'm currently attempting to access a pheripheral via a serial port. My goal is to be able to manage the data coming in but I have hit a road bump. I am working on a Linux OS and am obviously writing a C program to access the data on the serial port. The problem I am having is as follows. The device sends streams of data with a starting STX char, followed by a header character(F##) and ends the stream with an ending char ETX. The data is sent at a rate of 38400 with 8N1 (one stop bit). For example the device might send: FF01 a b c d F00 Hello Andrew my name is John. What is your name1? F00 Hello Andrew my name is John. What is your name2? F00 Hello Andrew my name is John. What is your name3? F00 Hello Andrew my name is John. What is your name4? F00 Hello Andrew my name is John. What is your name5? F00 Hello Andrew my name is John. What is your name6? F00 Hello Andrew my name is John. What is your name7? F01 a b c d F00 Hello Andrew my name is John. What is your name8? F01 a b c d F00 Hello Andrew my name is John. What is your name9? F01 a b c d F00 Hello Andrew my name is John. What is your name10? F01 a b c d F00 Hello Andrew my name is John. What is your name11? F01 a b c d F00 Hello Andrew my name is John. What is your name12? F01 a b c d F00 Hello Andrew my name is John. What is your name13? My code will attempt to access only the data with the F00 header, unfortuneatly this is all it saves: Hello Andrew my name is John. What is your name2? Hello Andrew my name is John. What is your name4? Hello Andrew my name is John. What is your name5? Hello Andrew my name is John. What is your name6? Hello Andrew my name is John. What is your name7? 0 Hello Andrew my name is John. What is your name8? 1 a b c d Hello Andrew my name is John. What is your name9? Hello Andrew my name is John. What is your name10? Hello Andrew my name is John. What is your name11? Hello Andrew my name is John. What is your name12? Missing a line at the start and end THe data retrieved will vary each time the program is run. It stores most streams correctly but on occasion the incorrect data is stored. I'm am configure my serial port as shown below: CPP / C++ / C Code:
Once stored into a buffer the stream is read directly to the storage file. The reason i'm storing the stream into a buffer and not reading directly to a file is I need to extract numbers from the stream to do some calculations. I realise this is a very broad question but if anyone could lend me any ideas to why i occasionaly miss a STX character that would be great? Cheers Andrew Charles Last edited by LuciWiz : 04-Aug-2006 at 10:49.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
Recent GIDBlog
Toyota - 2008 November Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to read from serial port in C | eng_girl | C Programming Language | 3 | 25-Feb-2008 00:51 |
| Serial port problem | chirayu | MS Visual C++ / MFC Forum | 0 | 07-Jul-2005 04:52 |
| Problem to read on a serial port | collinm | C Programming Language | 2 | 30-Mar-2005 02:42 |
| Problem with string and serial port | collinm | C Programming Language | 13 | 25-Mar-2005 08:39 |
| Serial Port communication in C or C++ | dmkst56 | C++ Forum | 0 | 23-Mar-2005 21:18 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The