0

I am using Moxa Nport's. They create around 200 virtual serial (COM) ports and are connected via Ethernet to my computer.

I am building an application which communicates with devices using the SerialPort class.

My question: Is there a maximum number of threads that I can run in parallel to open the ports? And of course to communicate in parallel via the ports? What do I have to take into account (RAM, Traffic, ect) so that I can repeat this process safely without having my computer hang himself.

I found this answer but it is only helpful in respect to computational operations concerning the core. But how does it behave with Virtual Serial-Ports?

Please share your knowledge and wisdom with me...

Community
  • 1
  • 1
Mong Zhu
  • 23,309
  • 10
  • 44
  • 76

1 Answers1

-1

SerialPort can only be opened once per port. So, in this case, all threads should share the same SerialPort object (static, maybe). If you have multiple ports, each thread can create its own SerialPort on different port. The maximum number of threads depends on the resources needed by each thread. 200 thread for your 200 ports is very reasonable in general. After all, I/O threads are in waiting (or blocked) state most of the time. If you want to open all the 200 ports at once, I think it would be better to make it in batches: start 20 threads in parallel with a timeout of 500 ms, then another 20, ... and so on. Creating 200 threads that communicate with the same driver at once may cause problems, IMHO

AhmadWabbi
  • 2,253
  • 1
  • 20
  • 35
  • And when there are 200 ports, like the question said? – Sami Kuhmonen Jun 21 '16 at 13:37
  • yeah that's also what I thought, but my computer dies 3 out of 15 attempts to open them all at once. Such performance is unfortunately unacceptable – Mong Zhu Jun 21 '16 at 13:43
  • @MongZhu What do you mean by "die"? What are the specifications of your computer (RAM, CPU, ..)? What is the error message in these 3 times? – AhmadWabbi Jun 21 '16 at 13:45
  • @AhmadWabbi my application stops opening at a certain Point/port. (Times out eventually) when I restart it then it might work or might stop again at a different port. Processor: i5 2x3.2Ghz, 4Gig RAM, 32-bit Win7 – Mong Zhu Jun 21 '16 at 14:00
  • @MongZhu Why 32 bits windows on i5? Anyway, I suggest doing it in batches like suggested in my answer. When a thread times out, put it in a special array, to be reconsidered at the end of the threads creation. This way your program should not hang. Also, print debug messages on the console about the status of each thread (port opened, timed out, ...) – AhmadWabbi Jun 21 '16 at 14:36
  • @AhmadWabbi thanks for the advice. I already tried everything you have suggested. I would like to know the maximum number of those batches. And on what it depends when using MOXA Nports and virtual COM ports. – Mong Zhu Jun 21 '16 at 14:57
  • @MongZhu Sorry I don't know about MOXA Nports specifically, but I would try different configurations andkeep the best. For example, start by 40 batches of 5 threads, then 20 batches of 10 threads, .... Good luck. – AhmadWabbi Jun 21 '16 at 15:15
  • 1
    Have you tried asking Moxa support for help on this? They are in the best position to know. Seems to me though like you are getting the answer - your PC isn't capable of supporting that many NPorts. Certainly sounds like you need to move to 64-bit OS and 8G or more RAM. Or you may have more joy on Linux. – DisappointedByUnaccountableMod Jun 21 '16 at 16:32
  • I agree with @barny. The hardware and OS seem problematic. – AhmadWabbi Jun 22 '16 at 07:16
  • @barny good point, I did this already, but now I did this again, and this time got someone else on the line and better answers. The PC can support much more NPorts. There is a nice configuration that messes the process up. – Mong Zhu Jun 27 '16 at 09:12