Receiving a variable

RickAlty

Senior Member
Hi again... I'm trying to input a number from my PC to the PICAXE. I wrote this code...

main:

serin 4, n2400, b1, b2, b3

for b0 = 1 to b1
high 2
pause 300
low 2
pause 300
next b0
pause 800

for b0 = 1 to b2
high 2
pause 300
low 2
pause 300
next b0
pause 800

for b0 = 1 to b3
high 2
pause 300
low 2
pause 300
next b0
pause 800


serout 1, n2400, ("Hello")

goto main

The PC sends a three digit number. The Picaxe then flashes the LED the correct number of times for the ASCII code of the three digits it has recieved and when it's done it sends "Hello" back to the PC. My VB application displays the "Hello" ok, so that end works too.

But.... If I change the line

serin 4, n2400, b1, b2, b3

to read

serin 4, n2400, #b1, #b2, #b3

which as I understand it should put the actual digits into the variables, not the ASCII codes, nothing happens. The PICAXE just sits as if it is waiting for a SERIN. What am I doing wrong, please?

Richard
 

hippy

Ex-Staff (retired)
The three digit number sent will have been put into b1, and SERIN will be waiting for something which indicates that number has ended and two more numbers to put into b2 and b3.
 

RickAlty

Senior Member
Thanks, Hippy. I changed the line again to only expect one variable, but it still hangs - do I need to send a CR or something after the value?

Also, am I correct that the three-digit number can't be higher than 255?

Richard
 

hippy

Ex-Staff (retired)
Yes, you'll need to send something after the number or the PICAXE will not know if there's another digit coming later or it has finished.

The number can probably be larger than 255, but it will be truncated to 8-bits just as normal arithmatic is. You can read a number up to 65535 using #w0 etc.
 

RickAlty

Senior Member
Thanks, hippy - that did it. I just changed the output line in VB to read ...

MSComm1.Output = Text1.Text & Chr$(13)

and now it works fine.

Richard
 
Top