Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:02 08 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : LCD question

Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 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 Zealand
Posts: 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: Thailand
Posts: 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 Kingdom
Posts: 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 Kingdom
Posts: 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
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025