Invio dati seriali da Arduino a VB.NET NON VA

di il
0 risposte

Invio dati seriali da Arduino a VB.NET NON VA

Sì, ho trovato Xsul forum un paio fi topics al riguardo,   ma non ho capito nulla ( forse a 77anni sono rincoglionito.)
Dunque, ho ripreso in mano un progetto per l agestione del trenino di un amico : il programma in vb.net invia da PC i comandi ad Arduino per attuare gli scambi,alimentare/disalimentare le 32 sezioni di binario, gestire i LED Semaforici: il tutto funziona che è una meraviglia.
Ho avuto la malsana idea di aggiungere agli scambi un limit switch per avere dal campo il feedback sullo stato degli scambi. funziona sul monitor seriale di arduino, ma VB.NET NON RICEVE 

Qui sotto il codice del modulo che gestisce la porta seriale

Imports System.IO.Ports
Module Module1
   Dim SP As New System.IO.Ports.SerialPort
   Public Sub SP_Open(ByVal P As String, ByVal B As Integer)
       SP.PortName = P
       SP.BaudRate = B
       SP.Open()
   End Sub
   '   MySub()
   '  End Sub
   Public Sub SP_Close()
       SP.Close()
   End Sub
   Public Function SP_Read()
       Dim Result As String = ""
       Result = SP.ReadExisting                 'ReadExisting
       Return Result
   End Function
   Public Function SP_Write(ByVal Str As String)
       SP.WriteLine(Str)
       Return Str
   End Function

End Module

l'accesso alla p<orta seriale viene fatto dal Form2

  Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     For Each SP As String In My.Computer.Ports.SerialPortNames
         PortsCombo.Items.Add(SP)
     Next
 End Sub

 Private Sub BtnConnect_Click(sender As Object, e As EventArgs) Handles BtnConnect.Click
     ' thedoor = TextBox1.Text
     'laporta = thedoor
     SP_Open(thedoor, 9600)
     ILLED.BackColor = Color.Red
     messaggi.Text = messaggi.Text & "Connessione stabilita" & vbCrLf
     LivSup.Visible = True
     LivInf.Visible = True
     Docs.Visible = True
     BtnProcedura.Visible = True
 End Sub

dal Form3 attivo il timer1 la cui sub va a leggere i dati in arrivo da arduino

 '************************************************************************************
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    '*****************************************************************************************
    clockTimer.Stop()
    info.Text = "Eccomi sul  Form3 " & vbCrLf
    tore = Int(hh.Text)
    tminuti = Int(mm.Text)
    tsecondi = 0
    Timer1.Enabled = Tru

e qui legge da arduino
 Private Sub Timer1_Tick_1(sender As Object, e As EventArgs) Handles Timer1.Tick
    datain = SP_Read()
    Pino = Mid(datain, 1, 2)           'è l numero che identifivìca il limit switch
    SPino = Mid(datain, 3, 1) ' il numero che dà lo stato 1=deviato 0 = dritto
    info1.Text = ""
    info2.Text = ""
    info1.Text = Pino
    info2.Text = SPino

    If (Pino = "11") Then
        My.Computer.Audio.Play("C:\temp\FSX01.wav")
        DS1W = SPino                        'S1N DEVIATO
        My.Computer.Audio.Play("C:\temp\FSX01.wav")
        DS2W = SPino                        'S1N DEVIATO
        FS2W()
    End If
    If (Pino = "C") Then
        DS3W = SPino                        'S1N DEVIATO
        FS3W()
    End If
    If (Pino = "D") Then
        My.Computer.Audio.Play("C:\temp\FSX01.wav")
        DS1N = SPino                        'S1N DEVIATO
        FSS1N()
    End If
omissis
ENNon sapprei proprio cosa fare ....
Devi accedere o registrarti per scrivere nel forum
0 risposte