Integrates real hardware into the xcos simulation using a serial comport. This toolbox provides this block and the corresponding C-code for the embedded system.
This block provides a bidirectional way to receive the C structure of input signals from an embedded system to the XCOS simulation and to send an other C structure of output signal back to the embedded system.
Some possible embedded systems:
Arduino
Any 8/16/32bit Controller with a serial port connection to the PC.
Existing control units with an serial port that shall be integrated in a hardware-in-loop simulation.
An other interconnected with the serial port
There the serial com-port name can be configured (e.g.: Windows: COM4, Linux: /dev/ttyUSB0). In future a TCP-IP based communication is planed but not implemented in this version.
Configure here the required baudrate of the serial connection.
With a sequence of characters the C-struct structure and alignment of data can be configured. For the following C-struct example the corresponding frame format is "bbb_dw__f".
This example output signal frame format will create 6 block input signal connectors.
// Frame format specified within the embedded system // and sent from the XCOS block to the embedded system. struct rxFrame { unsigned char digitalOutputs0_7; unsigned char analogOutput0; unsigned char analogOutput1; unsigned char spare0; // spare entry for correct alignment unsigned long analogOutput2; unsigned short analogOutput3; unsigned short spare1; // spare entry for correct alignment float analogOutput4; unsigned char crc1; unsigned char crc2; }; | ![]() | ![]() |
With a sequence of characters the C-struct structure and alignment of data can be configured. For the following C-struct example the corresponding frame format is "b_wfd".
This example input signal frame format will create 4 block output signal connectors.
// Frame format specified within the embedded system // and sent from the embedded system to the XCOS block. struct txFrame { unsigned char digitalInputs0_7; unsigned char spare0; // spare entry for correct alignment unsigned short analogInput0; unsigned float analogInput0; unsigned long counter; // position decoder unsigned char crc1; unsigned char crc2; }; | ![]() | ![]() |
Implemented and works. Exact description is pending.
Implemented and works. Exact description is pending.
Following Arduino project for a standard IO application contains a valid implementation of the communication stack. Extract it to implement it into your custom application.
// ============================================================================ // Execute this script top open the Arduino standard IO application source code // ============================================================================ editor(wgserialxcosio("getModulePath") +filesep()+ "arduino" + filesep()+"universalIO" + filesep()+"universalIO.ino"); | ![]() | ![]() |