【问题标题】:Run arduino project from winforms project within the same solution在同一解决方案中从 winforms 项目运行 arduino 项目
【发布时间】:2017-03-21 17:19:52
【问题描述】:

我在visual studio中做了一个解决方案,一个我有一个winform应用程序项目和另一个arduino项目。在我的winform中,我添加了一个按钮。所以我希望每当我点击winform中的按钮时,arduino代码都会执行。请告诉我这样做的程序。

【问题讨论】:

  • 我想最简单的方法是通过串口向Arduino发送消息。
  • 你能指导我吗,因为我是 arduino 的新手,或者你能给我一个我可以参考的链接。并感谢您的回复先生。

标签: c# winforms visual-studio arduino


【解决方案1】:

最简单的命令结构是单个字符。在C#端,打开一个串口并写入char:

// In the button handler write the command to the port
// Change port # to whatever
SerialPort serialPort = new SerialPort("COM3", 9600);
serialPort.Open();
serialPort.Write("1");
serialPort.Close();

在 Arduino 方面:

void setup () 
{ 
    // Enable serial port
    Serial.begin(9600); 
} 

char cmd;
void loop () 
{ 
    if (Serial.available()) {
        // Read byte from serial port 
        cmd = Serial.read(); 
        switch (cmd) { 
            case '1':
            // Command from PC rcvd - do something here
            break; 
        }
    } 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多