Arduino code to write and send at the same time simultaneously

余生长醉 提交于 2019-12-14 02:46:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!