LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-11-2006, 01:12 PM   #1
riffy
LQ Newbie
 
Registered: Jul 2006
Posts: 2

Rep: Reputation: 0
Question RS232 serial port errors when performing mutliple writes


I am sending data through a serial port and am having a couple of problems. I have read the serial and serial programming HOWTOs.

My application basically sends data in Buffer (byte*) using the following code:

Code:
BytesLeft = BufLen;
do
{		
    TxCount = write(handle, Buffer, BytesLeft);
    if(TxCount >= 0)
    {
        BytesLeft -= TxCount;
    }
    else
    {
        printf("TXStr error: %d\r\n", TxCount);
    }
}while (BytesLeft > 0);
I use the while loop to ensure that all characters are sent; if write() returns less than BufLen, it sends the rest. This may be unnecessary.

This code works, but I'm having a problem if I call my send function too frequently. If I call the function twice in succession, write returns -1. Adding a sleep(1) before the while prevents the error, but I'd appreciate a more viable fix.

I have noticed from serial libraries on places such as Sourceforge.net that the while loop is not used, so my first question is "is the while loop necessary". if not, is there any need to monitor the return value from write() other than to catch the error condition?

My second question is regarding the sleep I need to add. It seems that there is some buffer still being written to after the write() has returned, and if I try to write again too soon, I get an error. is there anything I can check to see whether the port is ready to be written to?

Many thanks,
Riffy
 
  


Reply


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
console login through RS232/serial port ? Yalla-One Linux - Software 3 02-24-2005 05:12 PM
USB - Serial RS232 Adapter blox Linux - Hardware 3 01-28-2005 11:58 AM
Serial RS232 problem Onyx^ Linux - Hardware 6 09-10-2004 12:35 AM
RS232 serial port programing blackzone Programming 2 08-11-2004 01:54 AM
serial port: RS232 RS574? blackzone Linux - Hardware 1 08-10-2004 05:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:37 PM.

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