I have a app that needs to listen to a serial port and react when something happens. I have NOT yet figured out the hardware side of the serial port but it will be as simple as possible as all it needs to do is detect either a button pressed twice within one second or a constantly held button for two or more seconds (if anyone has an idea please let me know).
For now I just want to be able to read the serial port in the background without interfering with my app. What is the least resource intensive way of doing this? I was thinking something like this to start with:
So this should start it on a background thread but I'm not sure how to go about the constant monitoring of the serial port. I also don't really want to add the "SerialPort" component because as you can see above I only want to enable this functionality for a very few select users. Or would it be better to "create" a SerialPort" component for the selected users and then use the DataReceived event?
I mainly want 0 resource impact on the users not in the allowed list and the lowest resource use possible for those that will have the serial port being used.
For now I just want to be able to read the serial port in the background without interfering with my app. What is the least resource intensive way of doing this? I was thinking something like this to start with:
VB.NET:
Private mySerialPortListenerThread As New Threading.Thread(AddressOf SeriaPortListener)
Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If My.Settings.SerialPortSenders.Contains(UCase(myCurrentUserName))
mySerialPortListenerThread.IsBackground = True
mySerialPortListenerThread.Start()
End If
End Sub
Private Sub SeriaPortListener()
' Do stuff for reading serial port here. Something like:
End Sub
So this should start it on a background thread but I'm not sure how to go about the constant monitoring of the serial port. I also don't really want to add the "SerialPort" component because as you can see above I only want to enable this functionality for a very few select users. Or would it be better to "create" a SerialPort" component for the selected users and then use the DataReceived event?
I mainly want 0 resource impact on the users not in the allowed list and the lowest resource use possible for those that will have the serial port being used.