Find The Needle Add My Company
TechTip: Using StringCat in a Macro on Weintek HMI

This TechTip is about using “StringCat” in a Weintek HMI macro. You may already be familiar with using CONCAT in Microsoft Excel to link different text strings together to form a new string, this is what StringCat does. In this example, we’ll be looking at a scenario where a number needs to be joined to a 4 character ASCII string. For example “number “+ “text” = “outputstring”. i.e. 1234+ABCD = 1234ABCD First off, we’ll declare the variables, we have “number” (which we’ll get from an HMI LW register LW0), “text” which we’ll get from LW2 (2 words – 4 characters) and the result will end up in “outputstring”. macro_command main() // Declare variables short number // Declare the number variable char text[4] // Declare the text suffix variable char outputstring[8] // Declare the destination string next… we’ll clear “outputstring” – this is important because if we enter “1234” + “ABCD” and do not clear “outputstring” we may end up with 12ABDCDC if we enter “12” + “ABCD”: FILL(outputstring[0], 0, 4) // clear outputstring SetData(outputstring[0], “Local HMI”, LW, 100, 10) // Clear LW100 Get the ASCII input and put it in “text”: GetDataEx(text[0], “Local HMI”, LW, 2, 4) // Get the ASCII input from LW2 Get the Numeric input and put it in “number”: GetData(number, “Local HMI”, LW, 0, 1) // Get “number” input from LW100 The number is in binary (BIN) format Convert so needs converting so our resulting string is ASCII: StringBin2DecAsc(number, outputstring[0]) // Convert “number” to ascii and put in “outputstring” This is where we use StringCat to join “text” and “outputstring”(which at the moment contains the number, converted to ASCII) StringCat(text[0],outputstring[0]) // Concatenate text and “outputstring”  so outputstring is ####TEXT Finally, we set LW100 with the string that we have generated in “outputstring”: SetData(outputstring[0], “Local HMI”, LW, 100, 10) // Put the concatenated result “outputstring” into LW100 end macro_command All together this should look like this: There is an example program for you to download here.

For more information on TechTip: Using StringCat in a Macro on Weintek HMI talk to Lamonde Automation Ltd

Enquire Now

  Please wait...

Location for : Listing Title