Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Bobby on September 11, 2015, 08:35:27 AM

Title: Converting an ASCII String charecter to binary.
Post by: Bobby on September 11, 2015, 08:35:27 AM
Good morning all!

I am using a Mettler Toledo PS Series scale and communicating via rs232. The scale sends a status bit back to me in ASCII text, for example they send me an "a". What I need to do then is convert that "a" into binary with each binary bit then being a status bit for the scale. So for "a" being "01100001" I would look at each number in that binary structure and depending on which one is a "1" or a "0" would give me info such as scale in motion, or scale ready.

I just cannot for the life of me find a way to get this conversion to actually work! Any help would be appreciated!
Title: Re: Converting an ASCII String charecter to binary.
Post by: franji1 on September 11, 2015, 10:17:46 AM
Do you have the data already in a Do-more STRING or in a Numeric Buffer of some sort?  i.e. you already have your STREAMIN working and have the data from the scale within a Do-more memory element?

If so, where is it (a STRING, e.g. SS0, or a byte/numeric buffer, e.g. buffer starting at V2000...)?  This is the "Data Destination" parameter in your STREAMIN instruction.
Title: Re: Converting an ASCII String charecter to binary.
Post by: Bobby on September 11, 2015, 01:43:18 PM
Do you have the data already in a Do-more STRING or in a Numeric Buffer of some sort?  i.e. you already have your STREAMIN working and have the data from the scale within a Do-more memory element?

If so, where is it (a STRING, e.g. SS0, or a byte/numeric buffer, e.g. buffer starting at V2000...)?  This is the "Data Destination" parameter in your STREAMIN instruction.

I currently have the data streamin and stored into a SS value then I strip off some leading edge stuff with the STRSUB instruction leaving only the ASCII letter in question.
Title: Re: Converting an ASCII String charecter to binary.
Post by: franji1 on September 11, 2015, 01:49:05 PM
I currently have the data streamin and stored into a SS value then I strip off some leading edge stuff with the STRSUB instruction leaving only the ASCII letter in question.
PERFECT!

Use STRPUTB STRGETB (what Mike said) to put GET the 1 character string and put it into a packed BYTE of C Bits (it must be aligned on a BYTE boundary), e.g.
C32:UB (C32-C39 as an UNSIGNED BYTE).

Now, you can easily address C32 thru C39 as individual bits, representing the 8 state values.  C32 will be the Least Significant Bit, and C39 will be the High bit.
Title: Re: Converting an ASCII String charecter to binary.
Post by: MikeS on September 11, 2015, 03:04:49 PM
i think you mean STRGETB - Get Bytes Out of a String instead of STRPUTB.
Title: Re: Converting an ASCII String charecter to binary.
Post by: franji1 on September 11, 2015, 03:11:51 PM
i think you mean STRGETB - Get Bytes Out of a String instead of STRPUTB.
Doh!
Title: Re: Converting an ASCII String charecter to binary.
Post by: Bobby on September 16, 2015, 01:37:39 PM
Thank you both!! PLC is still kinda new to me and both the Do-More software and these forums are really making is much easier!