View previous topic :: View next topic |
Author |
Message |
matjazs
Joined: 08 Nov 2016 Posts: 86
|
Posted: Wed Oct 30, 2019 1:06 pm Post subject: Reading data trough RS232 interface |
|
|
I have ATMEGA128A3U and on first port (COM1) read TXT data.
Would someone have an idea, how read this data?
First character is space, on the end of rows is CRLF.
Code: | chann rs dBm MCC MNC BCC C1 C2
122 39 -71 293 41 5 40 40
112 34 -76 293 41 0 31 31
116 34 -76 293 41 6 35 35
118 33 -77 293 41 5 34 34
113 32 -78 293 41 7 29 29
663 31 -79 293 41 1 26 26
OK |
Number of rows is not constant but it is depend of situation, maximum is 10.
For me it will be good solution, that I can read each rows.
I tryed with Ischarwaiting() function and wait for "space", but it doesn't work.
This table appear each second, between this time uC read from the same COM port other data in TXT format.
With other data I don't have any problems, because each rows start with special character f.e. * or +.
Best regards M.
(BASCOM-AVR version : 2.0.8.2 ) |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Wed Oct 30, 2019 1:51 pm Post subject: |
|
|
Space is a character with value 32 so rest of the values also comes like a string with these spaces like you presents?
Code: |
Const Max_len = 10
Dim Mystr (10) As String * Max_len
Dim Char As Byte , Idx As Byte , Row As Byte
Dim Got_msg As Byte , Receiving As Byte , Err_flag As Byte
Open "COM1:" For Binary As # 1
Enable Interrupts
Do
If 0 < Ischarwaiting(# 1) Then
Char = Waitkey(# 1)
Select Case Char
Case 32 'space
If Receiving = 0 Then 'first space
Receiving = 1
Row = 1 : Idx = 0
Else 'next space
Incr Row
If Row > 10 Then
Err_flag = 1 : Row = 1 'this is probably error because no enter after 10 msg`s
End If
End If
Case 13 'simply ignore, swallow enter
Case 10 'LF sign->Parse new data
Got_msg = 1
Case Else
If Receiving = 1 Then 'wait for first space for synchro
Mystr (row ) = Mystr (row ) + Chr(char )
Incr Idx
If Idx = Max_len Then
Err_flag = 1 : Incr Row 'error cause msg is too big
End If
End If
End Select
If Got_msg = 1 Then 'parse new msg
If Err_flag = 0 Then
'here you have array(row) of strings
Else
'there you can judge if you want to parse corrupted data
Err_flag = 0
End If
Got_msg = 0 : Receiving = 0 'we wait for new start after first space
End If
End If
Loop
End |
|
|
Back to top |
|
|
matjazs
Joined: 08 Nov 2016 Posts: 86
|
Posted: Tue Nov 12, 2019 7:53 am Post subject: |
|
|
EDC Than'k you very much. You are realy expert.
I tested this code and works OK. Otherwise all spaces in row disappear, but this is not a big problem.
Troubless appear when I recieve other text on the same COM port aproximately each second.
On this COM port recive also other text information with first character f.e. "+" or "*", or "$", but sometimes text start also with space.
How make solution with this mix of text is for me big problem
Best regards, Matjaz |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|