Programming :: Read X Bytes From Serial Port?

May 5, 2010

I am trying to write some code that interfaces with an AVR over a serial port. Basically I send a command then read the output which is 6 bytes. I need to receive all 6 bytes before the program continues. Is there a way to do this? If I use read() it returns -1 unless I add a delay before reading the port. Is there a way to get it to read the 6 bytes as soon as they arrive?In python you simply say how many bytes you want and the max time you are willing to wait which seems a whole lot easier than read

View 1 Replies


Programming :: Read Datas After Write On Serial Port?

Mar 8, 2011

I'm currently developping a C program to drive a Telit GM862-GPS module using the serial port of an embedded board (SBC9261).The communication with the module is based on AT commands : I just send my command to the module, through the RS232 line, and the module answers immediately.Here's an example with a basic command returning the GPS's acquired position, sent with Minicom :

$GPSACP: 104323.000,4x45.6171N,00x38.6219E,0.8,446.5,3,272.14,0.21,0.11,080311,09


View 4 Replies View Related

Programming :: Read Some Data From Controller Using Serial Port?

Aug 25, 2010

i want to try with a small application in linu in that i want to read some data from controller using serial port and i wanna transfor that data to another meachin in the network for this i want serial port interfacing programming as well as socket programming.

View 1 Replies View Related

Programming :: Serial Port Data Read Time Interval?

Oct 30, 2010

I am writing a C program which reads data over serial port. While reading data, if I send my data(which is a 13 byte structure) periodic with a period of 1 second for 10 times I read it without problem and I read the data 10 times as I sent and as I expectBut if I send data continuousuly(without any time interval between each sending) 10 times I can only read 1 of them(I can only read it once).

View 11 Replies View Related

Programming :: Debian Serial Port Read() Return Wrong Data?

Jul 6, 2010

I am implementing a simple serial protocol where my ARM9 board, running Linux is communicating to a slave peripheral board. The Master sends a 12 byte data stream and the peripheral board returns status in a 23 byte response. The serial port is opened in raw mode. It works perfectly on 44 reads; however, on the 45 read the data returned from the read() is incorrect. I've framed what's being sent on an oscope and it is correct.The coincidence is that 23 x 44 = 1012. It's as though the receive buffer is 1K and when I go past the boundary I get bad data. The read following the bad one is good again.I've tried flushing the buffer before reading but get the same result.Here's the port initialization code:

int initport(int fd)


View 4 Replies View Related

Programming :: Get Data From Serial Port Function Read() Blocks When Data Not Available?

Jun 11, 2009

I am using read() in c++ to get data from a serial port. However, if no data is available on the serial port the function blocks until dta arrives.Example code:

char m_readBuffer[255] = {0};
char* p_curChar = m_readBuffer;


View 1 Replies View Related

Ubuntu :: Unable To Read The Serial Port

May 23, 2010

I am using a F232 USB to serial adapter for connecting my wireless modem to my laptop and I wrote a simple C code for reading data received by the modem transmitted by another modem installed on my target device.The problem is my code is simply giving 0.00000 (float data) output .When I use the same code with my desktop its running fine and I am getting relevant data.What may be the problem? I even changed the permission for my /dev/ttyUSB0 I am using Ubuntu 10.04 on both my laptop and desktop

below is my code


#include <stdlib.h>
#include <math.h>
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */


View 5 Replies View Related

Ubuntu :: Serial Port Read, Write After DTR Toggle In C++?

Mar 31, 2011

I need to read and write to a serial device. When I connect via gtkterm, I need to toggle DTR before I can communicate with the device . My problem is that I cannot emulate this in C++.

I want to write some code that can setup a comport, toggle the DTR, then read and write strings to the port. However all my attempts have been fruitless. My serial settings are B9600, No parity, no hardware control, 8 bt characters and 1 stop bit:

#include <iostream>
#include <SerialStream.h>
#include <sys/ioctl.h>
#include <fcntl.h>
using namespace LibSerial;


View 1 Replies View Related

General :: Serial Port Configuration - Write Or Read

Dec 1, 2010

I have a minilinux that I being working on, the problem now is that the serial ports doesn't seem to work (I have 4 serial ports).They don't write or read.

