简体   繁体   English

如何将数据从Arduino发送到PC

[英]How to Send Data from Arduino to PC

I'm new to arduino. 我是arduino的新手。
I have a server side application (C# application) which responds on port 8888. 我有一个服务器端应用程序(C#应用程序),它在端口8888上响应。
I have connected the Arduino with my Laptop using Ethernet. 我已经使用以太网将Arduino与笔记本电脑相连。
My Laptop has a static IP address 192.168.1.23 and my Arduino has 192.168.1.22. 我的笔记本电脑有一个静态IP地址192.168.1.23,而我的Arduino有192.168.1.22。
I can not connect to server side application. 我无法连接到服务器端应用程序。

I have the following Arduino Code 我有以下Arduino代码

#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 177 };
byte server[] = { 192, 168, 1, 23 }; // Google

EthernetClient client;

void setup()
{
    Ethernet.begin(mac, ip);
    Serial.begin(9600);

    delay(1000);

    Serial.println("connecting...");
    Serial.println(Ethernet.localIP());

    if (client.connect(server,8888)) {
        Serial.println("connected");
    } else {
        Serial.println("connection failed");
    }
}

You can checking that your connection is OK, try to ping the PC from the Ardunio or a firewall blocking the messages? 您可以检查连接是否正常,尝试从Ardunio ping PC或防火墙阻止消息吗? You can try this code 您可以尝试此代码

void loop()
{ 
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    while (client.connected()) {
      if (client.available()) {

}
}
}

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

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