Threading with Serial Port read

Jun 25, 2010 at 6:58am
Hi,
I am new to this forum.
I am using UBUNTU linux 9.10 where i am connecting two devices simultaneously through serial ports.

Ser1: ttys0: Dev1
Ser2: ttys1: Dev2

My application will send the signal to the respective ports and wait for the signals to arrive from the ports.

If i receive the signal from dev1 then i will wait for dev2 if both come then continue program for other operation.

My questions are:
1. Can we use threading to connect both the ports continuously at the same time?
2. If yes, then how?

I hope to get good help.
- Prasad
Jun 25, 2010 at 1:24pm
What do you mean by "connect both ports"?
Jun 27, 2010 at 7:20am
I think i see what you mean. You could open the ports with non_block and then check them in a while loop for new data from the ports.
Jun 30, 2010 at 6:50am
Hello,
Sorry for the late reply. I want to establish continuous contact with all the attached devices. RedX is right that i should check it in while loop. I have already established connections but individually to the boards and checked the data communication using while loop.

The application brief is:

1.Serial port 1 is attached with one circuit PIC controller board.
2.Serial port 2 is attached with another circuit of 8051 controller board.
3.WIFI adapter is connected to the USB for wireless transmissions.

Now, i want to continuous monitor signals from all above boards/ wifi (in loop) and also send them instructions.
this should happen simultaneously for all of them.

So, i was thinking to implement respective threads so as one port should not stuck because of other port operations.

1. Can i implement mentioned scenario through Threads?
2. Yes, then how?






Jun 30, 2010 at 1:45pm
You could use threads. How is more time then i have at hand.
Take a look at pthreads. It a threading library. From the examples you should have an idea of what you have to do. You must also make sure that the write operations that you will be using are thread-safe or else you won't have any advantage on multi-threading.

I'd preferr, as i mentioned, open the sockets in NON BLOCKING mode and use that in a loop.
Jul 2, 2010 at 12:25pm
Thanks RedX. I will try your suggestions and soon get back to you here.
Only i am not clear on "Thread Safe" Could you please elaborate?
Last edited on Jul 2, 2010 at 12:27pm
Topic archived. No new replies allowed.