2014-07-24 1 views
0

Windows 7에서 Arduino 1.5.3으로 스케치를 업로드 한 인텔 갈릴레오에 이더넷으로 연결된 VS2012를 사용하고 있습니다. 최종 목표는 이더넷 케이블을 통해 모터를 제어하는 ​​것이지만 두 프로그램 간의 간단한 연결을 설정할 수는 없습니다. 이더넷 넷이나 Udp 또는 네트워크에 대한 경험이 없으므로 불합리한 금액을 상세하게 기재하십시오.인텔 갈릴레오를 이더넷 케이블을 통해 C#에 연결하려고 시도했습니다.

#include <SPI.h>   // needed for Arduino versions later than 0018 
#include <Ethernet.h> 
#include <EthernetUdp.h>   // UDP library from: [email protected] 12/30/2008 


byte mac[] = { 0X98 , 0x4F, 0xEE, 0x01, 0x54, 0xB3}; 
IPAddress ip(192,168,1,177); 
unsigned int localPort = 8888;  




char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet, 
char ReplyBuffer[] = "acknowledged";  // a string to send back 
// An EthernetUDP instance to let us send and receive packets over UDP 
EthernetUDP Udp; 


void setup() { 
// start the Ethernet and UDP: 
Ethernet.begin(mac,ip); 
Udp.begin(localPort); 


Serial.begin(9600); 
} 


void loop() { 
// if there's data available, read a packet 
int packetSize = Udp.parsePacket(); 
if(packetSize) 
{ 
Serial.print("Received packet of size "); 
Serial.println(packetSize); 
Serial.print("From "); 
IPAddress remote = Udp.remoteIP(); 
for (int i =0; i < 4; i++) 
{ 
    Serial.print(remote[i], DEC); 
    if (i < 3) 
    { 
    Serial.print("."); 
    } 
} 
Serial.print(", port "); 
Serial.println(Udp.remotePort()); 


// read the packet into packetBufffer 
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE); 
Serial.println("Contents:"); 
Serial.println(packetBuffer); 


// send a reply, to the IP address and port that sent us the packet we received 
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); 
Udp.write(ReplyBuffer); 
Udp.endPacket(); 
} 
delay(10); 
} 

첫째, 다음, 갈릴레오 오픈 스케치를 업로드 : 여기

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Net.Sockets; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 


namespace TemperatureArduinoReader 
{ 
static class Program 
{ 

    /// <summary> 
    /// The main entry point for the application. 
    /// </summary> 
    [STAThread] 

    static void Main() 
    { 
     byte[] packetData = System.Text.ASCIIEncoding.ASCII.GetBytes("hello World"); 


     string IP = "192.168.1.177"; 
      //"127.0.0.1"; 
     int port = 8888; 


     IPEndPoint ep = new IPEndPoint(IPAddress.Parse(IP), port); 
     Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); 


     client.SendTo(packetData, ep); 

    } 
} 
} 

는 아두 이노 webstite에서 촬영 아두 이노에 내 코드입니다 : 여기

은 C#을 내 코드입니다 직렬, 다음 C# 프로그램을 실행하지만 아무것도 직렬에 나타납니다.

나는 며칠 동안 이것을 알아 내려고 벽에 머리를 때렸다. IP 주소와 그 밖의 모든 조합을 시도했지만, 이제 당신의 도움을 찾고 있습니다.

감사합니다.

답변

1

Windows 시스템과 Galileo 사이의 IP 주소 확인에 문제가 있다고 생각합니다. Galileo를 Windows 랩톱에 직접 연결했을 때 169.254.151.131과 같이 할당되지 않은 서브넷과 연결된 IP 주소를 얻습니다.

내 Galileo에 192.168.1.177과 같은 IP 주소를 할당하면 내 Windows 시스템과 대화 할 수 없습니다. 필자의 Galileo에서 내 랩톱에 직접 연결되어있는 동안 이더넷 DHCP 주소를 요청하면 169.254.246.246과 같은 IP 주소를 얻게됩니다. 그래서 내 Windows 시스템은 Galileo와 대화하고 UDP 패킷을 스케치에 보낼 수 있습니다.

제 제안은 Windows 시스템과 Galileo의 IP 주소를 확인하여 서로 연결할 수 있는지 확인하는 것입니다.

갈릴레오와 이야기하는 데 사용한 스케치가 포함되어 있습니다.

