Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Problems with {034} inside strings in Print statements

 
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
mattcro

Bascom Member



Joined: 03 Oct 2007
Posts: 324
Location: Scotland

uk.gif
PostPosted: Mon May 16, 2011 5:06 pm    Post subject: Problems with {034} inside strings in Print statements Reply with quote

I'm trying to use the {034} trick in string constants to insert quotation marks in AT commands, but the strings are not correctly compiled. For example:
Code:
Dim Gprs_apn As String * 30
Gprs_apn = "my.ip.com"
Print "AT+CGDCONT=1,{034}IP{034},{034}" ; Gprs_apn ; "{034},{034}0.0.0.0{034},0,0" ; Chr(&H0d)
 


In the simulator and real program execution I get the following output:
Code:
AT+CGDCONT=1,"IP","" ; Gprs_apn ; "","0.0.0.0",0,0

 


Of course, I hoped to get the actual APN as part of the output string, but Bascom seems get confused with the {034} and the string delimiter quote marks... can this be considered as a bug? This is in version 2.0.5.0.

As a workaround I am using Quote() or Chr(34).

_________________
If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.2
Back to top
View user's profile
MAK3

Bascom Member



Joined: 24 Sep 2010
Posts: 450
Location: Germany

germany.gif
PostPosted: Mon May 16, 2011 5:39 pm    Post subject: Reply with quote

Hi mattcro,

to get this:
Quote:
AT+CCLK="10/02/15,08:02:00"


I use:
Code:
Print #2 , "at+cclk=" + Chr(34) + Sm5100_year + "/" + Sm5100_month + "/" + Sm5100_day + "," + Time$ + Chr(34)


(all variables are strings)

MAK3
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Mon May 16, 2011 8:30 pm    Post subject: Quote... Reply with quote

This is also a nice solution...

Code:

Dim A1 As String * 20
Dim A2 As String * 20
Dim A3 As String * 50

A1 = "AT+CCLK="
A2 = Quote( "10/02/15,08:02:00")
A3 = A1 + A2

Print A3

End


You can test it in the simulator...

Have fun
Ben Zijlstra
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1827

blank.gif
PostPosted: Mon May 16, 2011 8:38 pm    Post subject: Reply with quote

Code:
Print "AT+CGDCONT=1," ; Quote( "IP") ; "," ; Quote(Gprs_apn) ; "," ; Quote( "0.0.0.0") ; ",0,0" ; Chr(&H0d)

Quote:
AT+CGDCONT=1,"IP","my.ip.com","0.0.0.0",0,0

Very Happy
Back to top
View user's profile
mattcro

Bascom Member



Joined: 03 Oct 2007
Posts: 324
Location: Scotland

uk.gif
PostPosted: Mon May 16, 2011 8:59 pm    Post subject: Reply with quote

It looks like the parser/compiler gets confused, and treats some of the {034} as delimiter quote marks instead of part of the literal string. Some more tests:
Code:
print "this is {034}quoted{034} text and works OK"
print "this is correctly {034}quoted{034} text " ; "with concatenation"
print "this is just one correctly printed quote mark: {034}"
print "This does not work {034} " + "more text"
print "but {034}this{034} example {034} works correctly"
print "with just one {034} quote" + " and concatenation it goes wrong"
print "with a {034}pair{034} of quotes" + " and concatenation it works OK"
print "with {034}pairs{034} of quotes" + " and {034}concatenation{034} it goes funny"
print "the content of gprs_apn is {034}" + gprs_apn + "{034}. Wrong concatenation and the space before Wrong is missing"
print "this causes multiple <label too long, parentheses missing, numeric parameter expected> compile errors {034}" + gprs_apn

_________________
If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.2
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1827

blank.gif
PostPosted: Mon May 16, 2011 9:46 pm    Post subject: Reply with quote

Just wondering why you get stuck to an undocumented trick, while there's a dedicated function especially for the right use ?
And, if you'd insist it must work, not everything has to Smile
Code:
Print "{000}I do not want to be printed"
Back to top
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2114

netherlands.gif
PostPosted: Mon May 16, 2011 9:56 pm    Post subject: Reply with quote

It's not an undocumented trick, it's described in the help file under Language Fundamentals.

To insert special characters into the string :
s= "AB{027}cd"
The {ascii} will insert the ASCII value into the string.


It doesn't work at described, so it looks like a bug.

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
athomeelectronics

Bascom Member



Joined: 13 Jun 2007
Posts: 60

finland.gif
PostPosted: Tue May 17, 2011 8:11 am    Post subject: Reply with quote

Similar thread:

http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=9334&highlight=
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5071
Location: Holland

blank.gif
PostPosted: Tue May 17, 2011 2:15 pm    Post subject: Reply with quote

when you use print, you can best use ;
print "something" ; somevar ; "etc"

the problem with multiple quotes is that it is hard to know what is part of the strings and what isnt.
print "s"""; """ ' is ; part of the string or not?
As it worked, it checks if there are surrounding quotes.
The {034} solution is nice, but it was converted too early to " internal , leading to problems.
I rewrote it, and i checked with print, assigning, const, etc.
It seems to work fine now but from experience i know there is always some construction that makes it fail.
so i will make a beta available for customers that can only be downloaded with the wiz.
i will add a news item when it is available.

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

Bascom Member



Joined: 03 Oct 2007
Posts: 324
Location: Scotland

uk.gif
PostPosted: Tue May 17, 2011 7:38 pm    Post subject: Reply with quote

Ok Mark. I was going to write a support email but it looks like you are already working on this. Smile

Yes, it looks like the {xxx} gets converted to the corresponding byte value too early in the compile process, and then it is impossible to tell what is string delimiter and what is part of the string.

I wanted to have {034} in the strings to reduce the code size and execution time. It makes sense to have as few string concatenation operation in code execution as possible, when they can be stored as complete string constants.

When I was testing the {034} issues I tried with Print "this; myvar; "that" as well as Print "this" + myvar + "that" but I did not notice any difference. I guess the semicolon is the correct way to do it in a print statement though, since they are separate variables/constants.

_________________
If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.2
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5071
Location: Holland

blank.gif
PostPosted: Tue May 17, 2011 7:53 pm    Post subject: Reply with quote

maybe you can write a test sample that uses print, const , if and assign using {034} and send it to support. i had to make some tricky changes and do not like to break existing {} code.
_________________
Mark
Back to top
View user's profile Visit poster's website
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