December 8th, 2011, 06:57 AM
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?
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!