PDA

View Full Version : PropBasic: TX_BIN, TX_DEC, TX_HEX



Maxwin
05-18-2010, 05:39 PM
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

JonnyMac
05-18-2010, 09:49 PM
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.

[Edit] #1: Added TX_DEC

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

[Edit] #3: See below

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

Post Edited (JonnyMac) : 5/19/2010 5:31:09 PM GMT

Maxwin
05-18-2010, 11:26 PM
THANK YOU JonnyMac !


I have also updated the title of this post to reflect the TX_BIN routine included in your sample code.

JonnyMac
05-18-2010, 11:47 PM
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

JonnyMac
05-20-2010, 01:35 AM
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.

[Edit] Fixed bug in TX_DEC

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

Post Edited (JonnyMac) : 5/20/2010 3:33:31 PM GMT

Maxwin
05-20-2010, 01:56 AM
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....

Rsadeika
05-20-2010, 02:26 AM
@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

Maxwin
05-20-2010, 02:57 AM
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!

JonnyMac
05-20-2010, 03:09 AM
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! http://forums.parallax.com/images/smilies/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

JonnyMac
05-20-2010, 11:36 PM
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

Bean
05-21-2010, 12:23 AM
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. [RUSH - Freewill]

JonnyMac
05-21-2010, 01:23 AM
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

simonl
06-11-2010, 04:45 PM
Hey, thanks for this Jon, and three cheers for Bean & PropBASIC - just awesome http://forums.parallax.com/images/smilies/smile.gif

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

www.norfolkhelicopterclub.com (http://www.norfolkhelicopterclub.com)

Announcement: To cut costs in the current economic climate, we have switched-off the light at the end of the tunnel.