First of all, title your threads a little better than this next time, like "Custom Serial Port Events" or something of the like. You'll get more responses that way.
Here is an example of a custom event I found at
Code:
Public Class RegistrationWatch
Public Event NewRegistrations(ByVal pStudents As DataSet)
' Other methods and properties
Public Sub Look()
Dim dsStuds As DataSet
Dim flNew As Boolean
' Method that fires on a timer to look for new registrations
' since the last invocation of the method
' If one is found then create a DataSet with the new students
' and raise the event
flNew = True
dsStuds = New DataSet()
If flNew Then
RaiseEvent NewRegistrations(dsStuds)
End If
End Sub
End Class
I'm pretty sure you at least have a dll loaded to read from the Serial Port(s).
- First, make a class to handle the serial port(s).
- Add your existing code to it.
- Add an event to it, I'll use SerialPortEnabled
- Make a timer that tracks "something in that dll" that changes when you need the event to fire. When it detects the "event" you have in the timer, use the RaiseEvent command like in the above example.
- In another class/module/etc., you'll have to make an object to hold the class that can trigger the event, and a method to handle the Event.
Code:
'Serial Port Class
Public Class SerialPortClass
'Make sure you add this...
'This is the event declaration
Public Event SerialPortEnabled(ByVal someNeededParam As Object)
'Make a timer
Private tmrSerialEnabledCheck as Timer = New Timer
Public Sub New()
'Set Interval to 1/10th of a second(100 milliseconds)
tmrSerialEnabledCheck.Interval = 100
'Turn on the timer
tmrSerialEnabledCheck.Enabled = True
'Add any other code needed...
End Sub
'Put what you need in here to do whatever with the
'serial port(s)
'Handle the Timer's Tick Event
Private Sub CatchSerialEnabledEvent() Handles tmrSerialEnabledCheck.Tick
'Here you check your "something in the dll"
'If the "something" matches what should call the
'event then
RaiseEvent SerialPortEnabled(<add a parameter if you need too>)
End Sub
End Class
Public Class MainClass
'Declare a New SerialPortClass
'MAKE SURE YOU PUT THE WithEvents IN THERE
Public WithEvents oSerialPort As SerialPortClass = _
New SerialPortClass
'Make a method to handle the Serial Port Event
Public Sub oSerialPort_SerialPortEnabled(<any needed params>) Handles oSerialPort.SerialPortEnabled
'Do what you gotta do here...
End Sub
End Class
If you need more specific events search the web for VB.NET Delegates.
I haven't tried any of the code I just wrote here, so it's quite possible there is something wrong with it, but I really have to get back to work, so hopefully this gives you a start.
Hope this helps you out.
-Merk
There will either be World Peace or The World in Pieces. Everything we do plays a part for one of the outcomes.