Question Problem in serial Commports!

Noora

New member
Joined
Oct 16, 2008
Messages
1
Programming Experience
Beginner
Hi everyone,

I’m a beginner in vb.net, I have to do a project deals with the serial ports, I found a code that worked great to open and read from one serial comport, but unfortunately when I tried to modify the code to open all the available serial comports in the system at the same time it didn't work well! !!

In The open port method, it opens the first available port and when it gets the second it closes the opened one and then opens the next port and so on.

I check more than code, but i faced the same problem, first check if the other ports is already open, if one of them is open, close it and then open the other port!!

I need to open all the serial ports at the same time because my project have to read from many devices at the same time

my question is:

How can I open all the available comports at the same time and read from them as well?

please help :confused:
 
Hello.

That's somehow pretty easy...

All you'd need would be create a Private List of SerialPort, then loop through all avalaible ports in My.Computer.Ports, open all of them (if possible) and start reading the same way...maybe you could combine this with Multi-Threading.

Some pseudo Code:
VB.NET:
'##### this is supposed to run in another thread... #####
'port is a given parameter
Dim newPort as new SerialPort(port)

Try
      newPort.Open()

      reportBackToMainThread(newPort.readLine())

      newPort.Close()
      newPort.Dispose()
Catch ex as exception
End Try

'##### this is supposed to run in your main thread... #####
For each port as String in My.Computer.Ports
      runAsyncThreadHere(port)
Next

Bobby
 
Back
Top