![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2007
Posts: 13
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#3 | |
|
Newbie
Join Date: Aug 2007
Posts: 13
Rep Power: 0
![]() |
writing application for 32 comport
Quote:
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 |
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5
![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |