PDA

View Full Version : Do a calculation from serial data



dakota77
01-06-2006, 05:34 AM
Hello,
From a Pocket Pc connected to BS2p I send the string "40A"

In the Basic Stamp I'd like to retrieve the value 40 and store it in variable x
Then do a calculation on x: y=x * 2

So I want to get the number 80.

In the program below :
The DEBUG 1) displays 40 (DEC x)
The DEBUG 2) displays P (ASCII code 80 = P)
How can I retrieve 40 as a number and then do operation on it ?
Thanks for your help.

main:
SERIN 7,16624,[DEC x]
IF x>0 THEN rel2
GOTO main

rel2:
DEBUG "1) DEC x = ",DEC x,CR
y=x*2
DEBUG "2) y = ",y
GOTO main

In the BS manual it's written :

"DEC tells SERIN to convert incoming text representing decimal numbers into true-decimal form and store the result in serdata. Afterwards, the program can perform any numeric operation on the number just like any other number."

Newzed
01-06-2006, 05:44 AM
Change

DEBUG "2) y = ",y
to read

DEBUG ")2 y = " dec y

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html


Newzed
01-06-2006, 05:45 AM
Oops - forgot the comma before dec y.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html


joe from NY
01-06-2006, 06:34 AM
how is the Pocket pc hooked up to the stamp? Does it have a serial port?

dakota77
01-06-2006, 05:41 PM
Thanks for your help. I have not already check if it's working.

Yes the HX4700 has a serial port.

Mario