Italian [Risolto] Intercettare chr(10)

MAX_SV

Active Member
Licensed User
Longtime User
Sto leggendo dei dati da seriale, la stringa che mi manda l'apparecchiatura esterna è sempre terminata dalla coppia CR LF
La seriale legge un carattere alla volta e compongo la stringa al volo, ma non riesco a rilevare il carattere chr(10) ....
In debug il valore è (0xA) quindi di li passa.

Suggerimenti???
 

MAX_SV

Active Member
Licensed User
Longtime User
subito:
B4X:
Sub Astreams1_NewData (Buffer() As Byte)
            ' You must check for DeviceInfo or analyze Buffer data to know what is connected to the USB
            ' The order of the USB could change as you plug them and could change when changing the hub port they are connected to
            Log("NewData:")
            Log(BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
            Dim in_read As String
            in_read = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
            'in_read.Replace (Chr(13),"")
            If in_read=Chr(10) Then
                ' raggiunta fine stringa
                all_string=""
            Else
                ' compongo la stringa
                all_string=all_string & in_read
                lbl_log_seriale.Text = all_string
                Return
           
            End If
 

MAX_SV

Active Member
Licensed User
Longtime User
vedo passare correttamente i dati ... la cosa strana è che con hyperterminal funziona ti allego un log

B4X:
NewData:
N
NewData:


NewData:
NewData:
N
NewData:
NewData:


NewData:
N
NewData:
N
NewData:


NewData:
NewData:
N
NewData:
NewData:


NewData:
N
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
 

sirjo66

Well-Known Member
Licensed User
Longtime User
Secondo me è possibile che la routine non venga chiamata per ogni byte ricevuto, ma ad esempio che venga chiamata con due o più byte nel buffer e in quel caso il confronto con chr (10) fallisce. Prova ad aggiungere un
Log(buffer.lenght)
e dimmi cosa ti scrive il log
 

MAX_SV

Active Member
Licensed User
Longtime User
Secondo me è possibile che la routine non venga chiamata per ogni byte ricevuto, ma ad esempio che venga chiamata con due o più byte nel buffer e in quel caso il confronto con chr (10) fallisce. Prova ad aggiungere un
Log(buffer.lenght)
e dimmi cosa ti scrive il log
ho un picco di 9 ma poi scende e rimane costante a 1
 

MAX_SV

Active Member
Licensed User
Longtime User
comunque è strano secondo te è possibile leggere tutta la riga completa (sarebbe l'ideale) o un carattere alla volta ??
 

sirjo66

Well-Known Member
Licensed User
Longtime User
Non si può decidere, dipende da tanti fattori.
Comunque devi tenerne conto nella riga dove fai il confronto, devi fare un IF con la parte finale della stringa, e non con tutta la stringa come fai attualmente
 
Last edited:

MAX_SV

Active Member
Licensed User
Longtime User
B4X:
Dim verifica As Boolean
Dim str_in As String
str_in = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
all_string= all_string & str_in
verifica= rsp.EndsWith(Chr(10))
If verifica Then
.
.
End If

Alla fine sono riuscito a leggere la stringa intera, sopra il codice se dovesse servire

Segno il thread come risolto
 
Top