Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 10th, 2007, 9:11 AM   #1
amitpansuria
Newbie
 
Join Date: Aug 2007
Posts: 13
Rep Power: 0 amitpansuria is on a distinguished road
how i write application for 32 com ports simultaneously

Dear Sir,
i m going to use NP5610-16 moxa device for multiport serial communication.
i m using fedora-core 6 o.s.
after installation it will detect serial ports as /dev/ttyr0,/dev/ttyr1...ttyr32.
there are total 32 com ports.
now i want to write application which monitor all serial ports and received data from particular serial ports simultaneously
after that it send data on particular port.
its ok i understand this concept.
but i confuse that what programming approach i have to use to monitor multiport serial ports.
i have to fire 32 diff threads for each port or what
tell me how i write application such that it is easy to control all 32 com port
plz help me to sort out this issue
please also guide me that which is the best approach i have to use for this
Regards,
Amit
amitpansuria is offline   Reply With Quote
Old Aug 10th, 2007, 6:38 PM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5 grumpy is on a distinguished road
Generally, there are several options. One thread per port is not generally a good idea: 32 threads will slow down most processes on most operating systems due to context switching. The output is generally trivial, assuming a port opened for both reading and writing; it is the waiting for input that needs the thought, as that is responding to actions your software can't control.

If the total amount of data coming through the ports is not that high, the simple approach is to loop over poll each port until data is received - check for data, if it is there read it and dispatch it to code that handles it, etc. Generally a good idea to introduce small delays into the polling process, otherwise you find your application forever bashing the processor and starving CPU resources from other applications.

If the total amount of data is higher, it is better to wait for input. Quite a few operating systems have some form of API that allows waiting until there is input on one of a set of input devices. For example, if you are programming using sockets, there is the select() call on most forms of unix -- but, to use that, the programming interface for your devices needs to be consistent with the socket API. In general the method you use to do this is OS dependent -- you'll have to read your OS and device/driver documentation for the actual functions to use.
grumpy is offline   Reply With Quote
Old Aug 11th, 2007, 1:36 AM   #3
amitpansuria
Newbie
 
Join Date: Aug 2007
Posts: 13
Rep Power: 0 amitpansuria is on a distinguished road
writing application for 32 comport

Quote:
Originally Posted by grumpy View Post
Generally, there are several options. One thread per port is not generally a good idea: 32 threads will slow down most processes on most operating systems due to context switching. The output is generally trivial, assuming a port opened for both reading and writing; it is the waiting for input that needs the thought, as that is responding to actions your software can't control.

If the total amount of data coming through the ports is not that high, the simple approach is to loop over poll each port until data is received - check for data, if it is there read it and dispatch it to code that handles it, etc. Generally a good idea to introduce small delays into the polling process, otherwise you find your application forever bashing the processor and starving CPU resources from other applications.

If the total amount of data is higher, it is better to wait for input. Quite a few operating systems have some form of API that allows waiting until there is input on one of a set of input devices. For example, if you are programming using sockets, there is the select() call on most forms of unix -- but, to use that, the programming interface for your devices needs to be consistent with the socket API. In general the method you use to do this is OS dependent -- you'll have to read your OS and device/driver documentation for the actual functions to use.
helo thx for replying me.
anyway,
i m using moxa serial device and moxa driver of this device support linux and unix standard API for serial communication.
i think i can also use select() function in case of serial communication but how to write select() function for 32 com ports that i dont know
plz help me to make my design correct.
Regards,
Amit
amitpansuria is offline   Reply With Quote
Old Aug 11th, 2007, 9:11 AM   #4
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5 grumpy is on a distinguished road
If you can use select() for your devices, it's easy.

Most select() based applications do something like this;
1) Populate a fd_set structure with file descriptors that data will be read from.
2) Populate a fd_set structure with file descriptors data will be written to.
3) Do the following in a loop until required to terminate;
a) Call select() with those structures as arguments.
b) When select() returns, and it returned because of one of the set of file descriptors, read/write data as required (e.g. read in data request from com port with data ready).

I'll leave code to do the above as an exercise.
grumpy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to write a web application in c# dark_omen C# 3 Apr 25th, 2005 7:13 AM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC