Shop OBEX P1 Docs P2 Docs Learn Events
Variables — Parallax Forums

Variables

TexFlyTexFly Posts: 26
edited 2011-07-22 05:00 in Propeller 1
Hello,

I'm trying to send/receive information via RS232. I'm able to do so however I need help translating the information I receive on the Propeller.

For example when I send the letter "C" from the computer I can intercept on the SPIN using $43. But how do I output to the video Propeller? I use the graphic library

gr.text(84,20,sin)

But I get weird numbers!

What I really like is to send/receive bits/bytes so I can use the sequence of "1" and "0" to turn on and off Propeller IOs...

Any suggestion?

Thanks!

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2011-07-16 04:10
    create an zip-archive with the archive-function of the propellertool and attach this to posting.
    From what you have posted yet it's not really clear which object you are using (TV, VGA? and there which one exactly?)

    Minimum would be to insert code with the CON-OBJ-VAR-sections of your code and the method that tries to display the characters.

    If you only wnat to switch on/off 8 IOs you could simply send a single byte where each bit represents one IO-pin
    PUB SwitchIO
    
      DIRA[16..23] := %11111111 'set IO-pins as outputs
    
      OUTA[16..23] := receivedByte  'set state of 8 outputs 16..23 to the bitstates of the received byte
    
    

    if you send an ASCII-codes sequence of "0"s and "1"s
    ASCII-Code of "0" is 48
    ASCII-Code of "1" is 49

    so substract 48 from the ASCII-codes to get 0 and 1

    best regards
    Stefan
  • TexFlyTexFly Posts: 26
    edited 2011-07-16 04:21
    Displaying the information is really my second target. To display on the screen I'm using "Graphic Driver 1.0" I found on the OBJEX. It works except for this variable issue...

    What I really like to do is establish a sort of protocol to exchange information between my PC (VB6) and the Propeller. I can do that partially but I would like to send an information to the Propeller (via RS232) to turn on/off some of the bits. So for example let's say I have 16 graphic buttons on my PC code, when I push one of those buttons I like to turn on/off one of the Propeller IOs.
  • Mike GMike G Posts: 2,702
    edited 2011-07-16 07:18
    @TexFly, you could send two bytes that match the I/O you want to control. 0000_0000_1111_1111 would turn on pins 0-7 and turn off 8-15.
  • TexFlyTexFly Posts: 26
    edited 2011-07-16 07:46
    Mike good idea!

    Is there a sort of "midstr" instructions in SPIN so I can parse/extract the bits form the sent string?
  • dgatelydgately Posts: 1,633
    edited 2011-07-16 09:17
    TexFly wrote: »
    Mike good idea!

    Is there a sort of "midstr" instructions in SPIN so I can parse/extract the bits form the sent string?

    There are several "strings" libraries in the OBEX. Brandon Nimon's "Strings Library v2" has several methods such as "SubStr" that will help in pulling individual characters from a string. Kye's "string engine" library allows conversion of strings from and to integers. Send data from your PC to the Prop in any form that makes sense to you (binary string: "11111111", integer text: "255", HEX: "FF"). On the Prop side, convert the string to a usable form (binary, integer)...

    if the PC sends "00000001", something like this should work to set pin 23 to ON
    DIRA[16..23] := %11111111

    ser.GetStr(@myString) ' assumes "ser" is your serial input object (FullDuplexSerialPlus from the OBEX)
    setVal := binaryToNumber(myString) ' convert binary string to an integer
    OUTA[16..23] := setVal ' set pin(s) to ON
  • TexFlyTexFly Posts: 26
    edited 2011-07-16 11:44
    Great, thanks! Just found Kye's library...will test soon.
  • Mike GMike G Posts: 2,702
    edited 2011-07-17 13:09
    You don't need a string library. Send the actual number(s) down the pipe. Don't send ASCII data.
  • TexFlyTexFly Posts: 26
    edited 2011-07-20 03:12
    Mike,

    Would you give me an example?

    Let's say I send "81" HEX (or 10000001 Bin or 129 Dec) to the Propeller. How do I process this information to turn bit 16 and 23 ON?

    Can I do ser.GetStr(@myString) (FullDuplexSerialPlus from the OBEX)

    OUTA[16..23] := mystring

    ???

    Thanks!
  • AribaAriba Posts: 2,690
    edited 2011-07-20 14:26
    OUTA[16..23] := ser.rx
  • TexFlyTexFly Posts: 26
    edited 2011-07-22 04:31
    ...how can I print those information on the TV output to troubleshoot the process?

    I use the OBJEX Graphic interface that works great but I have some trouble printing the variables.

    I have

    gr.color(1)
    gr.textmode(2,2,5,%0001)
    GR.text(60,165,string("CONNECTED!"))
    gr.TextMode(2,1,6,%0001)
    gr.text(54,20,string("P="))
    gr.text(84,20,sin)

    but I get weird numbers on the screen...
  • kuronekokuroneko Posts: 3,623
    edited 2011-07-22 04:38
    Using the Graphics object for debugging seems like overkill. I assume that sin is a variable you want to display. The text method however requires a string pointer. So either you convert your value to a string ([Simple_]Numbers object) or you could fall back to using TV_Text which lets you output variables similar to the serial drivers (dec/bin/hex/str).
  • Mike GMike G Posts: 2,702
    edited 2011-07-22 05:00
    @TexFly, do a little reading on ASCII encoding. It will help you to understand why there are the weird characters on the screen and the difference between an ASCII character and a number.
Sign In or Register to comment.