Problems calling Timer.Enabled=True from SerialPort.DataReceived in VB .NET05
Posted on 2007-10-03
I am trying to enable a timer from a SerialPort.DataReceived rutine. The thing is not working and I suspect it is because I am calling Timer10.Enabled=true from an independent subprocess. I tried to use a delegate defined within a module but I didn't succeed. It is VB .NET 05 and this is the fragment of code:
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
comando = SerialPort1.ReadTo(";")
inicial = Mid(comando, 1, 4)
Select Case inicial
Timer1.enabled=false ' This works fine ! but Timer10.Enabled=True don't
Dim msd As Midelegado = AddressOf Me.ActivaTimer10
In a Module:
Public Delegate Sub Midelegado(ByVal a As Boolean)
In the Form (Form1):
Sub ActivaTimer10(ByVal a As Boolean)
Timer10.Enabled = a
Of course in the program there are more things but these are the relevant ones for the current case.
The program was made with VB6.0 and converted to .NET05 and then modified to use SerialPort instead of MSComm. I checked the serial port sub is working properly and data is being read. I save to copy the Serial port inicialization and so forth.
I have got no error msg but the Timer is not activated. In fact, after the data arrive in the serial port, I can't activate the Timer even from a button on the form.
Thanks in advance