Shop OBEX P1 Docs P2 Docs Learn Events
String to value — Parallax Forums

String to value

geokonstgeokonst Posts: 48
edited 2008-09-30 20:03 in Propeller 1
Hey everybody. Sorry to bother again.
I am trying to send a decimal variable 0-255 as a two digit hex over serial.
Any ideas why the following code won't work?
CON
  _clkmode = xtal1 + pll16x                             
  _xinfreq = 5_000_000                                  

VAR
   long af          
OBJ
    serial : "Extended_FDSeriall"
      convert : "simple_numbers"
PUB main 
af:= 23
Serial.Start(31,30,%0000, 115200)

 repeat 
          af:= convert.ihex ( 243,2 )
          
          serial.hex (af,2)



I get 35 and 38 and when I change to serial.str I get the right number ($F3) but in ascii.

Comments

  • hippyhippy Posts: 1,981
    edited 2008-09-27 02:52
    I haven't looked at 'simple_numbers' but I'd guess convert.ihex() converts what you give it as a number to a string and a subsequent serial.str prints that string.

    Using serial.hex(af,2) converts a number in af and sends it as two hex characters so there's no reason to call convert.ihex() before it.

      ' Transmits "00", "01", .. "FE", "FF"
      repeat af from 0 to 255
        serial.hex(af,2)
    
    
    

    Post Edited (hippy) : 9/27/2008 2:57:57 AM GMT
  • geokonstgeokonst Posts: 48
    edited 2008-09-30 20:03
    Hippy you were right. I guess I was too tired at that point. Thank you and sorry for not thanking earlier [noparse]:)[/noparse]
Sign In or Register to comment.