Arduino的code编写,并在同一时间同时发送 [英] Arduino code to write and send at the same time simultaneously

查看:251
本文介绍了Arduino的code编写,并在同一时间同时发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的图形块的Scilab(软件类似于MATLAB)仿真环境。应该有块叫AI(模拟输入),AO,DO。此外,将有两个方案:1)上的Scilab,其中一个发送和接收数据的一侧; 2)的Arduino的传送和接收数据的一侧,之一。

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.

现在我工作的Arduino侧code。它的code,应该从6个输入读取电压值,并通过串行它们发送到Scilab的同时写1/0至其产出时,它从Scilab的获取数据。在我的理解,发送/接收数据有关于针数(要知道它应该影响什么针)和价值本身的信息。此外,它应读,并在同一时间接收

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.

任何想法我怎么能这样做呢?帮助将非常AP preciated。谢谢你。

Any ideas how I could do it? Help would be much appreciated. Thank you.

推荐答案

您可以使用定时器中断阅读价值和通过串口发送给他们,并处理从Scilab的命令循环()如常。

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.

我不是100%肯定是否有可能是从问题可能被打断,而在 Serial.read()。在这种情况下,你可能会一边读请求禁止中断(与检查前Serial.available()是否有什么东西读)。

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).

这篇关于Arduino的code编写,并在同一时间同时发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