Component: Type Conversions (Storage)

From Flowcode Help
Jump to navigationJump to search


Author Matrix TSL
Version 1.0 (Release)
Category Storage


Image Type Conversions component

Component to simplify the task of converting data into different bit type variables. Allows conversion between Bytes, Ints, Longs and Floats. Useful when you need to store Ints, Longs and Floats into Byte based memory. Uses a simple 32-bit C Union to overlay the following variable types into the same RAM space. Byte[4], Int[2], Long, Float Please note float conversion does not currently simulate.

Examples

The type conversion component is aimed at allowing for simple, relible and efficient ways of converting between 8-bit, 16-bit and 32-bit values.

The component consists of a single 32-bit block of memory that consists of the following data types which are all overlaid on each other.

4 x 8-bit Bytes

2 x 16-bit INTs

1 x 32-bit Long

1 x 32-bit Float


For communications systems you may need to send or receive data as bytes.

So to pack up a float into bytes you would load a floating point value and then collect the 4 bytes.

To repack the floating point value at the other end you would load the 4 bytes and then collect the floating point value.


Here is a simple project showing how to convert between bytes, ints, longs and floats.

FC6 Icon.png Type Conversions Exmple

Downloadable macro reference

SetInt

Sets a single 16-bit INT value.

Index is in little endian, 0 is the LSW and 1 is the MSW

Parameters

BYTE Index
Range: 0-1
UINT Value
Range: 0-65535


Return value

This call does not return a value


SetLong

Sets a single 32-bit LONG value

Parameters

ULONG Value
Range: 0-4294967295


Return value

This call does not return a value


GetFloat

Gets a single 32-bit FLOAT value

Parameters

This macro has no parameters


Return value

FLOAT


GetLong

Gets a single 32-bit LONG value

Parameters

This macro has no parameters


Return value

ULONG


GetInt

Gets a single 16-bit INT value

Index is in little endian, 0 is the LSW and 1 is the MSW

Parameters

BYTE Index
Range: 0-1


Return value

UINT


SetByte

Sets a single 8-bit BYTE value

Index is in little endian, 0 is the LSB and 3 is the MSB

Parameters

BYTE Index
Range: 0-3
BYTE Value
Range: 0-255


Return value

This call does not return a value


GetByte

Gets a single 8-bit BYTE value.

Index is in little endian, 0 is the LSB and 3 is the MSB

Parameters

BYTE Index
Range: 0-3


Return value

BYTE


SetFloat

Sets a single 32-bit FLOAT value

Parameters

FLOAT Value
Range: 0-4294967295


Return value

This call does not return a value


Simulation macro reference

This component does not contain any simulation macros


Property reference

This component does not contain any properties