I am looking for a vb.net expert who can help me with the following topic:
I have a serialport waiterlock which I have to access through several forms. I looped through the internet but I
did not get a satisfying answer.
This code does what it should do:
Now I have the following problem: I want to access the serialport from other forms. I have tried to use the serialport as a global variable and work with another addhandler on another form. But this does not work.
I obviously need a class or a module with the serialport.datareceived event which I can access from all forms.
If you can help me please make an offer.
I have a serialport waiterlock which I have to access through several forms. I looped through the internet but I
did not get a satisfying answer.
This code does what it should do:
B4X:
Imports System.IO.Ports
Imports System.Text
Public Class Form1
Private serialport As SerialPort
Public waiterbuffer As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
serialport = New SerialPort
With serialport
.PortName = "COM2"
.BaudRate = 9600
.DataBits = 8
.StopBits = CType(1, StopBits)
.Parity = Parity.None
.Handshake = IO.Ports.Handshake.None
.RtsEnable = True
.ReceivedBytesThreshold = 1
.NewLine = vbCr
.DiscardNull = False
.Encoding = Encoding.Default
End With
AddHandler serialport.DataReceived, AddressOf Me.serialport_DataReceived
serialport.Open()
End Sub
Private Sub serialport_DataReceived(sender As Object, e As SerialDataReceivedEventArgs)
waiterbuffer = serialport.ReadLine
Me.BeginInvoke(New EventHandler(Of SerialDataReceivedEventArgs)(AddressOf txtreceived), New Object() {sender, e})
End Sub
Private Sub txtreceived(sender As Object, e As EventArgs)
txt_debug.AppendText("ID: " & waiterbuffer & vbCrLf)
End Sub
End Class
Now I have the following problem: I want to access the serialport from other forms. I have tried to use the serialport as a global variable and work with another addhandler on another form. But this does not work.
I obviously need a class or a module with the serialport.datareceived event which I can access from all forms.
If you can help me please make an offer.
Last edited: