View previous topic :: View next topic |
Author |
Message |
mattcro
Joined: 03 Oct 2007 Posts: 327 Location: Scotland
|
Posted: Mon May 16, 2011 5:06 pm Post subject: Problems with {034} inside strings in Print statements |
|
|
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.5 |
|
Back to top |
|
|
MAK3
Joined: 24 Sep 2010 Posts: 449 Location: Germany
|
Posted: Mon May 16, 2011 5:39 pm Post subject: |
|
|
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 |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Mon May 16, 2011 8:30 pm Post subject: 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 |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon May 16, 2011 8:38 pm Post subject: |
|
|
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 |
|
|
Back to top |
|
|
mattcro
Joined: 03 Oct 2007 Posts: 327 Location: Scotland
|
Posted: Mon May 16, 2011 8:59 pm Post subject: |
|
|
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.5 |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Mon May 16, 2011 9:56 pm Post subject: |
|
|
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 |
|
|
athomeelectronics
Joined: 13 Jun 2007 Posts: 60
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue May 17, 2011 2:15 pm Post subject: |
|
|
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 |
|
|
mattcro
Joined: 03 Oct 2007 Posts: 327 Location: Scotland
|
Posted: Tue May 17, 2011 7:38 pm Post subject: |
|
|
Ok Mark. I was going to write a support email but it looks like you are already working on this.
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.5 |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue May 17, 2011 7:53 pm Post subject: |
|
|
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 |
|
|
|