Dual Serial Ports


C

cmdolcet69

I have these two subs that are being called on two different timers
threads. It seems that when I get to the DoDualDSIWorkCOM2 that it
keeps passing in the sender and the e as the first serial com and not
the second serial com? How can I fix this?

Public Sub StartWorkerThreadDualDSI1(ByVal gageType As String, ByVal
comPort As Integer)
Dim expectedBaudRate As String = "57600"

Select Case gageType
Case "Mux"
AddHandler dataBackgroundWorker.DoWork, AddressOf
DoMuxWork
AddHandler dataBackgroundWorker.RunWorkerCompleted,
AddressOf MuxWorkComplete
expectedBaudRate = "57600"
Case "DAI"
AddHandler dataBackgroundWorker.DoWork, AddressOf
DoMuxWork
AddHandler dataBackgroundWorker.RunWorkerCompleted,
AddressOf DAIWorkComplete
expectedBaudRate = "57600"
Case "DSI"
AddHandler dataBackgroundWorker.DoWork, AddressOf
DoDualDSIWorkCOM1
AddHandler dataBackgroundWorker.RunWorkerCompleted,
AddressOf DualDSIWorkComplete
expectedBaudRate = "9600"
Case "501"
AddHandler dataBackgroundWorker.DoWork, AddressOf
Do501Work
AddHandler dataBackgroundWorker.RunWorkerCompleted,
AddressOf ASIWorkComplete
expectedBaudRate = "115200"
Case "Sony"
AddHandler dataBackgroundWorker.DoWork, AddressOf
DoSonyWork
AddHandler dataBackgroundWorker.RunWorkerCompleted,
AddressOf SonyWorkComplete
expectedBaudRate = "9600"
End Select


currentSerial = GetSerialPortUsed(comPort)
ChangeCOMBaudRateIfNecessary(expectedBaudRate)
dataBackgroundWorker.RunWorkerAsync(New Object()
{currentSerial})
Me.tmrBackgroundWorker.Enabled = True
End Sub
Public Sub StartWorkerThreadDualDSI2(ByVal gageType As String,
ByVal comPort As Integer)
Dim expectedBaudRate As String = "57600"

Select Case gageType
Case "Mux"
AddHandler dataBackgroundWorker.DoWork, AddressOf
DoMuxWork
AddHandler dataBackgroundWorker.RunWorkerCompleted,
AddressOf MuxWorkComplete
expectedBaudRate = "57600"
Case "DAI"
AddHandler dataBackgroundWorker.DoWork, AddressOf
DoMuxWork
AddHandler dataBackgroundWorker.RunWorkerCompleted,
AddressOf DAIWorkComplete
expectedBaudRate = "57600"
Case "DSI"
AddHandler dataBackgroundWorker2.DoWork, AddressOf
DoDualDSIWorkCOM2
AddHandler dataBackgroundWorker2.RunWorkerCompleted,
AddressOf DualDSIWorkComplete
expectedBaudRate = "9600"
Case "501"
AddHandler dataBackgroundWorker.DoWork, AddressOf
Do501Work
AddHandler dataBackgroundWorker.RunWorkerCompleted,
AddressOf ASIWorkComplete
expectedBaudRate = "115200"
Case "Sony"
AddHandler dataBackgroundWorker.DoWork, AddressOf
DoSonyWork
AddHandler dataBackgroundWorker.RunWorkerCompleted,
AddressOf SonyWorkComplete
expectedBaudRate = "9600"
End Select

currentSerial2 = GetSerialPortUsed(comPort)
ChangeCOMBaudRateIfNecessary(expectedBaudRate)
dataBackgroundWorker2.RunWorkerAsync(New Object()
{currentSerial2})
Me.tmrBackgroundWorker2.Enabled = True
End Sub

Private Sub DoDualDSIWorkCOM1(ByVal sender As Object, ByVal e As
DoWorkEventArgs)
Try
Dim args() As Object = e.Argument
Dim intloop As Integer

CType(args(0), IO.Ports.SerialPort).DiscardInBuffer()
muxClass.GetDualDSIInputCOM1(CType(args(0),
IO.Ports.SerialPort))
Catch ex As Exception
tListener.AddMethodError(ex)
End Try
End Sub

Private Sub DoDualDSIWorkCOM2(ByVal sender As Object, ByVal e As
DoWorkEventArgs)
Try
Dim args() As Object = e.Argument
Dim intloop As Integer

CType(args(0), IO.Ports.SerialPort).DiscardInBuffer()
muxClass.GetDualDSIInputCOM2(CType(args(0),
IO.Ports.SerialPort))
Catch ex As Exception
tListener.AddMethodError(ex)
End Try
End Sub
 
Ad

Advertisements

A

Armin Zingler

cmdolcet69 said:
I have these two subs that are being called on two different timers
threads. It seems that when I get to the DoDualDSIWorkCOM2 that it
keeps passing in the sender and the e as the first serial com and not
the second serial com? How can I fix this?

Public Sub StartWorkerThreadDualDSI1(ByVal gageType As String, ByVal
comPort As Integer)
Dim expectedBaudRate As String = "57600"

Select Case gageType
Case "Mux"
AddHandler dataBackgroundWorker.DoWork, AddressOf
DoMuxWork
AddHandler dataBackgroundWorker.RunWorkerCompleted,
AddressOf MuxWorkComplete
expectedBaudRate = "57600"
Case "DAI"
AddHandler dataBackgroundWorker.DoWork, AddressOf
DoMuxWork

Also AddressOf DoMuxWork here? Not AddressOf DoDAIWork?
Don't know if this answers the question.


Armin
 
C

cmdolcet69

Also AddressOf DoMuxWork here? Not AddressOf DoDAIWork?
Don't know if this answers the question.

Armin

no that work correctly....What is going on is that my
dataBackgroundWorker isn;t changing to dataBackgroundWorker2?
 
Ad

Advertisements

F

Family Tree Mike

It looks like you should be validating that comPort is 1 in
StartWorkerThreadDualDSI1, and comPort is 2 in StartWorkerThreadDualDSI2.
Also you have not shown GetSerialPortUsed(comPort). I think you should log
some diagnostic messages there.
 

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