班機鷹 發表於 2015-10-14 18:15:31

請問 Arduino Ethernet 與 電腦通信

大家好, 目前剛開始學習Arduino想透過Ethernet 接收PC上其它程式傳進來的資料
但是一直收不到PC端的資料
不知道是哪邊想法出錯了

Arduino端代碼
#include <Ethernet.h>
#include <SPI.h>
#include <SoftwareSerial.h>

// Ethernet
byte mac[] = { 0xAC, 0x22, 0x0B, 0x89, 0x7E, 0x62 };
byte ip[] = { 172, 16, 13, 36 };
EthernetClient client;

void setup() {
        // put your setup code here, to run once:
       
        // Open serial communications and wait for port to open:
        Serial.begin(9600);
        Serial.println("hello");


        if ( Ethernet.begin(mac) == 0 )
                Serial.println("Ethernet error");
        else
                Serial.println( Ethernet.localIP() );

        client.connect(ip, 80);
}

void loop() {
        // put your main code here, to run repeatedly:
       
       
        if ( client.available() ) {

                char rxData;
                int rxSteps;

                Serial.println("Ethernet");

                client.readBytes( rxData, sizeof(rxData) );

                rxSteps = atoi(rxData);
   
                Serial.println(rxSteps);               
               
        }
}



VS C++代碼
CSocket Socket;
        CString cmd;

        cmd = "GET /4000 HTTP/1.1\r\n";

        Socket.Create();
        Socket.Connect(gbCS_CamIP, gbI_PORT);
        Socket.Send( cmd.GetBuffer(0), cmd.GetLength() );
        Socket.Close();
頁: [1]
查看完整版本: 請問 Arduino Ethernet 與 電腦通信