LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-31-2004, 08:17 AM   #1
Onyx^
Member
 
Registered: Aug 2003
Location: Cornwall, UK
Distribution: Debian / Red Hat 7.3 / Peewee / Feather
Posts: 56

Rep: Reputation: 15
Linux serial port programming clash


Hi there,

I have a Linux system that includes a touchscreen runs a program to monitor com2 for touchscreen comms.

I have also written a custom program that communicates over the serial ports. Both programs work independantly fine, but if I run my program it *breaks* the touchscreen. I assume this is because my signal handler on the comm ports in my custom program is grabbing the IO that is intented for the touchscreen...

Is there a way to block the signal handler from grabbing comms from a specific com port? (sa_mask? status in signal handler?)

Here is my current code where I install the signal handler & the signal handler itself.
Code:
struct sigaction saio;

void signal_handler_IO(int status)
{
    wait_flag = FALSE;   // for thread communication.
}

...

saio.sa_handler = signal_handler_IO;
//saio.sa_mask = 0;
saio.sa_flags = 0;
saio.sa_restorer = NULL;
sigaction(SIGIO,&saio,NULL);

Last edited by Onyx^; 08-31-2004 at 08:23 AM.
 
Old 08-31-2004, 08:38 AM   #2
Stor_G
Member
 
Registered: Aug 2004
Posts: 50

Rep: Reputation: 15
one small question: do the program you wrote and the touch screen work on the same serial port?
maybe if your program could listen on another serial port if you have one on your system.

if not, i don't see a way your program could wait for serial data when the screen is connected anyway.
if you could explain how you can use the screen and another program on the same serial line and get data for each of them maybe i'll be able to help you...
 
Old 08-31-2004, 08:41 AM   #3
Onyx^
Member
 
Registered: Aug 2003
Location: Cornwall, UK
Distribution: Debian / Red Hat 7.3 / Peewee / Feather
Posts: 56

Original Poster
Rep: Reputation: 15
Nope, my program communicates on com1, com3, and com4

The touchscreen communicates on com2...
 
Old 08-31-2004, 08:52 AM   #4
Stor_G
Member
 
Registered: Aug 2004
Posts: 50

Rep: Reputation: 15
ohh i understand
the signal tells you when there's incoming data on a serial line. but it doesn't specify which.

is this correct?
if it is, have you considered using a select call?
try to read it up in the man if you don't know it.

Code:
man select
or
man select_tut
basically it allows you to monitor several file descriptors so u can monitor specifically the file descriptors related to Com 1 3 and 4 and ignore Com 2.
 
Old 08-31-2004, 09:17 AM   #5
Onyx^
Member
 
Registered: Aug 2003
Location: Cornwall, UK
Distribution: Debian / Red Hat 7.3 / Peewee / Feather
Posts: 56

Original Poster
Rep: Reputation: 15
yes i am using select along with a fdset to just monitor com1, com3 and com4 within my program.

However even ignoring com2 within my program it is still interfering with the touchscreen drivers
 
Old 08-31-2004, 09:24 AM   #6
Stor_G
Member
 
Registered: Aug 2004
Posts: 50

Rep: Reputation: 15
Quote:
Code:
struct sigaction saio;

void signal_handler_IO(int status)
{
    wait_flag = FALSE;   // for thread communication.
}

...

saio.sa_handler = signal_handler_IO;
//saio.sa_mask = 0;
saio.sa_flags = 0;
saio.sa_restorer = NULL;
sigaction(SIGIO,&saio,NULL);
in what part of your program do you have this code above?
 
Old 08-31-2004, 09:56 AM   #7
Onyx^
Member
 
Registered: Aug 2003
Location: Cornwall, UK
Distribution: Debian / Red Hat 7.3 / Peewee / Feather
Posts: 56

Original Poster
Rep: Reputation: 15
the signal handler is installed once at the beginning of execution of my program.

The signal handler code itself sets a flag to false. In the main while loop of my program this flag is examined, and if it has been triggered it knows to go ahead process the information from the serial port (using a select call to find which com port the data has arrived on).

Hope this information is helpful...
 
Old 08-31-2004, 02:18 PM   #8
bruce ford
Member
 
Registered: Jul 2004
Location: Munich, Germany
Distribution: Sun Solaris 8, SuSE 9.0
Posts: 43

Rep: Reputation: 15
Hi,

I think the select() part of your program would be more interesting for investigations about this problem. Why do you use signal driven i/o at all?
I have a program that monitors 128 network connections AND 128 serial ports using select() in a single thread without using any signals.

so long...
bruce
 
Old 08-31-2004, 11:00 PM   #9
Stor_G
Member
 
Registered: Aug 2004
Posts: 50

Rep: Reputation: 15
Quote:
I think the select() part of your program would be more interesting for investigations about this problem. Why do you use signal driven i/o at all?
i tend to agree with this approach.
you can create a thread that blocks on select indefinately or until woken/interrupted without registering the IO signal.
However, before doing that, i recommend commenting out the part in your code that handles the signal and see if it has any affect on the touchscreen.
if it has, return the signal handler code, and comment out all other code that relates to serial access (select, read, write etc...) to make sure that it's the signal capturing that causes the problem.

that way you can be sure that you know what the problem is and you won't spend hours/days (depending on system complexity) making adjustments that eventually won't advance you at all towards a complete stable system.
 
Old 09-01-2004, 04:16 AM   #10
Onyx^
Member
 
Registered: Aug 2003
Location: Cornwall, UK
Distribution: Debian / Red Hat 7.3 / Peewee / Feather
Posts: 56

Original Poster
Rep: Reputation: 15
ah yes, thanks for the advice so far stor_g / bruce_ford

I will try removing the signal handler (although this will mean that the the serial ports are only initialised but never checked) to see if I still have a problem. Narrowing down what is causing it is a definate next step.

I am using the signal handler because of the unique structure of the program which has been ported from a rabbit microprocessor to linux.
 
Old 09-01-2004, 05:15 AM   #11
Stor_G
Member
 
Registered: Aug 2004
Posts: 50

Rep: Reputation: 15
keep us posted about how it goes
 
  


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
serial port programming: Java or C? ar1 Programming 5 05-19-2005 02:55 PM
serial port programming!!! novice_din Programming 4 02-03-2005 08:50 PM
Serial port communication programming SeanatIL Programming 3 07-17-2004 08:26 PM
Programming the Serial Port karans Linux - Networking 2 11-03-2003 01:54 AM
Modem programming and serial port Drickx Linux - Networking 2 04-24-2002 09:24 AM


All times are GMT -5. The time now is 06:58 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration