Author |
Message |
lew247
 Guru
 Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Posted: 02:46am 14 Aug 2016 |
Copy link to clipboard |
 Print this post |
|
I've read both manuals and I understand "TEXT X, Y, STRING, JUSTIFICATION, FONT, SCALE, C, BC"
My question is
if I have a string being recieved on com2 how do I display it?
an example of what I mean
[code]CLS RGB(BLUE)
BOX 9,9,780,460,2,rgb(RED) 'Box round screen
Pin(48) = 0 'Set pin of HC-12 High
Open "COM1:19200" As #2 'Open port for HC-12 TX/RX
OPEN "COM3:9200" AS #3
DO
A$=INPUT$(30, #2)
B$=INPUT$(50,#3)
Print A$;
Print B$;
LOOP
End
End [/code]
This results with the following string being displayed on the console
[quote]START , 13:19:06 , Sun 14-Aug-2016, 26, 971.482, 47.3594, 247.507, 0.958333, 1.35722, 3.22997, 0.2794, 0, 27.75, 0, 25.75, 0, 0.02. 3.66667[/quote]
(there are no spaces between the ,'s)
If I want to display the time which is the 3rd set of characters I believe is right (13:19:06 in this example)
How would I tell the Micromite to display the time received (13:19:06) on the lcd at Text 40,25,"TIME PARSED FROM EXAMPLE" , CM ,1, 2, RGB(WHITE), RGB(BLUE)
I have 2 com ports with different things being received on both
Once I know how to extract and display one of the sets of data I can work the rest out
|
|
Grogster
 Admin Group
 Joined: 31/12/2012 Location: New ZealandPosts: 9590 |
Posted: 02:57am 14 Aug 2016 |
Copy link to clipboard |
 Print this post |
|
Hey there.
HINT: LEFT$ and RIGHT$ - Pages 75 and 78 respectively.
Example:
EXTRACT$=RIGHT$(A$,10) - Take the last ten bytes of A$ from the right-side-end of the string, and put them in EXTRACT$.
This example WON'T do what you want, but LEFT$ will if you play with that command......
Your Text command would then be along the lines of:
Text 40 ,25 ,EXTRACT$ , CM ,1, 2, RGB(WHITE), RGB(BLUE)
Also, check out MID$ - Page 76, which will probably do exactly what you need.
Example:
EXTRACT$=MID$(A$,StartByte,NumberOfBytes)Edited by Grogster 2016-08-15 Smoke makes things work. When the smoke gets out, it stops! |
|
MicroBlocks
 Guru
 Joined: 12/05/2012 Location: ThailandPosts: 2209 |
Posted: 03:15am 14 Aug 2016 |
Copy link to clipboard |
 Print this post |
|
Lewis,
You can use the following function to extract any value you want from a comma separated string.
This has also an example GPS record to test the function
[code]
'Required Global variable for GetFieldArray function
'Dimension this variable so that it can hold all values
Dim GetFieldArray$(12)
' Value is a sample GPS record
Value$ = "$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,0 03.1,W*6A"
Cls
Print "GPS Record:"
Print Value$
Print
N = GetFieldArray(Value$)
'A list of all values
Print "List of all fields"
Print "------------------"
For Index = 0 To N - 1
Print Index, GetFieldArray$(Index)
Next
Print "------------------"
Print
'or directly use a field
Speed = Val(GetFieldArray$(7))
Print "A field used by its index"
Print "-------------------------"
Print "Speed = " Speed
Print "-------------------------"
End
' =============================================================================
' GetFieldArray
' A function to split a string into an Array of fields
'
' Author: Microblocks
' Date: 5 march 2013
' Version: 1.0
'
' This function requires the use of a global variable
' named GetFieldArray$(). It should be dimensioned large
' enough to contain all fields.
'
' Function parameters:
' Record$: A string containing the delimited fields
' Delimiter$: (Optional) delimiter character, when omitted a comma is used
' KeepQuotes: (Optional) [0|1]
' Use value 1 if double quotes around field values have to be kept,
' when omitted or value 0 is used double quotes are discarded
' =============================================================================
Function GetFieldArray( Record$, Delimiter$, KeepQuotes )
Local Index, Char, InQuote, Count
InQuote = 0
Count = 0
If Delimiter$ = "" Then Delimiter$ = ","
For Index = 1 To Len(Record$)
Char = Asc(Mid$(Record$, Index, 1))
If Char = 34 Then
InQuote = Not InQuote
EndIf
If Not InQuote And Instr(Delimiter$, Chr$(char)) >= 1 Then
Count = Count + 1
Else
If Char <> 34 Or KeepQuotes Then
GetFieldArray$(Count) = GetFieldArray$(Count) + Chr$(char)
EndIf
EndIf
Next
GetFieldArray = Count + 1
End Function
[/code]
a compact version of the function
[code]
'Required Global variable for GetFieldArray function
'Dimension this variable so that it can hold all values
Dim GetFieldArray$(12)
N = GetFieldArray(YourStringHere$)
Function GetFieldArray( Record$, Delimiter$, KeepQuotes )
Local Index, Char, InQuote, Count
InQuote = 0
Count = 0
If Delimiter$ = "" Then Delimiter$ = ","
For Index = 1 To Len(Record$)
Char = Asc(Mid$(Record$, Index, 1))
If Char = 34 Then InQuote = Not InQuote
If Not InQuote And Instr(Delimiter$, Chr$(char)) >= 1 Then
Count = Count + 1
Else
If Char <> 34 Or KeepQuotes Then
GetFieldArray$(Count) = GetFieldArray$(Count) + Chr$(char)
EndIf
EndIf
Next
GetFieldArray = Count + 1
End Function
[/code]
Microblocks. Build with logic. |
|
lew247
 Guru
 Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Posted: 03:17am 14 Aug 2016 |
Copy link to clipboard |
 Print this post |
|
Thanks Grogster, that should enable me to work it all out
Edited by lew247 2016-08-15 |
|
lew247
 Guru
 Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Posted: 03:30am 14 Aug 2016 |
Copy link to clipboard |
 Print this post |
|
and Jean - didn't see your post until after I'd pressed enter |
|