I run the command setserial g /dev/ttySx and it says that his IRQ are 3 or 4 (3 for ttyS0 and ttyS2 , 4 for ttyS1 and ttyS4)�but when I run the command: dmesg | grep ttyS the IRQ�s are 0 for ALL my serial ports� could be this the reason why my serial ports aren�t working right??? And if it is how can I solve the problem??

View 2 Replies View Related

General :: Serial Port Programming Help

Apr 15, 2010

can we use inb() and outb() functions for serial port programming ??

View 5 Replies View Related

Programming :: C - Serial Port Won't Open?

Sep 1, 2010

I'm using C serial in a program to open and use a serial port but the port won't open for one reason or another. The program successfully runs on a different computer and when using RealTerm: Serial Capture Program, I can connect through the serial port with the same settings as I'm attempting through my c code. Anyone have any idea why it might be failing? I know this is still pretty vague, so let me know if there's other things I can tell you that might help to finding a solution

View 3 Replies View Related

Programming :: Intercept Data On Serial Port?

Dec 21, 2010

I dont know if this is the right forum, But I try to find a solution, I want to intercept data from/to serial port without disrupting the software that manages the serial port, (I would like to save the data to a file or sent into a socket) I searched somes modules and programs (linspy, ttysniff, interceptty, maxty ...), A bit complicated (There are some diff. between kernel 2.4 and 2.6), So I'd like to change the serial port driver to intercept the "read" and "write " and do what I want with the data, I'd like to know what do you think about

View 3 Replies View Related

Programming :: Serial Port Communications - CPU Bandwidth

Sep 15, 2010

I have an application written in C (by somebody else) monitoring a device connected to a serial port. I'm using an old laptop w. tinycore linux for an os. The app works well enough, and the communication speed is relatively slow, 9600bps, unidirectional, comes in packets of 18 bytes. The app is just picking apart the packets and displaying the contents on a formatted screen (ncurses), updating about once every 1/2 second. The trouble is, the app is polling the serial port and using *all* of the cpu bandwidth. The cpu fan runs full bore all the time.

Other activities are sluggish when the monitoring program is running. I'd like to modify the app to be a little more intelligent, use a receive buffer and interrupts to trigger processing each packet and, most importantly, not poll in a tight loop waiting for data. I'm not sure where to start, but I'm convinced this isn't that complicated of a change. Is there a good resource that would explain the basics of reading data from serial port software buffers, triggering on interrupts and suspending or sleeping when no interrupt is pending?

View 5 Replies View Related

Programming :: Send Data Through Serial Port Using C?

Oct 20, 2009

I am not a profession programmer. I have to write a C code which send some command to attach display using C program. Can any one please help me in this regard.

View 3 Replies View Related

Programming :: Multiple Protocols On Serial Port

Mar 24, 2011

I'm attempting to write an application that needs to read and reply to messages that will appear via 3 different methods:

1) Standard serial communications
2) TCPIP over serial via PPP
3) TCPIP over Ethernet

The problem is that I'd like for the application to be able to receive packets from any and all of the three interfaces simultaneously. I shouldnt have much trouble with performing #1 and #3 at the same time, as I think I can just get a file descriptor from termios and another for a socket and then use select to wait for data. But #2 is problematic.

