Serial

Description of the Serial communication protocol and its implementation in the Typhoon HIL Toolchain.

Introduction

The Universal Asynchronous Receiver/Transmitter (UART) controller is the key component of the serial communications subsystem of a computer. The UART takes bytes of data and transmits the individual bits in a sequential fashion. At the destination, a second UART re-assembles the bits into complete bytes. Each UART contains a shift register, which is the fundamental method of conversion between serial and parallel forms. Serial transmission of digital information (bits) through a single wire or other medium is less costly than parallel transmission through multiple wires.

Communication may be simplex (in one direction only, with no provision for the receiving device to send information back to the transmitting device), full duplex (both devices send and receive at the same time) or half duplex (devices take turns transmitting and receiving).

Speed of UART is defined as baud rate. It is number of bits that can be transmitted in one second.

Serial component in Typhoon HIL tool chain

In Typhoon HIL schematic editor, Serial components could be found in the Serial folder under the Communication tab.

The Serial library consists of three components: Serial Setup, Serial Send, and Serial Receive.

Figure 1. Serial component location

Serial Setup component

Figure 2. Serial Setup Component

Serial Setup

The Setup component is the main component of Serial library. This component is used for basic Uart settings, like baud rate, parity, stop bits, etc.

The selected settings will apply for Serial Send and Serial Receive components. For example, if you choose baud rate 9600 bps, Serial Send component will send data at the 9600 bps baud rate, and Serial Receive component will read data at the baud rate 9600 bps, too. To reach these settings, double click on Serial Setup component in schematics editor. Dialog window should appear.

Figure 3. Serial Setup properties
Description Values
HIL Device ID ID of HIL Device whose setting you want to edit
Baud rate Number of bits per second.

0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600

Data bits Number of bits in one character transmitted by UART.
  • 6
  • 7
  • 8
Parity Type of parity bit generated after character bits, before stop bit.
  • None
  • Even
  • Odd
  • Mark
  • Space
Stop bits This property value defines how much stop bits will be attached to data frame.
  • 1
  • 2
UART rx DI pin This property value defines the digital input pin connected to the UART controller rx port on HIL402 devices only. This value corresponds to the UART tx port in HIL SCADA, which can be configured using either the HIL SCADA/Model Settings/Digital Outputs menu or by using the the Output Settings component in Schematic Editor.
  • 1 to
  • 32

Serial Send

This component is used to send messages from the HIL device to any attached device via UART. The input of this component is a vector, and this vector is defined by the component which is connected to the Serial Send component.

Figure 4. Serial Send component
The Component properties window will appear after double clicking on this component.
Figure 5. Serial Send component properties
Property Description Values
Byte order

Little endian or big endian. Specifies in which endianness data part will be formatted.

Note:

Header frame is parsed byte by byte, so byte order does not apply to it.

Example: 0x12345678 as big endian is the same as 0x78563412 in the little endian format.
Header

Start sequence of message frame.

Examples for this property are more detailed described below this table.

No header, hexadecimal numbers array, ASCII characters array

Sending period

Timing delay between two messages.

Input number is in milliseconds.

From 0 to 1000000 (1 million) milliseconds
Execution rate Rate of executing Signal Processing part of component (acquiring variables). Depends of execution rate of component which is Serial Send connected to. -

Message description

Message can be represented in two ways.

  1. Message that contains header part and data part.
  2. Message with only data part.

Message has not message end indicator.

Note:

Be careful with parsing data on your machine. Data type (float(real), uint, int) which will be sent is defined in component which is connected to Serial Send component.

Figure 6. Message with header
Figure 7. Message with only data values, no header

How to define message header

Empty text box: message will not contain header frame. Data will be sent as raw bytes. Raw bytes is mode where message contains only Data values.

Array of hexadecimal numbers: in this case, before hexadecimal numbers array, you have to write “0x”.

Figure 8. Examples of hexadecimal header parsing

Array of characters: allowed values (characters) are all which are defined in ASCII table.

Figure 9. Example of ASCII character array to hexadecimal array parsing

Serial Receive

Serial Receive component is used for reading messages which are sent to the HIL Device from any attached device on UART port.

This component receives input bytes and convert them into data values. Input data values are represented by variables. Type of variables can be defined in property “Input variable data type”. After receiving, the variables can be used within the simulation.

Messages have the same types like ones described in Message description chapter Figure 6 .

Note: Be careful while sending messages from your machine. Be sure to send new data only when the last data went through Serial port.

Figure 10. Serial Receive component

As you can see, this component has two ports:

  • Data port
  • Status port

Data port is port which outputs received data next to component which he is connected to.

Status port outputs number of errors while receiving, but just in some cases. There are two types of errors:

  • Framing errors
  • Parity errors

If parity is not enabled (parity in Serial Setup component is defined as None), Status port will output always 0.

If parity is enabled, Status port will output count of parity errors and count of framing errors.

After double click on this component will appear component properties window.

Figure 11. Serial Receive component properties
Property Description Values
Byte order

Little endian or big endian. Specifies in which endianness data part will be formatted.

Note:

Header frame is parsed byte by byte, so byte order does not apply to it.

Example: 0x12345678 as big endian is the same as 0x78563412 in the little endian format.
Header

Start sequence of message frame.

Examples for this property are more detailed described in Serial Send, How to define message headerchapter. In this case, you have to generate header in messages, before data part, like ones described in examples.

No header, hexadecimal numbers array, ASCII characters array

Execution rate Rate of executing Signal Processing part of component (acquiring variables). -
Number of input variables

Count of how many variables (values) are sent per message. This is a fixed number, and every message has to contain the defined number of variables (values) every time.

Maximum value is 216

Input variable data type

Defines the type of received variables.

Note:

All values have to be formatted as the same type. For example, if you select real, every value in the message must be formatted as real (float)

1. real - 4 bytes float value

2. int - 4 bytes integer value

3. uint - 4 bytes unsigned integer value

Schematic examples of using Serial components

In this example, we have connected “Constant” component to Serial Send component.

Figure 12. Example of using Serial Send component

Variable types are described in “Constant” component properties:

Figure 13. Constant component properties example

In value text box is defined vector of constants. There are two constants, so number of variables which will be sent through the UART is 2. Signal type is “real”, which means that every variable will be formatted as real (float) type. Execution rate of Serial Send component depends of execution rate defined in “constant” component in this case.

Figure 14. Schematics example of using Serial Receive component

In this example, number of input variables is 4. That is why Bus Split component has 4 outputs, and it is used to split received variables. For analysis of received variables, we connect four probes on the Bus Split outputs. When we compile this schematics, and run in HIL SCADA, Probe 1 will represent first variable, Probe 2 will represent second, Probe 3 third, and Probe 4 fourth. Probe 5 will represent count of receiving errors (parity - if enabled/framing).

VHIL Device Support

Currently Serial components are not supported by VHIL Device.