ConvertSequenceData

<< Click to Display Table of Contents >>

Navigation:  Reference (Scripting) > Docklight Script Commands - The DL Object > Methods (Advanced) >

ConvertSequenceData

Converts Sequence data to/from a float number, an integer number, or other common types of data in technical applications.

 

Return Value

 

String

 

Syntax

 

result = DL.ConvertSequenceData( conversionType, source, [, representation] [, bigEndian ] )

 

The ConvertSequenceData method syntax has these parts:

 

Part

Description

conversionType

Required. String that specifies the conversion type and direction.
See below for the list of conversions and examples.

source

Required. Input data string for the conversion. This can be a Docklight Sequence, e.g. "4B 06 9E 3F", or a string with the application value, e.g. "1.234567". See below for details.

representation

Optional. Format of the sequence string (either source or result, depending on conversionType):

"H" = Hex (default), "D" = Decimal or "B" = Binary.

bigEndian

Optional. Boolean value to define the byte order for integer or float conversions.

True (default): Use big-endian byte order (first character is most significant)

False: use little-endian byte order (first character is least significant)

 

The conversionType argument supports the following values and types of conversions:

 

Value

Description

"toSingle"

Convert source to a single precision float number.

source: IEEE single precision (32 bit) sequence

result: string with floating point number in non-localized format, uses period (".") as the decimal separator.

Example:

DL.ConvertSequenceData("toSingle", "3F 9E 06 4B")

returns: 1.234567

"fromSingle"

Convert source to a IEEE single precision (32 bit) sequence

source: string with floating point number. Both period (".") and comma (",") are accepted as decimal separator.

result: 32 bit sequence data

Example:

DL.ConvertSequenceData("fromSingle", "1.234567")

returns: 3F 9E 06 4B

"toDouble"

Convert source to a double precision float number.

source: IEEE double precision (64 bit) sequence

result: string with floating point number in non-localized format (see above)

Example:

DL.ConvertSequenceData("toDouble", "103 154 149 160 081 161 036 075", "D", False)

returns: 9.87987987987E+53

"fromDouble"

Convert to a IEEE double precision (64 bit) sequence

source: string with floating point number. Both period (".") and comma (",") are accepted as decimal separator.

result: 64 bit sequence data

Example:

DL.ConvertSequenceData("fromDouble", "9.87987987987E+53", "D", False)

returns: 103 154 149 160 081 161 036 075

"fromText"

Converts a plain text into a Hex, Decimal or Binary sequence.

E.g.

DL.AddComment DL.ConvertSequenceData("fromText", "Hello World")

returns: 48 65 6C 6C 6F 20 57 6F 72 6C 64

 

bigEndian = false: If this option is used for "fromText", the resulting sequence is without separator, e.g. 48656C6C6F20576F726C64

"toInteger16"

"fromInteger16"

Convert to/from a signed 16 bit integer value

Examples:

DL.ConvertSequenceData("toInteger16", "80 00")

returns: -32768
DL.ConvertSequenceData("fromInteger16", "-1")

returns: FF FF

"toUnsigned16"

"fromUnsigned16"

Same as "toInteger16" / "fromInteger16", but for unsigned 16 bit integer data

Examples:

DL.ConvertSequenceData("toUnsigned16", "80 00")

returns: 32768
DL.ConvertSequenceData("fromUnsigned16", "65535", "D")

returns: 255 255

"toInteger32"

"fromInteger32"

Convert to/from a signed 32 bit integer value

Examples:

DL.ConvertSequenceData("toInteger32", "00 00 00 80", "H", False)

returns: -2147483648
DL.ConvertSequenceData("fromInteger32", "-2", "H", False)

returns: FE FF FF FF

"toUnsigned32"

"fromUnsigned32"

Same as "toInteger32" / "fromInteger32", but for unsigned 32 bit integer data

Examples:

DL.ConvertSequenceData("toUnsigned32", "FF 00 FF 00")

returns: 4278255360
DL.ConvertSequenceData("fromUnsigned32", "21121977", "D")

returns: 001 066 075 185

"toBool"

Returns "True" if the first source character is <> 0

Example:

DL.ConvertSequenceData("toBool", "00")

returns: False

DL.ConvertSequenceData("toBool", "01 00")

returns: True

"toText"

Converts sequence data into a text string with printing characters only (see ASCII Character Set). ASCII code 0 - 31 and 127 - 255 are filtered out and do not appear in the result.

source: sequence with the original data, including non-printing character codes

result: the ASCII text using only ASCII code 32 - 126  

Example:

DL.ConvertSequenceData("toText", "FF 48 65 6C 6C 6F 21 0D 00 00")

returns: Hello!

 

Remarks

 

Carefully check your protocol specification on the data format, including Endianness (little endian / big endian).

 

When using the result of a "toSingle" or "toDouble" conversion for further calculations, keep in mind that result can be a non-numeric strings like "NaN" (not a number) or "Inf" (Infinity).

 

Note that "toText" is not the same as reading out a data sequence in ASCII representation ("A"). Example:

 

DL.AddComment DL.OnSend_GetData("A")

DL.AddComment DL.ConvertSequenceData("toText", DL.OnSend_GetData("H"))

 

could return the following:

 

Hello!<CR><NUL><NUL>

Hello!