HEXSTR_TO_DATA
The function converts a hexadecimal string into binary data and returns the number of successfully converted data bytes as result. Only spaces may be used as separators in the hexadecimal string to be converted. Lower and upper case letters are permitted as hex characters. In the event of an error or an illegal character the conversion is aborted and a zero length is returned as result.
FUNCTION HEXSTR_TO_DATA : UDINT
VAR_INPUT
sHex : T_MaxString;
pData : DWORD;
cbData : UDINT;
END_VAR
sHex: The hexadecimal string to be converted. E.g.: 'AB CD 01 23'
pData: Start address (pointer) to the target buffer into which the converted data bytes are to be written. The address can be determined with the ADR operator.
cbData: Max. available length of the target buffer. The length can be determined with the SIZEOF operator.
Example in ST:
PROGRAM MAIN
VAR
sH : STRING := 'AB CD EF 01 23 45 67 89';
data : ARRAY[0..10] OF BYTE;
cbData : UDINT;
END_VAR
cbData := HEXSTR_TO_DATA( sH, ADR( data ), SIZEOF( data ) );
The result (online):
Requirements
Development environment | Target platform | PLC libraries to be linked |
---|---|---|
TwinCAT v2.10.0 Build >= 1334 | PC or CX (x86, ARM) | TcUtilities.Lib |