Hi guys, quick question, in dealing with IO.Ports.Serialport
I have this class,
Public Class ComPorts
Friend Shared Sub FindComPorts()
End Sub
Friend Function OpenComPort() As Boolean
End Function
'and such..
(this came from a serial communication example from lvr.com)
I'm using this class on my first form , like such
Public UserPort1 As ComPorts
UserPort1.OpenComPort()
My question arises here: now that the port is open on the first form(UserPort1 is declared:Public UserPort1 As ComPorts on the first form), how do I keep the port open,when I close/hide the first form and give focus/show the second form??
---------------------------
UPDATE:
Thank you for the reply. I added a public module
Module PublicSerialPortModuel
Public UserPort1 As ComPorts
End Module
and now I can use UserPort1 in form2 without the "form1.xxxx" prefix.
I run into another problem though, which got me really nonplussed(well..confused)
I used a even handler on form1 to handle DataReceived event
AddHandler UserPort1.SelectedPort.DataReceived, AddressOf DataReceivedHandler
and that sub is something like
Private Sub DataReceivedHandler(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs)
COMportReadBuffer1 = UserPort1.SelectedPort.ReadExisting
While UserPort1.SelectedPort.BytesToRead > 0
COMportReadBuffer1 &= UserPort1.SelectedPort.ReadExisting
End While
End Sub
which works all fine on the first form. But when I do the same thing on form2,
AddHandler UserPort1.SelectedPort.DataReceived, AddressOf DataReceivedHandler2
when DataReceived event is triggered and I get into DataReceivedHandler2(), the read buffer is blank and its length is 0
Can you think of any possible reasons for this? I can't ..with UserPort1 now being defined public in the public module