# code problem

**URL:** <http://community.robotshop.com/forum/t/code-problem/18458>\
**Category:** Electronics & Software\
**Created:** [July 7, 2009, 4:37pm UTC](http://community.robotshop.com/forum/t/code-problem/18458 "2009-07-07T16:37:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![angryone](http://community.robotshop.com/forum/user_avatar/community.robotshop.com/angryone/32/2605_2.png) [@angryone](http://community.robotshop.com/forum/u/angryone)\
**Post date:** [July 7, 2009, 4:37pm UTC](http://community.robotshop.com/forum/t/code-problem/18458/1 "2009-07-07T16:37:25Z")

</div>

Can anyone tell me why this will not compile?

[code]ENABLEHSERIAL  
sethserial h9600,h8databits,hnoparity,h1stopbits

elmout var long  
elmin var long  
dtc var long

pause 3000

main

```
hserin 500, expd, [elmout]

hserout ">AT Z",13]

	
if elmout= "ready" then
	hserout "req codes"]         
else 
goto main
	         
endif
	serout s_out, N9600, "got data ", elmout]  
   goto main

```

expd  
goto main

endn  
[/code]

I’m using IDE 8.0.1.11. I get an error:

(LINE 47) : [TOKEN “r”] : Expected THEN. It points to the line if elmout. I cant for the life of me figure out why.

Thanks for the help

---

<div class="post-metadata">

**Author:** ![kurte](http://community.robotshop.com/forum/user_avatar/community.robotshop.com/kurte/32/38394_2.png) [@kurte](http://community.robotshop.com/forum/u/kurte)\
**Post date:** [July 7, 2009, 4:54pm UTC](http://community.robotshop.com/forum/t/code-problem/18458/2 "2009-07-07T16:54:55Z")

</div>

Hi AngryOne,

I am not sure about how the basic compiler handles a string in cases like this. I do see some other things that may be issues.

One I believe that your hserin will only pass one byte of data to your variable elmout. You should look at the examples in the Atom Pro PDF under HSERIN. If you wish to accept strings, you should look at the STR io modifier.

The second issue I noticed is even if you could compare in a way similar to what you tried. The variable elmout is a long, which is only 4 bytes long and you are comparing this to a 5 byte string.

Kurt

---

<div class="post-metadata">

**Author:** ![angryone](http://community.robotshop.com/forum/user_avatar/community.robotshop.com/angryone/32/2605_2.png) [@angryone](http://community.robotshop.com/forum/u/angryone)\
**Post date:** [July 7, 2009, 5:04pm UTC](http://community.robotshop.com/forum/t/code-problem/18458/3 "2009-07-07T17:04:06Z")

</div>

Thanks Kurt, I feel kinda dumb mot putting a modifier in there and then declaring that variable as long. I’ll give the manual another looksey and keep you posted on what I come up with

Thanks a bunch for the help, I would have to change my S/N to crazyone if it wasnt for you

---

<div class="post-metadata">

**Author:** ![angryone](http://community.robotshop.com/forum/user_avatar/community.robotshop.com/angryone/32/2605_2.png) [@angryone](http://community.robotshop.com/forum/u/angryone)\
**Post date:** [July 7, 2009, 7:19pm UTC](http://community.robotshop.com/forum/t/code-problem/18458/4 "2009-07-07T19:19:14Z")

</div>

I found something weird (besides the fact they my code may not work). When the value in the if statement is larger than one character, it gives the error stated above

```auto
main

data_in var long
data_out var long
dtc var long     
    

ENABLEHSERIAL
    sethserial h9600,h8databits,hnoparity,h1stopbits

 

hserin 500, expd, [str data_in\5]

 if data_in = "" then   
           goto dtclabel             
       else
           goto resetlabel           
      endif

expd      
goto main
```

More info on what I’m trying to do.

I want to BAP to interface with the elm327 OBDII interpreter [elmelectronics.com/thehome.html](http://elmelectronics.com/thehome.html). My end goal being a handheld scan tool. The elm327 communicates over rs232, using just plain ASCII.

I’m currently trying to see if I can make the BAP talk to Docklight in a similar manner, I set up Doclight to respond to simple messages for ease of trouble shooting.

I’m beginning to fear that this project may be a little over my head due to my noobness. Any guidance is appreciated greatly

---

<div class="post-metadata">

**Author:** ![angryone](http://community.robotshop.com/forum/user_avatar/community.robotshop.com/angryone/32/2605_2.png) [@angryone](http://community.robotshop.com/forum/u/angryone)\
**Post date:** [July 7, 2009, 9:40pm UTC](http://community.robotshop.com/forum/t/code-problem/18458/5 "2009-07-07T21:40:39Z")

</div>

I just tried old code that would compile a similar IF statement. The old code will not compile.

---

<div class="post-metadata">

**Author:** ![robotdude](http://community.robotshop.com/forum/user_avatar/community.robotshop.com/robotdude/32/2468_2.png) [@robotdude](http://community.robotshop.com/forum/u/robotdude)\
**Post date:** [July 7, 2009, 9:45pm UTC](http://community.robotshop.com/forum/t/code-problem/18458/6 "2009-07-07T21:45:16Z")

</div>

Posting the code may be helpful if not just for a reality check. What do you mean specifically “will not compile” are there any errors?

---

<div class="post-metadata">

**Author:** ![angryone](http://community.robotshop.com/forum/user_avatar/community.robotshop.com/angryone/32/2605_2.png) [@angryone](http://community.robotshop.com/forum/u/angryone)\
**Post date:** [July 7, 2009, 9:55pm UTC](http://community.robotshop.com/forum/t/code-problem/18458/7 "2009-07-07T21:55:38Z")

</div>

[code]ENABLEHSERIAL  
sethserial h9600,h8databits,hnoparity,h1stopbits

main

```
   id var long 
   lx var long  
   ly var long  
   rz var long  
   rr var long  
   btn var long 
   
  
  
    

   hserin 500, tmout, [id, hex2 lx\2, hex2 ly\2, hex2 rz\2, hex2 rr\2, hex4 btn\4]   

```

if BTN = “$0000” then  
low p8

```
goto main 

```

tmout

```
   high p8               
   pause 100
   low p8
   pause 100
   high p8                 
   pause 100
   low p8
   pause 100
   goto main [/code]

```

“(LINE 20) : [TOKEN] : Expected , or ]” Indicates the hserin line

[code];  
;  
;  
;  
;-=data requests=-  
;01 -show current data  
;02 -show freeze frame data  
;03 -show dtc  
;04 -clear codes and stored values  
;07 -show pending codes  
;  
;-=parameter ID=-  
;?  
;?  
;MAX232 WIRING YEL=P15 BLK=P14  
;  
;  
main

data\_in var long  
data\_out var long  
dtc var long

ENABLEHSERIAL  
sethserial h9600,h8databits,hnoparity,h1stopbits

hserin 500, expd, [str data\_in]

if data\_in(5) = “ready” then  
goto dtclabel  
else  
goto resetlabel  
endif

expd  
goto main

resetlabel  
hserout “\>AT Z”,13]  
goto main

dtclabel  
hserout “gimme\_codes”,13]  
goto main[/code]

I V0.BAS(LINE 37) : [TOKEN ,] : Expected THEN. Indicating the IF line

---

<div class="post-metadata">

**Author:** ![acidtech](http://community.robotshop.com/forum/letter_avatar/acidtech/32/6_449c533f586939b6e5f246632a46421f.png) [@acidtech](http://community.robotshop.com/forum/u/acidtech)\
**Post date:** [July 7, 2009, 11:34pm UTC](http://community.robotshop.com/forum/t/code-problem/18458/8 "2009-07-07T23:34:45Z")

</div>

The first problem I see if you can’t use a string of characters in an if then(or any other conditional). For example:

`if temp = "1234" then
    ;do stuff
endif`

Is invalid code. You can only compare against single characters( eg “T”) or numbers. Period.

So you need to make a for next loop or something like it to compare a string to another string. But this is kind of high end so I’d like to know what exactly you are trying to do before I go into something that may just confuse you more.

Here however is a modification of your original program that may do what you want.

[code]ENABLEHSERIAL  
sethserial h9600,h8databits,hnoparity,h1stopbits

main  
hserout “\>AT Z”,13]  
hserin 500,main,[wait (“ready”)]  
hserout “req codes”]  
serout s\_out, I9600, “got ready”]  
pause 3000  
goto main[/code]

I simplified it alot but this looks to be the basic jist you were going for. I assume you are talking to some kind of AT device. You send an \>AT Z command and expect a reply of “ready”. If you don’t get it in half a second you retry. It’s been a long time(over 20 years) since I had to use the AT command set but I don’t remember having to send an “\>” before AT but I think this will do what you want.

---

<div class="post-metadata">

**Author:** ![angryone](http://community.robotshop.com/forum/user_avatar/community.robotshop.com/angryone/32/2605_2.png) [@angryone](http://community.robotshop.com/forum/u/angryone)\
**Post date:** [July 8, 2009, 12:01am UTC](http://community.robotshop.com/forum/t/code-problem/18458/9 "2009-07-08T00:01:06Z")

</div>

Thanks Acidtech, I guess I was doing the ol’ square peg in a round hole thing. Thanks for clearing up my error.

I want the atom to communicate with another chip via rs232. The elm is an OBDII to rs232 interpreter. The elm responds to ASCII strings like the following: \>AT Z will reset the elm, \>01 0c will make the elm request PID info from the vehicle ECM, parse it, and respond back with something like 41 0c 1a f8.

I need to send and receive these strings and parse them. I was trying to see if I could simulate the elm chip with Docklight and send strings back and forth. That is when things got retarded, sorry =) A sample for next loop would be awesome. I have other projects that would deal with more strings, so it would be very useful to me.

---

<div class="post-metadata">

**Author:** ![kurte](http://community.robotshop.com/forum/user_avatar/community.robotshop.com/kurte/32/38394_2.png) [@kurte](http://community.robotshop.com/forum/u/kurte)\
**Post date:** [July 8, 2009, 12:16am UTC](http://community.robotshop.com/forum/t/code-problem/18458/10 "2009-07-08T00:16:21Z")

</div>

Hi again,

In you latest post. The first problem is probably the line:

```auto
if BTN = "$0000" then 
```

My guess here is that it should simply be

```auto
if BTN = $0000 then 
```

However compiling this, it looks like a compiler bug, which now that I think about it, I believe I have heard before. The compiler does not appear to allow the #min on the IO modifier in the hserin command. This may not be much of a problem if you are generating your own interface. If you always pass two hex digits it should work with just:  
hex2 lx.

Probably should add this to the bug list.

In your second version, I am pretty sure your end program will not want to wait on a string. When I played with the STR input modifier before, I would do it more like:

```auto
data_in var byte(20) ; allocate 20 bytes.
...
hserin 500, expd, [str data_in\20\13]
```

Note: did not try to compile this so don’t know if the \ will cause problems here as well in hserin. I used it before in serin. Also I had to clear the array before I did the serin into the array as the terminator is not passed into the array. IE if the first time through this loop you receive the command:“QP”, cr  
the first element will be Q and the Second element witll be a P. Now if you loop back and the next input is the command “Q”, cr The first element will be the new “Q” and the second element will still be “P” as only one byte was transfered. I hope that makes sense.

If you can define your own interface, it is easier to use a fixed format, preferably with numbers instead of strings.

As Nathan (AcidTech) also mentioned you can not do a straight compare of strings. There are hacks you can do, for example if you read it into a long variable and the string you were looking for was “1234”, you could probably compare it to 0x31323334 (ie the hex value for the ascii strings), but this can be a pain.

In another program, where I was trying to have the BAP emulate the SSC-32. I instead put all of the input strings into a table and had a asembly language function scan it and return a command index number.  
So there are several ways to approach this.

I hope this helps  
Kurt

---

<div class="post-metadata">

**Author:** ![angryone](http://community.robotshop.com/forum/user_avatar/community.robotshop.com/angryone/32/2605_2.png) [@angryone](http://community.robotshop.com/forum/u/angryone)\
**Post date:** [July 8, 2009, 12:22am UTC](http://community.robotshop.com/forum/t/code-problem/18458/11 "2009-07-08T00:22:00Z")

</div>

It totally does. I dont understand a lot of it, but it gives me dome direction, that’s half the problem
