News:

  • July 04, 2026, 07:04:42 AM

Login with username, password and session length

Author Topic: Converting an ASCII String charecter to binary.  (Read 11157 times)

Bobby

  • Sr. Member
  • ****
  • Posts: 60
Converting an ASCII String charecter to binary.
« 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!

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3833
    • Host Engineering
Re: Converting an ASCII String charecter to binary.
« Reply #1 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.

Bobby

  • Sr. Member
  • ****
  • Posts: 60
Re: Converting an ASCII String charecter to binary.
« Reply #2 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.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3833
    • Host Engineering
Re: Converting an ASCII String charecter to binary.
« Reply #3 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.
« Last Edit: September 11, 2015, 03:11:38 PM by franji1 »

MikeS

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 265
    • Host Engineering, Inc.
Re: Converting an ASCII String charecter to binary.
« Reply #4 on: September 11, 2015, 03:04:49 PM »
i think you mean STRGETB - Get Bytes Out of a String instead of STRPUTB.
Good design costs a lot. Bad design costs even more.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3833
    • Host Engineering
Re: Converting an ASCII String charecter to binary.
« Reply #5 on: September 11, 2015, 03:11:51 PM »
i think you mean STRGETB - Get Bytes Out of a String instead of STRPUTB.
Doh!

Bobby

  • Sr. Member
  • ****
  • Posts: 60
Re: Converting an ASCII String charecter to binary.
« Reply #6 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!