Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 01-06-2009, 10:56 AM   #1
LQ Newbie
Registered: Nov 2006
Posts: 7

Rep: Reputation: 0
serial port failure: Resource temporarily unavailable


I have a weird problem. I want to write data through a serial line (/dev/ttyS0). My program writes data , then sleep and repeat this process forever. Pretty simple!

Here is my program

//------------------------- TestPort0.cpp -------------------

#include <cstdio>
#include <fcntl.h>
#include <termios.h>
#include <cstring>
#include <string>
#include <errno.h>
#include <signal.h>

using namespace std;

int m_fdw;
char m_To[10] = {0x55, 0xAA, 10, 1, 0, 0, 0, 0, 0, 11};

void SetAttribute()
struct termios Attr_o;
speed_t orate = B115200;
if(tcgetattr(m_fdw, &Attr_o) == -1)
perror("SerialPortComm tcgetattr:");
// set baud rate
if(cfsetispeed(&Attr_o, orate) == -1)
perror("SerialPortComm tcgetattr:");
Attr_o.c_cflag = CLOCAL | CS8 ;
Attr_o.c_cflag &= ~CRTSCTS;
Attr_o.c_iflag = 0;
Attr_o.c_oflag = 0;
Attr_o.c_lflag = 0;
Attr_o.c_cc[VTIME] = 0;
Attr_o.c_cc[VMIN] = 1;

if(tcflush(m_fdw, TCIOFLUSH) == -1)
perror("SerialPortComm tcflush:");
if(tcsetattr(m_fdw, TCSANOW, &Attr_i) == -1)
perror("SerialPortComm tcsetattr:");

int main()
m_fdw = open("/dev/ttyS0", O_WRONLY| O_NOCTTY | O_NDELAY);
if(m_fdw == -1)

if(write(m_fdw, m_To, 10) == -1)
return 0;

//--------------------- END OF TestPort0.cpp ---------------

When I run it from a terminal, Everything looks fine, I do not see any problems. I can see the data on the line with an oscilloscope.

But if I start the program with a script then I see two behaviors:

1. Everything is fine.

2. write just dont work! no data could be seen on the line with the oscilloscope, even if write return 10 (he is telling me that it work but it dont). After 4-5 sec, write starts to return -1 and sets errno to Resource temporarily unavailable. Note that when the program behave like that, write will never work, it will always fail.

Here is my script

//-------------------- BEGIN OF StartPort ---------------------
# run the program
./TestPort0 &

//--------------------- END OF StartPort -----------------------

So I start my program by doing
sh StartPort0

My kernel is 2.6.20 with the real time patch from, distro is Fedora core 6.

any ideas???



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
fork: resource temporarily unavailable ??? str8edge Linux - General 3 06-21-2011 09:00 AM
vfork: resource temporarily unavailable verbose Linux - General 5 02-04-2007 04:17 AM
xcdroast - resource temporarily unavailable mwildam Linux - Newbie 4 09-24-2006 04:28 PM
Siocsifflags: Resource Temporarily Unavailable camapa Linux - Networking 0 09-24-2005 07:58 PM
SIOCSIFFLAGS: Resource temporarily unavailable bleef Linux - Networking 2 05-14-2001 10:54 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:21 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration