Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

'Split' seems to breakup a string wrong

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
jeroenpost

Bascom Member



Joined: 19 Aug 2014
Posts: 3

netherlands.gif
PostPosted: Wed Sep 03, 2014 10:03 pm    Post subject: 'Split' seems to breakup a string wrong Reply with quote

I am new in the Bascom and Arduino world.
The project i am working on is an attempt to read GPS data, battery voltage, altitude and motor current from a model airplane and send this data to a laptop.
I came this far:
reading the GPS data from a SW-comport.
making 6,7,8 or 9 strings containing this data.
Adding the measurements current, voltage, altitude / airspeed.
and sending it to a SW-comport to a data sender.

Now something’s simple....add the relevant GPS data.

I want to break up the string with are containing data separated with a ",".
so..split should do the trick.

to show what the problem is…

T_int = Split(r_str(1) , S_str(1) , "," )

Ard(1) = ""
For S_int = 1 To T_int
Ard(1) = Ard(1) + S_str(s_int) + " "
Next

It should break up the string r_str(1) and place the parts separated with "," into an array S_Str().
then put is back together in Ard(1) but the "," should be replaced with spaces.


r_str(1) contains : $GPRMC,202313.00,A,5230.00005,N,00447.12334,E,0.041,,030914,,,A*7A

Ard(1) contains : $GPRMC 202524.00 A 5229.99807 N 00447.1217 4 E 0.054 030914 A*78
(don’t mind the difference in data)
Has anyone any idée why ‘split’ breaks up ,00447.12334,E, into 00447.1233 4 E

(GPS data is dynamic, splitting it up using a separator is the best way... if its works correct..)
See the attachment for the program

(BASCOM-AVR version : 2.0.7.7 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5071
Location: Holland

blank.gif
PostPosted: Wed Sep 03, 2014 11:04 pm    Post subject: Reply with quote

Hi Jeroen,

Welcome.

it seems that split() is working correct.
just tried it in the sim:

Code:
  T_int = 1
r_str(1)="$GPRMC,202313.00,A,5230.00005,N,00447.12334,E,0.041,,030914,,,A*7A"
goto test

...

test:
    T_int = Split(r_str(1) , S_str(1) , "," )

'prepaire data for HOST (more to come here)
    Ard(1) = ""
    For S_int = 1 To T_int
       Ard(1) = Ard(1) + S_str(s_int) + ","
    Next
   print ard(1) '         '$GPRMC,202313.00,A,5230.00005,N,00447.1233,4,E,0.041,,030914,,,A*7A,
 

as you can see the results are the same.
if the only goal is to replace a char for another one have a look at REPLACECHARS in the help.

if you need split, debug by printing the data you have before and after the conversion.
I suspect the data you think you have is not what you have. Or the target array is too small so the strings are broken up.

_________________
Mark
Back to top
View user's profile Visit poster's website
jeroenpost

Bascom Member



Joined: 19 Aug 2014
Posts: 3

netherlands.gif
PostPosted: Thu Sep 04, 2014 10:33 pm    Post subject: Reply with quote

Hi Mark,

In your SIM the Longitude is also broken up in two.
This is caused by the size of the target array string.

Read the manual, but don't believe everything they say…
The format of the Longitude should be dddmm.mmmm (10 char) (example:12158.3416)
The GPS send 00447.12334 and that’s 11 char’s
The format of the Latitude should be ddmm.mmmm (9 char) but also contains 1 more.
So…
Dim S_str(20) As String * 10
Should be
Dim S_str(20) As String * 12

Thanks….
Jeroen.
Back to top
View user's profile
Arera

Bascom Member



Joined: 23 Sep 2007
Posts: 375
Location: Wuppertal, Germany

germany.gif
PostPosted: Sat Sep 06, 2014 11:16 am    Post subject: Reply with quote

It is always a good idea to dim strings a bit longer than you would expect them to be.
Strings can be (invisibly) terminated by one or two characters, or grow for any other reason. The only disadvantage of dimming them longer is the extra use of ram. If that is no point, dim them long.
Back to top
View user's profile
jeroenpost

Bascom Member



Joined: 19 Aug 2014
Posts: 3

netherlands.gif
PostPosted: Wed Sep 10, 2014 8:22 pm    Post subject: Reply with quote

Arera,
I expected split to break of the string to make it fit the target array.
It does but Split puts the remains in the next element of the array.
But you right. I also encountered NULL chars in the source string, so extra space is useful.
I am not happy with a software-UART. It makes the program time critical.
Let’s see if I can use the hardware-UART…
Thanks for the response.

Jeroen.
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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