Do-more Technical Training Instruction Set (String)
Instruction Set THE BASICS ▫1▫181 instructions CContact (14) CCoil/Bit Output (11) AAnalog/Process (13) DDate/Time/Calendar (7) EEthernet (5) HHardware/Device (9) HHigh Speed/CTRIO (19) MMath (5) MMisc/Data Manipulation (23) PProgram Control (20) PProgram-Looping (8) PProtocol-Custom/ASCII (7) PProtocol-Standard (10) SString (14) TTimer/Counter/Drum (16)
String ▫STR2INT ▫STR2REAL ▫STRCASE ▫STRCLEAR ▫STRCMP ▫STRDELETE ▫STRFIND ▫STRGETB ▫STRINSERT ▫STRPRINT ▫STRPUTB ▫STRSUB ▫STRTRIM ▫STRTRUNC Instruction Set (String)
STR2INT “Convert String to Integer” ▫C▫Converts ASCII digits to integer value ▫P▫Parameters: IInput String – string to be converted IInput Radix – determines valid characters DDecimal (base 10): characters “0-9” HHexadecimal (base 16): characters “0-F” OOctal (base 8): characters “0-7” IImplied Base: characters “0x” (hex), “0” (octal), “1-9”(decimal) OOther (2-36): e.g. 36 would validate characters “0-Z” NNumeric Output – location of converted value IIndex Where Stopped – character location in string ▫N▫NOTES: IIf Input String is empty then Index Where Stopped = -1; ERR = “STR2INT input string is empty” IIf Input String contains invalid characters then Index Where Stopped = -1; ERR = “STR2INT input string couldn’t be converted to an integer value”
STR2REAL “Convert String to Real” ▫C▫Converts ASCII digits to real value ▫P▫Parameters: IInput String – string to be converted NNumeric Output – location of converted value IIndex Where Stopped – character location in string ▫N▫NOTES: VValid characters are: “ E+-” IIf Input String is empty then Index Where Stopped = -1; ERR = “STR2REAL input string is empty” IIf Input String contains invalid characters then Index Where Stopped = -1; ERR = “STR2REAL input string couldn’t be converted to an integer value”
STRCASE “Convert String to UPPER/lower Case” ▫C▫Converts all characters in a string to either upper case or lower case letters ▫P▫Parameters: IInput/Output String – string to be converted CConvert to: aall lower case AALL UPPER CASE ▫N▫NOTES: VValid characters are only alphabetic letters IIf character is not alphabetic, no change occurs to that character SS0abcd!EFgH abcd!efgh LowLow ABCD!EFGH UpUp
Instruction Set (String) STRCLEAR “Clear Strings” ▫D▫Deletes all characters from a single string or a range of strings ▫P▫Parameters: SStart String – 1 st (or only) string to be cleared NNumber of Strings to Clear – 1 to (or variable) ▫N▫NOTES: TThe Status display will only show as many characters that fit in its borders (about 50 characters)
STRCMP “String Compare” ▫C▫Compares two strings to determine if they are equal, less than or greater than ▫L▫Less than & greater than values are determined by the ASCII byte values ▫E▫Each byte position is compared until: BByte values don’t match with one value > or < EEnd of one string reached 1 st meaning it is < EEnd of both strings reached simultaneously meaning equality ▫P▫Parameters: FFirst String CCase Sensitive: YYes, upper/lower case are different NNo, upper/lower case are equal SSet If Equal (optional) SSet If Less Than (optional) SSet If Greater Than (optional) SSecond String or Text – the 2 nd string can be a literal text in quotes IInput Leg: EEdge triggered PPower flow enabled SS0abcd!EFgH SS1abcd!EFgH Yes, upper/lower case are different SS0 = SS1SS0 < SS1SS0 > SS1 YES No, upper/lower case are equal YES SS0abcd!EFgH SS1abcd!E Yes, upper/lower case are different SS0 = SS1SS0 < SS1SS0 > SS1 YES No, upper/lower case are equal YES SS0abcd!EFgH SS1abcd!eF Yes, upper/lower case are different SS0 = SS1SS0 < SS1SS0 > SS1 YES No, upper/lower case are equal YES E = 45 hex e = 65 hex SS0’s E is < SS1’s e SS0’s E & SS1’s e are equal in value & SS0 is longer
Instruction Set (String) STRDELETE “Delete Substring” ▫D▫Deletes characters from a string ▫T▫Trailing characters are shifted to take the place of deleted ones ▫P▫Parameters: IInput / Output String SStarting at Offset: 0 – 1023 (or variable) TThe 1 st character is 0 (zero) NNumber of Characters to Delete SS0abcd!EFgH To delete the ! character: Starting at Offset = 4 Number of Characters to Delete = SS0abcdEFgH
Instruction Set (String) STRFIND “Find within String” ▫S▫Search a target string for a particular string ▫I▫If successful the where-found offset could be used in STRSUB, STRDELETE or STRINSERT instructions ▫P▫Parameters: FFind within – string in which to search SSearch from: BBeginning to end EEnd to beginning CCase Sensitive: YYes, upper/lower case are different NNo, upper/lower case are equal IIn Offset: Start / Out Offset: Where Found – will contain -1 if nothing is found SSet if found (optional) SSet if NOT found (optional) FFind Text/String: EExact sequence AAny one of these characters – text box IInput Leg: EEdge triggered / Power flow enabled SS0abceEEFgH To find the E character: Search from: Beginning to end Case Sensitive: Yes Find Text/String: Any one of these characters: “E”
Instruction Set (String) STRPUTB “Put Bytes Into a String” ▫P▫Puts bytes of data from a specified location range into a string ▫P▫Parameters: PPut Into String – string that will contain data bytes SStart at Index – 1 st location in the string for the bytes LLength in Bytes – number of bytes to write into string FFrom Starting Element – 1 st location to read bytes <<Create Byte Buffer> button – convenient way to create a Memory Block of bytes (shows up in Memory Configuration) ▫N▫NOTES: NNot intended to operate on strings with ASCII text
STRGETB “Get Bytes Out of a String” ▫E▫Extracts bytes of data out of a string & stores them in specified location ▫P▫Parameters: GGet out of String – string with data bytes SStart at Index – 1 st location in the string for the bytes LLength in Bytes – number of bytes to copy IInto Starting Element – 1 st location to put extracted bytes <<Create Byte Buffer> button – convenient way to create a Memory Block of bytes (shows up in Memory Configuration) ▫N▫NOTES: NNot intended to operate on strings with ASCII text Values are manually written to a custom byte memory MyBuffer The STRPUTB writes the range MyBuffer10-13 into SS0 The STRGETB writes the bytes in SS0 to the range MyBuffer0-3 ASCII values of 10, 20, 30 are not displayable characters. 40 decimal ASCII is (.
Instruction Set (String) STRINSERT “Insert Substring” ▫I▫Inserts characters into a string ▫P▫Parameters: IInsert String or Text IInto String SStarting at Offset IIf > length of string, it is appended to string IIf > allowable size of the Into String, then: ▫T▫Text is appended to string ▫$▫$OutOfRange (ST132) = ON ▫E▫ERR = “Argument out of range in STRINSERT…” The text “not ” is to be inserted into SS0 starting at offset 12.
Instruction Set (String) STRPRINT “Print to String” ▫W▫Writes text & formatted data into a string ▫P▫Parameters: PPrint to AAppend to String (optional) AAutomatically insert space after each term (optional) PPrint Script – text with optional embedded fields (text, control characters, strings, elements, formatting & string selection functions, raw data) – See next slide IInput Leg – Edge triggered / Power flow enabled
Instruction Set (Ethernet) STRPRINT “Print to String” ▫P▫Parameters: PPrint Script SString Literals – ASCII text in double quotes (e.g. “Hi!”) DData Elements – (e.g. “The current count is” CT0.Acc) CControl Characters ▫$▫$$ $ ▫$▫$” “ ▫$▫$L <LF> (line feed) ▫$▫$N <CR><LF> (carriage return, line feed) ▫$▫$P <FF> (form feed) ▫$▫$R <CR> (carriage return) ▫$▫$T <TAB> (tab) ▫$▫$hh hh (any one-byte hex value) FFormatting Functions [see Do-more Designer Help Topic DMD0168] ▫F▫FmtString – Sets length and/or justifies text within a string ▫F▫FmtBit – Formats bits’ values as a text instead of just 0 or 1 ▫F▫FmtInt – Formats how an integer is represented in a string ▫F▫FmtReal – Formats how real numbers are represented in a string ▫F▫FmtTMR – Formats how Timer Accumulator values are represented in a string ▫F▫FmtDate – Formats how a Date stamp is represented in a string ▫F▫FmtTime – Formats how a Time stamp is represented in a string ▫L▫Lookup – Selects a string in a list to represent a value ▫R▫Raw – Places bytes of data from a data block into a string
Instruction Set (String) STRSUB “Get Sub-String” ▫C▫Copies characters from one string to another ▫P▫Parameters: IInput String SStarting Offset OOffset From – Beginning / End LLength – variable or Remainder of input string OOutput String IInput Leg – Edge triggered / Power flow enabled
STRTRIM “Trim Whitespace” ▫R▫Removes all whitespace characters from the beginning and/or end of a string WWhat is “Whitespace”? SSpace (ASCII 20 hex) HHorizontal tab <TAB> (ASCII 09 hex) CCarriage return <CR> (ASCII 0D hex) LLine feed <LF> (ASCII 0A hex) FForm feed <FF> (ASCII 0C hex) VVertical tab <VT> (ASCII 0B hex) ▫P▫Parameters: SString TTrim LLeading (optional) TTrailing (optional)
STRTRUNC “Set String Length” ▫S▫Sets the length of a string ▫P▫Parameters: SString LLength IIf 0 (zero) or negative (-) clears string <empty string> IIf > string’s length then string is padded with nulls (0; not spaces) to reach the specified length IIf > string’s allowed length (e.g. >64 for SS, >256 for SL) then entire string is padded with nulls (0; not spaces) and… ▫$▫$BufferOverflow (ST140) = ON ▫E▫ERR: “Length was greater than max string length in STRTRUNC…”