Serial Port Buffering and non canonical mode

Getting your soundcard to work, using Debian on non-i386 hardware, etc

Serial Port Buffering and non canonical mode

Postby fsonnichsen » 2017-07-07 10:51

I have been struggling with this for a few days and would appreciate some advice. I am running a PERL serial program on a Debian system. Connected to an USB emulated serial port is a steaming hardware device that sends a ~50 byte record ever few seconds. An stty shows -icanon so I am assuming non blocking mode here.

I read this port/device periodically, about every 30 seconds.My read is done in PERL with a byte by byte loop. It "spins" until the accumulated number of bytes is retreived. When i read, I need the MOST RECENT record. However I keep getting "stale" data, that is, an earlier record. I think my understanding of the serial port is the issue here so I have some questions:
1) Where would the serial port buffer be maintained--in Debian or in the PERL control sections
2) How does the read of the port work. I already assume based upon what I am seeing is that it if FIFO, e.g. the oldest record is returned first. I am guessing some type of ring buffer is established either in Debian or PERL.

Is there some way to insure that I get the most recent bytes transmitted. I was thinking of setting the buffer size to some low value to insure that is is flushed when I do the read but I cannot see an stty or ioctl mandate to do this.

Posts: 8
Joined: 2015-11-30 18:44

Re: Serial Port Buffering and non canonical mode

Postby peter_irich » 2017-07-07 19:37

The earliest data transmitted to serial port will be read the first and the last data will be read last.
In one ed of the pipe data are arrives and from other its gets out.
Read in while() by portion what you needed until the date will be finished and leave the last.

Posts: 1169
Joined: 2009-09-10 20:15
Location: Saint-Petersburg, Russian Federation

Return to Hardware

Who is online

Users browsing this forum: No registered users and 3 guests