我想做的事情: Processing 3通过我的网络摄像头接收一种QR代码->它读取这个值并发送给我的Arduino,Arduino成功地接收到它,现在可以用它做一些事情了。现在我想增加另一个沟通渠道,团结。我希望Arduino将处理过程中的值发送给Unity。这是很容易沟通之间的Arduino和团结,但我需要处理的网络摄像头的价值。
问题:同时处理3和使用同一个端口(COM4,9600)。这将导致联合中的IO异常,即“拒绝访问”,后面是串行端口的错误。
处理3码
...
//Open port
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
myPort.write(1);
...Arduino码
void setup() {
// put your setup code here, to run once:
...
Serial.begin(9600); // Start serial communication at 9600 bps
...
}
void loop() {
if (Serial.available()) { // If data is available to read,
val = Serial.read(); // read it and store it in val
}
//val contains now the data that was sent from Processing 3
//Send this data to Unity:
Serial.flush();
Serial.println(val);
}统一码
...
SerialPort stream = new SerialPort ("COM4", 9600); //We obviously can't open this port since its already in use by Processing 3. How to fix this?
...
// Use this for initialization
void Start () {
stream.Open(); //Throws IO exception: Access Denied error
}
// Update is called once per frame
void Update () {
string value = stream.ReadLine();
val = int.Parse(value);
if (val == 1) {
//Links van arduino
goLeft();
}else if (val == 2) {
//Rechts van arduino
goRight();
}
}我们显然不能打开统一的端口,因为它已经通过处理3使用了。如何解决这个问题?通讯流:
Processing 3 --> Arduino --> Unity最终,团结需要知道你是向左还是向右,根据网络摄像头的QR代码输入。
发布于 2018-06-13 14:08:11
对于那些想知道如何解决这个问题的人来说。你不能。我们得用另一种方式思考。备选方案有:
我已经实现了最后一个选项
通过这种方式,我们仍然可以使用Arduino和Unity直接读取来自处理的输出,而不需要中间人。
发布于 2018-06-13 10:51:50
不能在两个并发应用程序中使用相同的串行端口(为什么要使用Arduino?)解决方案之一是在应用程序之间建立连接。使用127.0.0.1环回连接的网络连接是创建该链接的一种尝试和测试的方法。
就协议而言,您有无尽的选择,我个人的偏好是使用OSC --处理(通过OSCP5)和统一(各种插件,包括我自己的插件--我应该在某个时候公开)--对消息传递有很好的支持,但您可以使用许多其他类型的链接(即。( websockets)
https://stackoverflow.com/questions/50833796
复制相似问题