问题
I am working a graphical blocks for Scilab (software similar to MATLAB) simulation environment. There should be blocks called AI (analogue input), AO, DO. Also, there will be two programs: 1) on the side of Scilab, one which sends and receives data; 2) on the side of Arduino, one which sends and receives data.
Right now I am working on Arduino side code. It, the code, should read voltage values from 6 inputs and sends them to Scilab via serial and simultaneously write 1/0 to its outputs when it gets data from Scilab. In my understanding, data sent/received should have information about pin number (to know what pin it should affect) and value itself. Also, it should read and receives at the same time.
Any ideas how I could do it? Help would be much appreciated. Thank you.
回答1:
You could use a timer interrupt to read the values and send them via serial and handle the commands from Scilab in loop() as usual.
I'm not 100% sure whether there could be problems from possibly being interrupted while in Serial.read(). In this case you might have to disable interrupts while reading the request (check before with Serial.available() whether there's something to read).
来源:https://stackoverflow.com/questions/8996675/arduino-code-to-write-and-send-at-the-same-time-simultaneously