News:

  • July 27, 2026, 09:04:51 AM

Login with username, password and session length

Author Topic: Strings and ascii encoding  (Read 35528 times)

fluidpowerman

  • Full Member
  • ***
  • Posts: 21
Re: Strings and ascii encoding
« Reply #15 on: July 09, 2013, 05:51:29 PM »
I am trying to do something similar using a C-more HMI to DO-more to Kepdirect and out to Datanet to create a data base that I can print forms etc.  I want to be able to enter a number of Text/number entry fields (ASCII Strings)ie. Customer Name, customer address, Job number etc. I have no problem going from ASCII to SS memory in the Do-More, but converting the SS memory to DLV memory that I can use with KEPTDIRECT.....oh boy. I am somewhat familiar with the STRGETB, however the number of characters in each field can vary, I'm not sure how to structure my code.   Does anyone know if there is a sample program or an easier what to do this.

I really appreciate any help and input

Thank you
Bryan :)

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3622
  • Darth Ladder
Re: Strings and ascii encoding
« Reply #16 on: July 09, 2013, 06:32:05 PM »
For variable length strings, you can prefill the target string with nulls or spaces before writing your real string.  Then either your HMI will be smart enough to see the first null or space and stop displaying or else it will just "display" them as blank space.  That usually works fine, or you might need to terminate the strings with an 0x0D, 0x0A or both.  Look at STRTRIM and STRFIND.  Those may be of use to you.  STRTRIM doesn't trim nulls at the moment, but will from v1.1 I believe.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

plcnut

  • Hero Member
  • *****
  • Posts: 814
    • premiersi.com
Re: Strings and ascii encoding
« Reply #17 on: July 09, 2013, 07:20:15 PM »
You can check the string length with SS0.length etc. and be able to know how many characters/bytes you are dealing with.
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
http://premiersi.com

CReese

  • Hero Member
  • *****
  • Posts: 184
Re: Strings and ascii encoding
« Reply #18 on: July 10, 2013, 10:34:42 AM »
Short answer is that it is not a lot of fun.

If you have strings of length N in a string field:

Set up a target ascii converted block, e.g. 'stringascii'. Make it type signed word. It will need to be of length N/2 words.

Clear out the ascii target using SETNUMR with 0 value.

STRGETB your string into your ascii block.

If you need to reverse ascii (as I did for my HMI), you can publish using reverse bytes to an MHR register, or SWAPB to reverse the bytes in each word.

I iterated over this with a loop to convert a long string block into a long word block, and then just pointed my HMI to the correct offsets (N/2 for each string) in the MHR registers.

HTH,
C

fluidpowerman

  • Full Member
  • ***
  • Posts: 21
Re: Strings and ascii encoding
« Reply #19 on: July 10, 2013, 02:27:28 PM »
Thanks for the input.....I will give it a shot.