Read minus value

Howky

New Member
Here is my program:
the program on my computer sends data via the COM port to Picaxe
the data looks like this:kpk2 , kpk5, kpk10 etc...but occasionally the values are minus kpk-2, kpk-4, etc
is it possible to process minus values?

like this? when the state is minus, for example, kpk-12 goto stav2




setfreq m16

symbol hodnota = w3
start: ; zacatek programu
serin C.4,N9600_16,("kpk"),#hodnota ; nastaveni portu a nazev hodnoty kpk
if hodnota=0 then goto stav1 ;rovna se hodnota kpk 0 jdi na stav1
if hodnota=1 then goto stav2 ; rovna se hodnota kpk 1 jdi na stav2
goto start: ;

stav1:
low B.0 ;zhasni pin B.0
goto start ; zpet na zacatek programu start

stav2:

high B.0 ;rozsvit pin B.0
goto start
 

oracacle

Senior Member
I've not had dealing with this, but I suspect if you receive into 2 variables. check the first one for a negative symbol, if it is negative read the second variable and carry out the course of action for that. if its not then just carry out the course of action for the number in the variable.
 

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

The PICAXE does not itself understand negative numbers but it can hold negative number representations.

The problem here is not so much a negative number issue but reading in a stream which is "kpk", a possible "-" symbol, then some number of digit characters.

I cannot think of any way to read all the possible options, "kpk1", "kpk-1", "kpk12", "kpk-12", etc using SERIN.

Do you have any control over what is sending the data ? If you do and can alter that to include a "+" sign when zero or positive then it should be trivial to solve.
 

hippy

Technical Support
Staff member
I'm surprised I wrote a bit stupid, in the demo program what i need so pkp0 and pkp-1
Are you saying those are the only two possibilities ever sent ? If so that's quite easy -

SerIn ... ( "kpk" ), b0
If b0 = "0" Then .... Else ...

Otherwise, if it is any positive or negative number sent; which PICAXE device are you using ?

If using an X2 variant you should be able to use the hardware background serial receive, and then extract the data, but that won't be possible with the M2 variants.
 
Last edited:
Top