Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 13:03 14 Sep 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 : Newie got a few questions

     Page 6 of 25    
Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:49am 31 Aug 2016
Copy link to clipboard 
Print this post

This is what my sub now is
BUT it's printing everything until it gets to
[quote]FieldArray$(Count) = FieldArray$(Count) + Chr$(char)
Error: String too long[quote]

SUB

[code]SUB SERIAL3
Local F$
LOCAL N as INTEGER
F$ = Input$(254, #3) 'Suck everything in buffer out
N = GetFieldArray(F$)
'PRINT FieldArray$(0)
PRINT FieldArray$(1)
PRINT FieldArray$(2)
PRINT FieldArray$(3)
PRINT FieldArray$(4)
pause 500
End Sub [/code]
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:53am 31 Aug 2016
Copy link to clipboard 
Print this post

What I really want/need to do is
1 Suck everything out of the serial port
2 Count the arrays in the port at that moment
3 Check the first array in the serial port and
4 IF it's "Time" then go to one sub (for printing)
5 IF it's DAY2 go to a different sub (for printing)
6 IF it's DAY3 go to another sub (for printing)
7 Close the serial port which will clear the buffer ready for the next transmission
8 Pause 600
9 Open serial port again

I've "split" the data being sent by the ESP8266 into various segments, each with a 1 second delay before it then sends that segment (5 segements)
and then it's repeated at 5 min intervalsEdited by lew247 2016-09-01
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 01:55am 31 Aug 2016
Copy link to clipboard 
Print this post

If it helps anyone
this is NOW what is coming in the serial port of the Micromite
There is a pause of 1000 before each serial string is sent (1 second between each line)
[code]Update Time Wed:12:53:23

Today,scattered clouds,03d,19.72,1018,5.7,290,82

Day2,Thu Sep 01 12:00:00 2016,clear sky,02d,14.09,20.06,1018,67,4.52,290

Day3,Fri Sep 02 12:00:00 2016,moderate rain,10d,13.82,20.02,1018,91,6.19,290

Day4,Sat Sep 03 12:00:00 2016,heavy intensity rain,10d,12.24,18.25,1018,80,4.76

Day5,Sun Sep 04 12:00:00 2016,light rain,10d,8.2,17.8,1018,0,3.83[/code]
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 02:21am 31 Aug 2016
Copy link to clipboard 
Print this post

Just call the function with the data you want to split and it does just that and puts the result in the FieldArray$. It also returns the number of fields so that you can check this and determine if the right amount of data has been parsed.

You then access each field by its index.
FieldArray$(0) until FieldArray$(N)


[code]
Data$ = "Today,scattered clouds,03d,19.72,1018,5.7,290,82"
N = GetFieldArray(Data$)

FOR L = 0 TO N - 1
PRINT FieldArray(L)
NEXT
[/code]

In the data you showed there are at most 10 fields.
You could then use
DIM FieldArray$(10)

If needed add a LENGHTH for the maximum length a field could be. In the above data the timestamp is the largest with 24 characters.
If you have control how the timestamp is made you could make it simpler to parse when you use a format like YYYYMMDDHHmmSS. It is a lot shorter and much easier to work with.

I would also suggest to change the line that has the data for Today. Make it the same number of fields and order as all the other lines, you can then use a single routine to parse all the lines. Currently you would need two.



Edited by MicroBlocks 2016-09-01
Microblocks. Build with logic.
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 07:10am 31 Aug 2016
Copy link to clipboard 
Print this post

I'm starting to get there
After spending almost 2 full days on this I've "partly" got it working

This is the code I'm using
[code]Open "COM1:19200" As #1 'Open port for HC-12 TX/RX
OPEN "COM3:9200" AS #3 'Open port for ESP8266

IF LOC(#1) > 1 THEN SERIAL1
END IF
IF LOC(#3) > 1 THEN SERIAL3
END IF

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
FieldArray$(Count) = FieldArray$(Count) + Chr$(char)
EndIf
EndIf
Next
GetFieldArray = Count + 1
End Function

SUB SERIAL3
Local F$
LOCAL N as INTEGER
F$ = Input$(100, #3) 'Suck everything in buffer out
N = GetFieldArray(F$)
print FieldArray$(0);
print FieldArray$(1);
print FieldArray$(3);
print FieldArray$(4);
CLOSE #3
CLOSE #1
Open "COM1:19200" As #1 'Open port for HC-12 TX/RX
OPEN "COM3:9200" AS #3 'Open port for ESP8266
pause 400
End Sub[/code]

It's "KINDA" working
It now prints this





BUT prints every 4 items one after the other until it does this

FieldArray$(Count) = FieldArray$(Count) + Chr$(char)
Error: String too long

I think I need to clear the FieldArray$ when I close the serial port but not sure how to do this

I also need to put a line feed after each item is printed, I THOUGHT I had done that by adding ; at the end of the print statement

EDIT:
For clarity here is the information being received on Com3
[quote]Today,few clouds,02d,18.59,1019,5.1,290,59
Day2,Thu Sep 01 12:00:00 2016,clear sky,02d,14.31,20.28,1019,67,4.52,290
Day3,Thu Sep 01 12:00:00 2016,clear sky,02d,14.31,20.28,1019,67,4.52,290
Day4,Thu Sep 01 12:00:00 2016,clear sky,02d,14.31,20.28,1019,67,4.52,290
Day5,Thu Sep 01 12:00:00 2016,clear sky,02d,14.31,20.28,1019,67,4.52,290[/quote]

Here's how the info looks when viewed on Terraterm



and

here's how the info looks viewed on the MMEDIT console



The Function seems to me to be stripping the commas from the received data?
AND it also doesn't clear the count when it receives new data from the com port, it just adds it all up till it crashes
Edited by lew247 2016-09-01
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2946
Posted: 08:24am 31 Aug 2016
Copy link to clipboard 
Print this post

The semi-colon at the end of a PRINT statement will PREVENT the linefeed. Simply remove the semicolon!
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2946
Posted: 08:36am 31 Aug 2016
Copy link to clipboard 
Print this post

To 'empty' an array element I would simply set it to an empty string AFTER you have finished with the element.

So for example; if you want to simply print the data contained in FieldArray$(7) then use:
PRINT FieldArray$(7): FieldArray$(7)=""
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:02am 31 Aug 2016
Copy link to clipboard 
Print this post

Thanks Phil
It's getting better but still not right
[quote]FieldArray$(Count) = FieldArray$(Count) + Chr$(char)
Error: String too long[/quote]
The FieldArray$ is still counting after printing, I need to find a way to clear the whole FieldArray$ after I've finished printing the elements I need so it's empty for the next serial input
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 09:36am 31 Aug 2016
Copy link to clipboard 
Print this post

Yes, what WW said.
However there is another way and that is to make sure the array is empty before you use the function.
[code]
FOR L = 0 TO NumberOfFields - 1
FieldArray$(L) = ""
NEXT
[/code]

A better way is to add this to the function itself, so that each time you call it, it will clear the values for you. Unfortunately MMBasic does not have a UBOUND so there is no way to get the number of items in an array. The thing you have to be aware of is that you HAVE TO USE the number of fields that is returned by this function to check how many fields have valid information.

[code]
Function GetFieldArray( Record$, Delimiter$, KeepQuotes ) AS INTEGER
  Local Index, Char, InQuote, Count   
  InQuote = 0   
  Count = 0
FieldArray$(Count) = ""
  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   
FieldArray$(Count) = ""
    Else   
      If Char <> 34 Or KeepQuotes Then   
        FieldArray$(Count) = FieldArray$(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: 10:23am 31 Aug 2016
Copy link to clipboard 
Print this post

Thanks Jean
That definitely hekped
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9638
Posted: 03:51pm 31 Aug 2016
Copy link to clipboard 
Print this post

Slightly off topic, but congratulations on a ten-page thread, lew.
Plenty of interest in this subject to make it to double-digit pages.

Although, applause might not be exactly what you are wanting considering you probably did not want this thread to be this long, but for whatever reason, 10+ pages is an achievement.

...but I digress.......
Smoke makes things work. When the smoke gets out, it stops!
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:08pm 31 Aug 2016
Copy link to clipboard 
Print this post

Not sure if that's good or bad Grogster

Can anyone tell me what I'm doing wrong please?

icon = "03d.bmp"
LOAD IMAGE icon$ [,392 , 185]

Edit I've also tried
icon$ = "03d.bmp"

neither work - Error: Expression syntax

Edited by lew247 2016-09-02
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10397
Posted: 11:11pm 31 Aug 2016
Copy link to clipboard 
Print this post

icon icon$
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:15pm 31 Aug 2016
Copy link to clipboard 
Print this post

I thought that might be it, I had already tried
icon = "03d.bmp"
LOAD IMAGE icon [,392 , 185]

I get the error [174] Load IMAGE icon [,392 , 185]
Error: Expected a string

EDIT

if I change it to
icon$ = "03d.bmp"
LOAD IMAGE icon$ [,392 , 185]

I get [174] Load IMAGE icon$ [,392 , 185]
Error: Expression syntax
Edited by lew247 2016-09-02
 
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 11:23pm 31 Aug 2016
Copy link to clipboard 
Print this post

No [ ] round the location parameters
Codenquilts
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:26pm 31 Aug 2016
Copy link to clipboard 
Print this post

  MikeO said   No [ ] round the location parameters

Thanks Mike - that helped a bit

The error is here somewhere icon = "02n.bmp"


IF I do
LOAD IMAGE "02d.bmp" , 392 , 185 - it works
if I do
LOAD IMAGE icon$ , 392 , 185 - it doesn'tEdited by lew247 2016-09-02
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2946
Posted: 11:44pm 31 Aug 2016
Copy link to clipboard 
Print this post

lew247

It works for me - just ensure icon$ is loaded with ICON$="02d.bmp" first before you call LOAD IMAGE ICON$

 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:49pm 31 Aug 2016
Copy link to clipboard 
Print this post

Got it working Phil
it was actually an IF THEN ELSE statement that was wrong before the icon select statement
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 02:24am 01 Sep 2016
Copy link to clipboard 
Print this post

Different problems this time

I'm "trying" to learn about touch and switches and so on
I've been trying to do this

GUI SWITCH #80, "Today|Forecast" , 300, 185, 80, 40, RGB(WHITE), RGB(BLUE)
Error: GUI reference number #80 is in use

but every time I try it I get the error
[quote]Error: GUI reference number #80 is in use[/quote]
I get the same error no matter what gui number I use from 1 to 100

I'm using a 64 pin MM+ with 5.2 and a 7 inch touchscreen

I ideally want to end up with a way that once I touch the screen (anywhere) or a "switch" I can clear the screen, keep the clock and other interrupts workng in the background and display information on a 2nd screen
Then when the screen is touched again (or the switch pressed) it reverts back to the original display

I have it working so if I use touchup and touchdown I go back to the original screen when I let go of the screen, but that's no use as I want to do something with a "2nd screen"

Specifically I want to display the weather forecast for several days on the 2nd screen with no fancy graphics, just a background picture (maybe)
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 03:35am 01 Sep 2016
Copy link to clipboard 
Print this post

This is frustrating
Page 26 of the MM+ manual has this
GUI SWITCH #ref, caption$, StartX, StartY, Width, Height, FColour, BColour

I cannot get it to work, it says "Reference number reference number in use" , I have it exactly as the manual says and I even tried it without the # in front of the reference number

EDIT:
I have the same problem with GUI BUTTON - GUI reference number #"number" is in useEdited by lew247 2016-09-02
 
     Page 6 of 25    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025