Shop OBEX P1 Docs P2 Docs Learn Events
PropBasic: TX_BIN, TX_DEC, TX_HEX — Parallax Forums

PropBasic: TX_BIN, TX_DEC, TX_HEX

VonSzarvasVonSzarvas Posts: 3,523
edited 2010-06-11 08:45 in Propeller 1
With SX/B, JonnyMac had provided these useful wrappers around TX_BYTE for formatting "numbers" for transmission to a serial terminal or an LCD (etc..). Very useful for debugging.

Is there such code available for PropBasic ?

---

In case I am overlooking something already available and am asking the wrong question, this is what I would like to achieve:

I have a byte array populated by SHIFTIN.

tmp(0) = $12
tmp(1) = $6a
...
tmp(16) = $17

I would like to TX_HEX each byte to a serial terminal, so it reads 12 6a ... 17

In SX/B I would have run a loop 0 to 16, calling TX_HEX tmp(idx). I think I can almost manage this in a big loop using the STR function to generate DEC format, but not HEX - and it also seems a little heavier than a simple TX_HEX might be...

I have tried to adjust the original TX_HEX, but I believe I am tripping over on the fact that LONGS are longer than bytes!
So really each TX_HEX might need to transmit 00000012 0000006a (or even 1ECF0F1E if I had such a big number in my array!)

* I appreciate my last example is bigger than a byte, but others may need to use TX_HEX for longs - heck even me later!...

Max.

Post Edited (Maxwin) : 5/18/2010 4:13:25 PM GMT

Comments

  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-05-18 13:49
    The Propeller's instruction set (specifically the rotate instructions) makes the process of converting values to binary or hex strings much easier in PropBASIC than in SX/B. See attached. The TX_BIN and TX_HEX subroutines are translations of their Spin counterparts found in FullDuplexSerial.

    [noparse][[/noparse]Edit] #1: Added TX_DEC

    [noparse][[/noparse]Edit] #2: Improved TX_DEC speed by about 14% -- removed one division (replaced with loop)

    [noparse][[/noparse]Edit] #3: See below

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA

    Post Edited (JonnyMac) : 5/19/2010 5:31:09 PM GMT
  • VonSzarvasVonSzarvas Posts: 3,523
    edited 2010-05-18 15:26
    THANK YOU JonnyMac !


    I have also updated the title of this post to reflect the TX_BIN routine included in your sample code.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-05-18 15:47
    Well... I noticed that your original post mentioned TX_DEC -- so I added it (to my original post). Note that TX_DEC uses division twice and consumes a fair bit of code space.· It is surrounded by {$IFUSED ...} markers so that it doesn't get compiled into your project unless you actually use it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-05-19 17:35
    George Lucas says that movies are never finished, they're simply abandoned.· I think that holds true for programs as well.· So... I'm about to abandon my TX formatting code for PropBASIC because I think I've taken it as far as it needs to go.

    The attached is my final version which LOADs subroutine definitions and associated code·from external files; this makes using formatted TX output easy in any program without copy-and-paste.· Some of you will notice a small bit of inline Assembly in a couple routines;··I did this to circumvent the normal compiler output which was creating problems when I wanted to reuse __paramx variables (I've sent a note to Bean about this with a suggested compiler update).

    Okay, I'm done; I hope someone finds this useful.

    [noparse][[/noparse]Edit] Fixed bug in TX_DEC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA

    Post Edited (JonnyMac) : 5/20/2010 3:33:31 PM GMT
  • VonSzarvasVonSzarvas Posts: 3,523
    edited 2010-05-19 17:56
    JonnyMac: Your work and efforts to help are outstanding and generous. I hope your afore mentioned matter of worry has started to alleviate itself. If TX code was a treadmill, I reckon you've run a few extra miles today to take your mind off things.

    The TX_HEX routine is helping me debug my SD-CARD reader/writer in PropBasic - without it I was really struggling to debug and fathom the protocol. Looking forward to sharing the code soon. Gonna be a late night....
  • RsadeikaRsadeika Posts: 3,837
    edited 2010-05-19 18:26
    @Maxwin, maybe you should start a PropBASIC SDCard thread? I was wondering how long it would take for somebody to do the code. Maybe you could give a general outline of your project. Like how many lines of code did it take? Sounds interesting I am sure other people would be interested in your project.

    Ray
  • VonSzarvasVonSzarvas Posts: 3,523
    edited 2010-05-19 18:57
    Rsadeika: I am working through the basics.... So far I can read/write and erase - I do intend to start a new thread soon (read 2-3 days) to share the code and hopefully get some feedback/testing.

    I had read your earlier thread, and so I would just mention I am not working on FATxx; rather direct storage much like a portable big cheap eeprom.

    For analysis I have written some c# .NET code to read into Windows the data (direct from the PhysicalDisc), so it's not needed the FAT overhead (in my case). .. Heck - you can also use WinHex or the like for occasional data grabbing anyhow!
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-05-19 19:09
    Maxwin said...
    JonnyMac: Your work and efforts to help are outstanding and generous. I hope your afore mentioned matter of worry has started to alleviate itself. If TX code was a treadmill, I reckon you've run a few extra miles today to take your mind off things.

    The TX_HEX routine is helping me debug my SD-CARD reader/writer in PropBasic - without it I was really struggling to debug and fathom the protocol. Looking forward to sharing the code soon. Gonna be a late night....

    Don't sell me as "generous" too quickly -- we're all motivated by something and my "something" will reveal itself in a few months! tongue.gif

    The matter did resolve; my mother required surgery for cancer and it all went very well -- she'll be fine. It's tough being in Los Angeles when she's in Anchorage, AK. Thankfully, my sister is there and keeps me up to date.

    I don't have a treadmill but I do like to walk and jog; after I posted the update I walked down to the Warner Brothers movie studio (about 2.5 miles) and then jogged back. Now it's time to tackle a big work project!

    I, too, am looking forward to seeing your SD card code. I've actually asked Parallax for an "official" SD card object to go along with their video output, audio output, keyboard and mouse input -- the only thing missing is file storage. FSRW (Spin/PASM) works very well, but is not full-featured (no file rename, no sub-directories) and I'd like to have these things.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-05-20 15:36
    Whoops... found a bug in TX_DEC. I got lucky in testing yesterday because an uninitialized variable (dcNegX -- flag for when value is NEGX) was doing what the code wanted; today it didn't and I found it. This flag is now pre-initialized to false and the code works as desired. New TX_FORMAT_INC.PBAS file is attached above.

    Good news: I was speaking with Bean yesterday and asked him about integrating the definitions and sub/func code into one file (for LOAD); he was already working on an idea and seems to have made it work so, perhaps in a day or two, libraries like this will be contained in a single file and that will be good for all of us when sharing code. Will be good, too, if some sort of PropBASIC repository is created.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • BeanBean Posts: 8,129
    edited 2010-05-20 16:23
    Jon,
    Yeah, basically just combine the two files into one with a '{$CODE} line seperating the header and code sections.

    I haven't tried it for TASKs yet, but it should work the same way.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-05-20 17:23
    Three cheers for Bean!· I folded my two library files together, inserted the '{$CODE} tag were required, and now there is only one LOAD statement in the program -- and only one library file to keep updated.· Excellent!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • simonlsimonl Posts: 866
    edited 2010-06-11 08:45
    Hey, thanks for this Jon, and three cheers for Bean & PropBASIC - just awesome smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,
    Simon

    www.norfolkhelicopterclub.com

    Announcement: To cut costs in the current economic climate, we have switched-off the light at the end of the tunnel.
Sign In or Register to comment.