简体   繁体   English

通过单独的Raspberry Pi c ++在一个Raspberry Pi上控制程序

[英]Controlling a program on one Raspberry Pi from a separate Raspberry Pi c++

I have two Pis that will run an identical program. 我有两个Pi,它们将运行相同的程序。 I want to be able to control a second pi with the Controlling Pi using an ethernet cable and TCP. 我希望能够使用以太网电缆和TCP通过控制Pi控制第二个pi。 I will be inputting a number to start the code once the connection between the Pis is established, and I want that number to be input on both machines so the code begins running at the same time. 在Pis之间建立连接后,我将输入一个数字来启动代码,并且我希望在两台计算机上都输入该数字,以便代码同时开始运行。 Once the code completes I want the second Pi to send the value it calculates back to the first Pi. 代码完成后,我希望第二个Pi将其计算的值发送回第一个Pi。

The value sent from the "Controlling Pi" to the second pi will be a 1 digit number. 从“控制Pi”发送到第二个pi的值将是1位数字。 The value sent from the second pi to the Controlling Pi will be a 2 or 3 digit number. 从第二个pi发送到控制pi的值将是2或3位数字。

This is the first time I've ever worked with a device communication, so my question is can I use normal TCP protocols or will that not work due to the fact I need to run the code on both machines? 这是我第一次使用设备通信,所以我的问题是我可以使用普通的TCP协议,还是因为我需要在两台计算机上都运行代码而使它不起作用?

The code below is the data that will be sent from the Controlling Pi. 下面的代码是将从控制Pi发送的数据。 The algorithm that each Pi runs is fully functional, I just need a way to trigger it at the same time and then send the data from one pi to the other. 每个Pi运行的算法都具有完整的功能,我只需要一种方法即可同时触发它,然后将数据从一个pi发送到另一个。 Thanks for the help. 谢谢您的帮助。

cout << "Have patient move eyes to Left, Type: 1, Press enter";
cin >> Step;

A Raspberry-Pi is nothing more than a (mini) Linux machine. Raspberry-Pi仅仅是一台(微型)Linux机器。 You can communicate between them using sockets. 您可以使用套接字在它们之间进行通信。 There are plenty of tutorials on this. 有很多关于此的教程。 Make sure you change the default nane of the Raspberry. 确保更改了Raspberry的默认名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM