HEXSTR_TO_DATA

HEXSTR_TO_DATA 1:

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.

HEXSTR_TO_DATA 2: Return value

Name

Type

Description

HEXSTR_TO_DATA

UDINT

 

HEXSTR_TO_DATA 3: Inputs

VAR_INPUT
    sHex   : T_MaxString;
    pData  : POINTER TO BYTE;
    cbData : UDINT;
END_VAR

Name

Type

Description

sHex

T_MaxString

The hexadecimal string to be converted (type: T_MaxString, e.g.: ‘AB CD 01 23’ ).

pData

POINTER TO BYTE

Start address (pointer) to the destination buffer into which the converted data bytes are to be written. The address can be determined with the ADR operator.

cbData

UDINT

Max. available length of the destination buffer. The length can be determined with the SIZEOF operator.

Example:

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):

HEXSTR_TO_DATA 4:

Requirements

Development environment

Target platform

PLC libraries to be integrated (category group)

TwinCAT v3.1.0

PC or CX (x86, x64, Arm®)

Tc2_Utilities (System)