Find The Needle Add My Company
TechTip: Using HIWORD/LOWORD & HIBYTE/LOBYTE in a macro on Weintek HMI

The Weintek Macro language has a some useful functions for stripping 32bit and 16bit numbers into words, and bytes. In this macro example, we’re splitting a 32bit word into a 16bit “HIWORD” and a 16bit “LOWORD“, and splitting the two resulting words into four bytes. The syntax for HIWORD, LOWORD, HIBYTE & LOBYTE is the same format – FUNCTION(source, destination): HIWORD(source, destination) LOWORD(source, destination) HIBYTE(source, destination) LOBYTE(source, destination) The Macro is carrying out the operation shown below, starting off with a 32bit value. 32bit binary: aaaaaaaabbbbbbbbccccccccdddddddd HIWORD: aaaaaaaabbbbbbbb LOWORD: ccccccccdddddddd HIBYTE (1): aaaaaaaa LOBYTE (1): bbbbbbbb HIBYTE (2): cccccccc LOBYTE (2): dddddddd macro_command main() int inword = 0 // inword is 32 bit short hword = 0 // hword is 16bit for use with HIWORD short lword = 0 // lword is 16bit for use with LOWORD short a = 0 // a is 16bit for the HIBYTE of HIWORD short b = 0 // b is 16bit for the LOBYTE of HIWORD short c = 0 // c is 16bit for the HIBYTE of LOWORD short d = 0 // d is 16bit for the LOBYTE of LOWORD GetData(inword, "Local HMI", LW, 0, 1) // get 32bit value inword from LW 0 // Syntax HIWORD(source, destination) HIWORD(inword, hword) // put upper 16bits of 32bit inword in hword LOWORD(inword, lword) // put lower 16bits of 32bit inword in lword // Syntax HIBYTE(source, destination) HIBYTE(hword, a) // put HIBYTE of the HIWORD, hword and put in a LOBYTE(hword, b) // put LOBYTE of the HIWORD, hword and put in b // Syntax HIBYTE(source, destination) HIBYTE(lword, c) // put HIBYTE of the LOWORD, lword and put in c LOBYTE(lword, d) // put LOBYTE of the LOWORD, lword and put in d SetData(a, "Local HMI", LW, 10, 1) // set LW 10 with value a SetData(b, "Local HMI", LW, 11, 1) // set LW 11 with value b SetData(c, "Local HMI", LW, 12, 1) // set LW 12 with value c SetData(d, "Local HMI", LW, 13, 1) // set LW 13 with value d end macro_command We have a demo project to download here.

For more information on TechTip: Using HIWORD/LOWORD & HIBYTE/LOBYTE in a macro on Weintek HMI talk to Lamonde Automation Ltd

Enquire Now

  Please wait...

Location for : Listing Title