I keep working on graphic blocks for Scilab xcos simulation environment (equivalent to MATLAB Simulink). There will be three types of blocks (see picture): AI (Analogue input), AO (Analogue output), DO (Digital output), 6 AI blocks, 6 AO blocks, 14 DO blocks. These blocks will represent inputs, outputs of Arduino. So, right now I am thinking of the concept of communication between blocks (C/C++ code) and Arduino code via serial port.
On the Arduino side there will be one code that will listen and read to serial port for messages from blocks and write to serial port to blocks (see picture). On the Scilab side, there will be C code in each block. So, my question is what is the best way to organize the communication between these two sides to avoid collisions (when, for example, both sides start writing to serial port simultaneously). For me, it seems too complicated right now.