Multiple COM ports in vb 2003

C

cmdolcet69

I tried to create a multiple COM port which i was success in doing
for just one com port. What seems to be going on is this If I detect
multiple COM port by my activeCOM arraylist then I loop thought the
for loop. In the Ocp.Open it goes to another method and opens the com
port.... When it tries to open the second com port it goes to the
Ocp2.open and open that com2 port... Or its suppose to...Its seems as
if the COM port just open the last created com port....


Can anyone help its urgent?




Public Sub Indicator_COM()
Dim intloop As Integer
For _COMPortIndex = 0 To ActiveCOM.Count - 1
If _COMPortIndex = 0 Then
intCommPort = ActiveCOM(_COMPortIndex)
'IndicatorCOMPort
intBaud = 57600
intData = 8
bytParity = RS232.DataParity.Parity_None
bytStop = RS232.DataStopBit.StopBit_1
oCP.Open(intCommPort, intBaud, intData, bytParity,
bytStop, 4096)
tmrRead.Enabled = True
MenuItem2.Enabled = False
MenuItem3.Enabled = True
ToolBar1.Buttons(0).Enabled = False
ToolBar1.Buttons(1).Enabled = True
TextBox1.Enabled = True
TextBox2.Enabled = True
btnClear.Enabled = True
Me.btnSendTable.Enabled = True
_IndicatorCOM = intCommPort

ElseIf _COMPortIndex = 1 Then
intCommPort2 = ActiveCOM(_COMPortIndex)
'IndicatorCOMPort2
intBaud = 57600
intData = 8
bytParity = RS232.DataParity.Parity_None
bytStop = RS232.DataStopBit.StopBit_1
oCP2.Open(intCommPort2, intBaud, intData, bytParity,
bytStop, 4096)
tmrRead.Enabled = True
MenuItem2.Enabled = False
MenuItem3.Enabled = True
ToolBar1.Buttons(0).Enabled = False
ToolBar1.Buttons(1).Enabled = True
TextBox1.Enabled = True
TextBox2.Enabled = True
btnClear.Enabled = True
Me.btnSendTable.Enabled = True
_IndicatorCOM2 = intCommPort2
End If
'_COMPortIndex += 1
Next
End Sub



Public Overloads Sub Open(ByVal Port As Integer, _
ByVal BaudRate As Integer, ByVal DataBit As Integer, _
ByVal Parity As DataParity, ByVal StopBit As DataStopBit, _
ByVal BufferSize As Integer)

Me.Port = Port
Me.BaudRate = BaudRate
Me.DataBit = DataBit
Me.Parity = Parity
Me.StopBit = StopBit
Me.BufferSize = BufferSize
Open()
End Sub

Public Overloads Sub Open(ByVal Port2 As Integer, _
ByVal BaudRate As Integer, ByVal DataBit As Integer, _
ByVal Parity As DataParity, ByVal StopBit As DataStopBit, _
ByVal BufferSize As Integer)

Me.Port = Port2
Me.BaudRate = BaudRate
Me.DataBit = DataBit
Me.Parity = Parity
Me.StopBit = StopBit
Me.BufferSize = BufferSize
Open()
End Sub
 
A

Armin Zingler

cmdolcet69 said:
I tried to create a multiple COM port which i was success in doing
for just one com port. What seems to be going on is this If I detect
multiple COM port by my activeCOM arraylist then I loop thought the
for loop. In the Ocp.Open it goes to another method and opens the com
port.... When it tries to open the second com port it goes to the
Ocp2.open and open that com2 port... Or its suppose to...Its seems as
if the COM port just open the last created com port....

Do oCP and oCP2 reference different COM port objects? If you write

debug.writeline(OCP Is oCP2)

before the loop, which result do you get?
For _COMPortIndex = 0 To ActiveCOM.Count - 1

How many COM ports do you have? Two or ActiveCOM.Count? The code is written
for two ports but the loop can go further (or is maximum for Count=2?)

Public Overloads Sub Open(ByVal Port As Integer, _
ByVal BaudRate As Integer, ByVal DataBit As Integer, _
ByVal Parity As DataParity, ByVal StopBit As DataStopBit, _
ByVal BufferSize As Integer)

We don't see what this Open method (called above) does.

Public Overloads Sub Open(ByVal Port2 As Integer, _
ByVal BaudRate As Integer, ByVal DataBit As Integer, _
ByVal Parity As DataParity, ByVal StopBit As DataStopBit, _
ByVal BufferSize As Integer)


This can not be compiled because both Open methods have identical
signatures. Are the methods in the same class? You can delete one anyway
because they do exactly the same.

Which option did you set in

Menu Tools -> Options -> Projects and solutions -> Build and run
-> On Run, when build or deployment errors occur



Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top