/* 
    UDPSendReceive 

This sketch receives UDP message strings, prints them to the serial port 
and sends an "acknowledge" string back to the sender 

A Processing sketch is included at the end of file that can be used to send 
and received messages for testing with a computer. 

created 21 Aug 2010 
by Michael Margolis 

This code is in the public domain. 

*/ 


#include <SPI.h>   // needed for Arduino versions later than 0018 
#include <Ethernet.h> 
#include <EthernetUdp.h> // UDP library from: [email protected] 12/30/2008 


// Enter a MAC address and IP address for your controller below. 
// The IP address will be dependent on your local network: 
byte mac[] = { 0x98, 0x4f, 0xeE, 0x00, 0x23, 0xb9 }; 
unsigned int localPort = 8888;    // local port to listen on 

// buffers for receiving and sending data 
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet, 
char ReplyBuffer[] = "acknowledged";  // a string to send back 

// An EthernetUDP instance to let us send and receive packets over UDP 
EthernetUDP Udp; 

void setup() { 
    Serial.begin(9600); 
    delay(5000); 
    Serial.println("Ready"); 
    // get an IP address from DHCP server, if there isn't a DHCP server on the network 
    // an address such as 169.254.246.246 will be assigned 
    if (Ethernet.begin(mac) == 1) { 
    Serial.println("Ethernet.begin() succeeded!"); 
    Serial.print("IP:  "); 
    Serial.println(Ethernet.localIP()); 
    Serial.print("Subnet: "); 
    Serial.println(Ethernet.subnetMask()); 
    Serial.print("Gateway: "); 
    Serial.println(Ethernet.gatewayIP()); 
    Serial.print("DNS:  "); 
    Serial.println(Ethernet.dnsServerIP()); 
    } else { 
    Serial.println("Failed to initialize Ethernet"); 
    while(1); 
    } 
    Udp.begin(localPort); 
    Serial.println("Listening to UDP port 8888"); 

} 

void loop() { 
    // if there's data available, read a packet 
    int packetSize = Udp.parsePacket(); 
    if(packetSize) 
    { 
    Serial.print("Received packet of size "); 
    Serial.println(packetSize); 
    Serial.print("From "); 
    IPAddress remote = Udp.remoteIP(); 
    for (int i =0; i < 4; i++) 
    { 
     Serial.print(remote[i], DEC); 
     if (i < 3) 
     { 
     Serial.print("."); 
     } 
    } 
    Serial.print(", port "); 
    Serial.println(Udp.remotePort()); 

    // read the packet into packetBufffer 
    Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE); 
    Serial.println("Contents:"); 
    Serial.println(packetBuffer); 

    // send a reply, to the IP address and port that sent us the packet we received 
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); 
    Udp.write(ReplyBuffer); 
    Udp.endPacket(); 
    } 
    delay(10); 
} 

/* 
    A sample perl script to send a UDP message to above Galileo sketch 
    #!/usr/bin/perl -w 
    use strict; 
    use IO::Socket::INET; 
    # change PeerAddr to match what the Galileo sketch reports back 
    my $sendSocket = new IO::Socket::INET(PeerAddr=>'169.254.246.246', 
         PeerPort=>8888, 
         Proto => 'udp', 
         Timeout=>1) or die('Error creating UDP socket'); 
    my $data = "Hello Galileo!"; 
    print $sendSocket $data; 

*/ 

그리고 아래는 내 직렬 포트의 출력이 원격 시스템의 IP 주소가 255.255.255.255, 포트 0으로 표시되어 있는지

Ready 
Ethernet.begin() succeeded! 
IP:  169.254.246.246 
Subnet: 255.255. 0. 0 
Gateway: 255.255.255.255 
DNS:  255.255.255.255 
Listening to UDP port 8888 
Received packet of size 14 
From 255.255.255.255, port 0 
Contents: 
Hello Galileo! 

주를 모니터링, 그래서 스케치는 할 수 없습니다 UDP 응답 패킷을 다시 보냅니다. 나는이 부분을 아직 이해하지 못했다. 해결 방법이 있는지 확인하려면 https://communities.intel.com/community/makers/content을 확인하십시오.

또한 C#이 아니라 갈릴레오와 대화 할 때 perl을 사용했습니다. 그래도 문제가 아니어야합니다. 나는 C#에 익숙하지 않다.

관련 문제