First I dont know how to set up a socket that uses PPP as the data link layer. And secondly, (here's the big one) this PPP data is coming over the same port that the serial data is. There's no chance for data collision, and I am guaranteed not to receive another packet until I respond to the last one (in the same protocol at that) but incoming packets may or may not be PPP/TCP/IP framed.

My app will act like the PPP client, so I was just thinking "somehow" that I could run a standard termios application on the serial port which would begin to interpret the packet. If its PPP framed then it would have to get passed to a PPP client, which would be listening to my application rather than a physical port. And I have no idea how to do that. Is there an API available that will help me with the PPP packets?

How hard would it be to write a device driver that simulates a serial port. The device can listen on a real serial port, interpret its contents to an extent, and then distribute the incoming data to multiple "virtual" serial ports, which the main application can then listen to for incoming traffic.

View 2 Replies View Related

Programming :: Opening A Serial Port From Interrupt?

Aug 17, 2010

I'm trying to open ttySx from an interrupt.the kernel crashes. is it possible to open/write to serial port from interrupts ? I think it crushes because when I try to open the device there is a mutex lock which cause the kernel to crash , am I right

View 2 Replies View Related

Programming :: PHP Serial Port No Longer Work

Aug 24, 2010

I had a web server running from a Windows 7 computer and recently moved everything to an Ubuntu server. All is set up and running smoothly. I do have one page that actually interfaces with the serial port. The only thing I do with it is to set the DTR pin to "true" which applies +12v to the pin. This activates a relay. It is very basic and simple. After moving everything to Linux, this page will no longer work. I knew this would happen. I know the page had code in it to call out "Com1" which would change to "ttyS0". It also had "set_serDTR(True);" in the code. I can't figure out how to get PHP to control the DTR pin on a Linux serial port.

View 10 Replies View Related

Programming :: Writing To Serial Port From Kernel?

Aug 16, 2010

I want to write data to serial port ( ttyS ) from inside the kernel.

View 5 Replies View Related

Programming :: Rs232 Serial Port Programming?

Jun 1, 2010

I have been working on writing a small rs232 driver like minicom for months. I am almost there, I have the interrupt service routine running, I can read() ok. However when I write(), it returns the number of characters written, 1, but nothing is actually written out the port. I researched termios, and they say that serial port programming is really messy in linux/unix.

I am probably not setting up the port parameters correctly, or my write() function is not doing what it is supposed to. As I said, write() is returning successful. Other comm programs run ok (picocom & gtkterm) on my hardware. I am running knoppix/debian on an ancient computer. I saw other guys using slackware.

View 14 Replies View Related

Programming :: Serial Port Programming String?

Nov 24, 2010

I have a serial port program which is reading a string .if(read(readfd,sResult,1)>0)where sResult is unsigned char sResult[10];if sResult is array of 10 then iam getting string perfectly but if iam making sResult only as unsigned char I am getting NULL value CODE BELOW

unsigned char sResult;
readfd = open("/dev/ttyUSB0", O_RDONLY);
if (readfd == -1)
perror("READ: open_port: Unable to open /dev/ttyUSB0-


View 2 Replies View Related

Networking :: Serial Port : Read Data, Not Reading Complete Data?

Mar 5, 2010

I have an application where I am sending data via serial port from PC1 (Java App) and reading that data in PC2 (C++ App). The problem that I am facing is that my PC2 (C++ App) is not able to read complete data sent by PC1 i.e. from my PC1 I am sending 190 bytes but PC2 is able to read close to 140 bytes though I am trying to read in a loop.Below is code snippet of my C++ AppOpen the connection to serial port

serialfd = open( serialPortName.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
if (serialfd == -1)


View 5 Replies View Related

Debian Programming :: Serial Port Signal Handler

Jan 14, 2015

Basically I'm intending to write serial RX signal handler.Application receives defined packages of data over serial which contains header and payload. Handler should analyse incoming stream and upon detection of header (header is 6B in length) switches to receive payload of length defined in header, then after receiving full message packs it and sends to application for handling.Problem I'm facing is that at random moments in signal I receive errors that "Resource temporarily unavailable" while reading from ttyOx device and I see that sometimes I miss incoming data.Also is it possible that if while I'm handling signal one more signal arrives and it is started to be handled parallel? If it is, what are the ways to prevent it? So I would be sure that no more signals will fire on same peripheral until I will finish handling what I have on my hands now.

Serial open and init:
Code: Select allint open_port(int port_nr) {
    int fd; /* File descriptor for the port */
    switch (port_nr) {
    case 1:
        fd = open("/dev/ttyO1", O_RDWR | O_NOCTTY | O_NDELAY);

View 5 Replies View Related

Programming :: C++ - LibSerial With Socat Virtual Serial Port?

Oct 17, 2010

I'm trying to use a C++ program to communicate through a serial port on Ubuntu 10.04. I've installed LibSerial and for now I'm using virtual serial ports using socat. I'm getting an error on compiling (found below). But step by step, first I start the virtual serial ports:

(MYNAME@MYCOMPUTER):~$ socat -d -d PTY: PTY:
2010/10/17 22:04:18 socat[18575] N PTY is /dev/pts/2


View 4 Replies View Related

Programming :: Displaying I/O Possible When Reading Data From The Serial Port?

Aug 31, 2009

I have got a problem while reading from the serial port. I'm working on iMX-31 board and Eclipse IDE. Whenever I'm trying to read any data through the serial port, it's displaying I/O Possible and the application is being terminated. After reading I'm trying to write this data on a file. Here are the excerpts from the code:

# int main()
if (openport()<0)


View 7 Replies View Related

Programming :: Getting Information From Serial Port On Server Unit

Jul 19, 2011

I'm working on program that is going through setting different baud rates onto a config file. After I set a new value i want to check if it's the correct one by reading from the serial port on the server unit. I know what to expect if it's the correct baud rate so that's no problem, but searching through the internett i've yet to find a compact solution to my problem.

View 1 Replies View Related

Programming :: Inconsistency In Transferring Commands Over Serial Port?

Jun 10, 2009

I have been reading data(non-canonical input) off a serial port in a loop. The device I am connected to sends the data in a bursty manner and I have to read using the loop. The device sends some data when initially powered on which I am supposed to read. I can then send "commands" to the device over the serial port. The "command" is supposed to be "debug d 35 5 0"After I send the command there is some data that is sent back by the device to show that the command was successful. This command should elicit the right response from the device but it responds correctly some times while other times it does not. (when I try to write the consecutive commands) If I send two consecutive commands after reading the initial data and the command feedback I face some problems.

View 10 Replies View Related

Programming :: Porting Serial Port Program From Windows?

Jan 8, 2009

I bought a set of 3 laser sensors and it came with a software and its C++ source code for windows to receive the lasers info through the serial port. Since the entire project is running on Linux, I need to port the windows code to Linux. At the present moment, I already can receive the data from each of the 3 sensors, but the info is coming concatenated! Tracking down the original windows code, I found that it is probably happening cause I didn't ported these lines to my Linux version:


CommTimeouts.ReadIntervalTimeout = 2;


I've searched already about how to specify the serial port timeouts on Linux, but didn't find a solution. how to port these lines to Linux or maybe where to find more info about how to set serial port timeouts on Linux?

View 4 Replies View Related

Programming :: RTS Toggling In Serial Port From Kernel Space?

Jan 29, 2010

Driven by my needs , i need to toggle only the flow control (RTS, CTS) bits and have nothing to do with the rest of the functionality (e.g. normaltx , rx operation). I am presuming that there exists a line discipline from user space for toggling RTS as ioctl (*file, cmd, *unsigned long ) can be used easily to toggle RTS. However, the use of IOCTL in kernel space for the same purpose brings about no change on RTS (oscilloscope shows no change). google led me to this [URL] and according to that i should make changes directly in the driver.


int x=0;
int actual_module()
{ int k;
mm_segment_t oldfs;


View 3 Replies View Related

Programming :: Configure Serial Port RS-232 To Use Flow Control?

Aug 2, 2010

how to configure serial port RS-232 to use flow control? The reason is without flow control is is not working properly(dala loss etc.) Im trying to run it as it is just with setting the flow control flag and Im sending my data via loop-back on the rs-232 to GTK TERM on the same computer... but when I enable IXON/IXOFF in GTK TERM, my sending program cant even open the port...

My current settings is:

struct termios termios_p;
tcgetattr(sc.fd, &termios_p);
termios_p.c_cflag = B9600;


View 2 Replies View Related

Programming :: Serial Port Becomes Unreachable After Being Opened And Closed Once?

Sep 22, 2009

I am writing a program to read and write to devices over my serial port. My program will need to connect to up to four other machines at once. I can connect to machines successfully, it works well. However, after I connect and disconnect once, attempting to connect again will cause the FIRST serial connection will fail and all the ones after it will pass.


That works as long as it is executed only once in the program. The second time it is executed, fd[0] will die and fd[1-3] will work normally.I can't figure out why this happens, but I found a workaround by connecting to "/dev/null" before any real serial ports.What should I do?

View 10 Replies View Related

Copyrights 2005-15, All rights reserved