I’m a beginner in vb.net and I have no knowledge in it, but I have to use it to do my project. I found a tutorial about Serial Port Communication in VB.Net develped by Psychocoder it was very helpful.
I tested the code, it works great to open and read from one comport, but unfortunately when I tried to modify the code to open all the available comports in the system by adding a loop to get all available ports and read from them simultaneously it doesn’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 modify this sub routine in the frmMain class:
CODE
Private Sub cmdOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOpen.Click
comm.Parity = cboParity.Text
comm.StopBits = cboStop.Text
comm.DataBits = cboData.Text
comm.BaudRate = cboBaud.Text
comm.DisplayWindow = rtbDisplay
'''''''''''''''''''''''''''''''''''''''''''''''''
''These lines I add in the code:
For Each str As String In SerialPort.GetPortNames()
comm.PortName = str
comm.OpenPort()
Next str
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
cmdOpen.Enabled = False
cmdClose.Enabled = True
cmdSend.Enabled = True
End Sub
I tried to check where is the fault, so I tried to remove the command that close the opened port but still it doesn’t work, another issue I faced, only one port is opened.
In the CommManager class:
CODE
Public Function OpenPort() As Boolean
Try
'first check if the port is already open
'if its open then close it
''I removed these lines that close the opened port before openning the next one :
If comPort.IsOpen = True Then
comPort.Close()
End If
How can I open all available ports at the same time and read from them as well???? Do I have to change the whole code?? Or maybe use another library by importing it?? Or is it possible to use the same program and modify it??
Thank you and waiting for a help soon