Help with string arrays
mdsteen
Posts: 8
Hello all,
Been reading these forums for a while now, but this is my first post.
I need help. I'm developing this code for a tester for a Sensotech DS depth transducer. I have attached the code thus far. My problem is that I am having trouble converting my incoming scientific notation into PSI. To do this I have the scientific notation coming in from the depth transducer as a string array, and I am having trouble manipulating the data after I receive it. More specifically I can't seem to be able to add a variable -- labeled upper -- to the string array -- lowerStr. Is this even possible? or is there a better way to go about this.
Any help would be much appreciated.
Thanks,
mdsteen
Been reading these forums for a while now, but this is my first post.
I need help. I'm developing this code for a tester for a Sensotech DS depth transducer. I have attached the code thus far. My problem is that I am having trouble converting my incoming scientific notation into PSI. To do this I have the scientific notation coming in from the depth transducer as a string array, and I am having trouble manipulating the data after I receive it. More specifically I can't seem to be able to add a variable -- labeled upper -- to the string array -- lowerStr. Is this even possible? or is there a better way to go about this.
Any help would be much appreciated.
Thanks,
mdsteen
bs2
2K
Comments
Looks like you're on the right track. However, you need to add one step which is converting the string representation of the digit into a number.
A couple of techniques are:
1. use the DEC formatters to receive the data from the depth transducer directly in number format.
2. write a subroutine that can look at the string version of the number, for example the character "3", and convert it to the digit 3. Basically, if the character is "3", then the value becomes 3, which is different from the ASCII representation of "3".
This is part of the reason your "upper" and "lower" don't appear to work. They're working with the ASCII values of the string representations, not numbers.
On a related topic, your SERIN might be a bit more reliable if you could use the WAIT parameter to make sure you're always grabbing the right set of 12 characters.
Cheers,
Tom Sisk
So, first you have to convert your numeric String into a number of some description. If it's scientific notation, then a floating point number would be nice -- but I don't think the BS2 does floats.
Does anyone have any ideas how to effectivly implament the above suggestion of converting my string into decimal numbers?
Thanks again,
mdsteen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
--mdsteen
http://forums.parallax.com/showthread.php?p=545173
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Second will implamenting an ASCII lookup table to convert my ASCII values to decimal values be the most efficiant way to go here?
-mdsteen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
My incoming data stream looks like this: +1.12345E+12 -- just scientific notation. I am bringing it in via a 13 byte string array (where the 13th byte is set to 0). I want to convert the ASCII values into decimal numbers so I can manipulate them later on in the code. I have attached my thus far working code to show what I am doing.
--mdsteen
ASCII Table Chart
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 8/9/2005 9:01:56 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Would using the Lookdown and Lookup commands be able to convert my ASCII to decimal, something like this:
-mdsteen
I gather you are keeping the numerical value in memory for manipulations of the number. Since it is in scientific notation, I assume you'll be storing each digit into a seperate memory location (like you are doing with your xdcrSTR). To save memory space, consider storing that data into an array of nibbles (NIB) since 4 bits can represent a single digit (0-9). This way the number will take up half the space of the ASCII representation, which requires 8 bits per character. You can do the conversion on the fly so you don't need to store the ASCII value.
Heres a code sample (which assumes the data is formatted as +1.12345E+12):
You can structure the program the way you want, such as having seperate variables for the mantissa and exponent, this is only meant as an example.
You can see that instead of needing 12 bytes of space to hold the actual data, you only need 4 bytes (8 nibs) and 2 bits.
You didnt specify exactly how you are receiving the data, this code assumes you can get successive digits seperately (this should work if you are SHIFTINing the data, if you are SERINing the data, this approach of getting each digit seperately may not work).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 8/10/2005 9:01:44 PM GMT
Thanks for all of the fantastic help, this was my first big stamp coding project. I got the code working just this morning. My boss likes the results. Now on to my next stamp project for him -- a Battery Tester / Load Tester. Should be fun and interesting. I'm sure I'l be back on these forums looking for assistance, but this next project should be a lot easier, since we're using A/D to bring in the data.
Till next time,
-mdsteen