rs-232 <-> Ethernet

Нет ответов
AS
Offline
Зарегистрирован: 12.03.2014

Хочу сделать сабж.

Arduino UNO R3 + W5100

/*

 The circuit:
 * RX is digital pin 3 (connect to TX of other device)
 * TX is digital pin 5 (connect to RX of other device)


 */
#include <SoftwareSerial.h>
#include <SPI.h>
#include <Ethernet.h>

SoftwareSerial mySerial(3, 5); // RX, TX

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
IPAddress myDns(192,168,1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);


// telnet  to port 509
EthernetServer server(509);
boolean alreadyConnected = false; // whether or not the client was connected previously

void setup() {
  // initialize the ethernet device
  Ethernet.begin(mac, ip, myDns, gateway, subnet);
  // start listening for clients
  server.begin();
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Chat server address:");
  Serial.println(Ethernet.localIP());

   // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
    
}

void loop() {
  // wait for a new client:

EthernetClient client = server.available();
  // when the client sends the first byte, say hello:
  //if (client) {
   // if (!alreadyConnected) {
      // clear out the input buffer:
    //  client.flush();
    //  Serial.println("We have a new client");
    //  client.println("Hello, client!");
    //  alreadyConnected = true;
   // }

    if (client.available() > 0) {
      // read the bytes incoming from the client:
      byte thisChar = client.read();
      //char thisChar = client.read();
      // echo the bytes back to the client:
      server.write(thisChar);
      // echo the bytes to the server as well:
      Serial.write(thisChar);
      //mySerial.write(thisChar);
      mySerial.println(thisChar, HEX);
    //}
  }
  if (mySerial.available()) {
    byte serChar = mySerial.read();
    Serial.write(serChar);
    server.write(serChar);
  //}
  }
}

А вот com-port, который прилеплен на 3 и 5 ногу выдает билиберду. И обратно, если с com-port`a посылать данные, то в native com и в telnet`e тоже билиберда. Подскажите, где я не прав?