-
December 8th, 2011, 06:57 AM
#1
Multithreading for multiple serial ports
I have a PC with 16 RS485 serial ports attached (using 2 MOXA PCI to serial port cards).
I need to download the contents of a file (with binary data) to the devices attached to all 16 serial ports simultaneously.
I've created and launched 16 BackgroundWorkers to manage the download for each port. Each BackgroundWorker runs a method that opens a specified COM port. I use a timer with each serial port to manage reception timeout handling. I use the StopWatch class to generate dealys where required. Each BackgroundWorker also opens a FileStream with reach only access and fileshare settings on the one file to be used for downloading to all 16 ports.
There are some bizarre things happening here! The timer used with the SerialPorts doesn't appear to operate, received data is not generating received data events and there are spontaneous closures of some of the Filestreams!
Is my approach to managing multiple downloads a valid one to use? Can anyone suggest either why I'm seeing the problems described and how to solve them, or a better method to performing the simultaneous download to multiple ports?
-
December 8th, 2011, 12:34 PM
#2
Re: Multithreading for multiple serial ports
Problem solved.
The System.Timers.Timer used with the serial port was declared as a static. Once removed, the issue went away.
I found it was also necessary to call System.Threading.ThreadPool.SetMinThreads to set a suitable number of idle threads to be available to perform the downloads efficiently.
-
December 9th, 2011, 12:46 AM
#3
Re: Multithreading for multiple serial ports
Glad it worked out. I don't know that I've heard of someone using so many serial ports. I am curious: how do you address them all? Do you really just get COM1 through COM16? Or is it something else?
Good luck in the rest of your project; sounds neat.
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
December 9th, 2011, 03:30 AM
#4
Re: Multithreading for multiple serial ports
I have had to use as many as 8 before each had the next sequencial com number, Seems like they started at 5 on the digi board we used but it has been a long time so memory is foggy now. In my case the system was monitoring 8 phone lines for incoming calls to receive sales orders from people in the field.
Always use [code][/code] tags when posting code.
-
December 9th, 2011, 09:36 AM
#5
Re: Multithreading for multiple serial ports
oh RS485, familiar name... are you using modBus protocol?
-
May 8th, 2012, 04:34 PM
#6
Re: Multithreading for multiple serial ports
Hi oz_peter,
Could you plz share your code as am looking for similar kinda apps multiport serial communication.Thx Sam
-
July 2nd, 2014, 08:41 AM
#7
Re: Multithreading for multiple serial ports
Hi oz_peter, can you please share your solution, I'm try to handle 8 comport receives.
Thanks in advance
-
July 4th, 2014, 11:59 PM
#8
Re: Multithreading for multiple serial ports
Don't revive code from many years ago, as nobody cares. Start a new thread
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|