Community
cancel
Showing results for 
Search instead for 
Did you mean: 
FGarc8
Novice
963 Views

Serial to Ethernet converter Intel Galileo Gen2

Jump to solution

Hello,

I have been trying to create via Arduino IDE with one sketch a Serial to Ethernet converter (the code is below). First of all I've tried to communicate from the Serial port to the Ethernet and everything was ok, via telnet. After this I've tried to communicate from Ethernet to Serial and it was also ok, without any kind of delay. However, when I joined both solutions I found one problem: the serial to ethernet information is received as a burst not continuosly. After some debugging I detected that the method client.available() is the one that introduces a delay, I assume that is a timeout delay waiting for the client and after this delay I receive all the information buffered in the serial port. The question is that I want to receive in continuously in both directions, so my questions are:

Is there any way to modify the timeout of the different functions such as client.available()?

If there is no way to modify this timeout, can I execute in a parallel way both recepcion and transmission in order not to block non of the processes? In other words, can I handle independently the Serial to Ethernet and the Ethernet to Serial in order not to block with the timeout of the Ethernet functions the serial ones?

Sorry if it's and easy question but I am starting with Intel Galileo, Arduino IDE an sketch.

Thank you very much in advance.

 

Note: I am using the serial interface to debug and serial1 to connect the a physical serial port (that's why everything is related to Serial1, but with Serial works exactly the same)

 

 

Best regards,

 

Fran

 

# include

# include

byte mac[] = {0x98, 0x4F, 0xEE, 0x05, 0xA3, 0xD3};

IPAddress ip(192,168,1, 20);

IPAddress gateway(192,168,1, 1);

IPAddress subnet(255, 255, 0, 0);

EthernetServer server(23);

boolean alreadyConnected = false; // whether or not the client was connected previously

void setup() {

pinMode(5, OUTPUT);//Select the multiplexor to choose the RS232 Slot of Cooking hack's

system("ifdown eth0");//I have to do this in order to make Ethernet work

system("ifup eth0");//I have to do this in order to make Ethernet work

delay(3000); // Delay to check in the serial port the IP

// initialize the ethernet device

Ethernet.begin(mac);// IP with DHCP

// start listening for clients

server.begin();

// Open serial communications and wait for port to open:

Serial.begin(9600);//Initialize debugging port

Serial1.begin(9600);//Initialize Cooking Hacks port

while (!Serial) {

; // wait for serial port to connect. Needed for Leonardo only

}

Serial.print("Chat server address:"); //To debugging port

Serial1.print("Chat server address:");//To Cooking Hacks port

Serial.println(Ethernet.localIP()); //To debugging port

Serial1.println(Ethernet.localIP());//To Cooking Hacks port

}

void loop() {

// wait for a new client:

EthernetClient client = server.available();

digitalWrite(5, HIGH);//Select the multiplexor to choose the RS232 Slot of Cooking hack

//--------------------------------------From Ethernet to Serial-----------------------

// when the client sends the first byte, say hello:

if (client) {

if (!alreadyConnected) {

// clead out the input buffer:

client.flush();

Serial.println("We have a new client");//To debugging port

Serial1.println("We have a new client");//To Cooking Hacks port

client.println("Hello, client!");

alreadyConnected = true;

}

/*if (client.available() > 0) { // HERE is where the process is blocked (with the client.available), if there is no reception via Ethernet the From Serial to Ethernet is not executed until the timeout expires.

//When the timeout

// read the bytes incoming from the client:

char thisChar = client.read();

// echo the bytes to the serial ports:

Serial.print(thisChar);//To debugging port

Serial1.print(thisChar);//To Cooking Hacks port

}*/

//--------------------------------------From Serial to Ethernet-----------------------

//if (Serial.available())

//{

// delay(10);

// char inByte;

// inByte = Serial.read();

// Serial.write(inByte);

//}

if (client.available() > 0) {

// read the bytes incoming from the client:

char thisChar = client.read();

// echo the bytes back to the client:

//server.write(thisChar);

// echo the bytes to the server as well:

Serial.print(thisChar);

Serial1.print(thisChar);//To Cooking Hacks port

}

else{

if(Serial1.available())

{

while (Serial1.available()) {

char inChar = char(Serial1.read());

Serial.write(inChar);

Serial1.write(inChar);//To Cooking Hacks port

server.write(inChar);

}

Serial.write("\n");

Serial1.print("\n");//To Cooking Hacks port

//server.write("\n");

}

}

}

}

Tags (1)
1 Solution
Juan_M_Intel
Employee
64 Views

Hi fgarcia.autis,

Yes it is possible to modify the timeout of client.available(). You can do this in the library EthernetClient.cpp in the function int EthernetClient::available(). In case you are using Arduino 1.6.5 this file can be found in Windows at C:\Users\\AppData\Roaming\Arduino15\packages\Intel\hardware\i586\1.6.2+1.0\libraries\Ethernet\src\Et... I hope this helps.

Regards,

 

JPMontero_Intel

View solution in original post

2 Replies
Juan_M_Intel
Employee
65 Views

Hi fgarcia.autis,

Yes it is possible to modify the timeout of client.available(). You can do this in the library EthernetClient.cpp in the function int EthernetClient::available(). In case you are using Arduino 1.6.5 this file can be found in Windows at C:\Users\\AppData\Roaming\Arduino15\packages\Intel\hardware\i586\1.6.2+1.0\libraries\Ethernet\src\Et... I hope this helps.

Regards,

 

JPMontero_Intel

View solution in original post

FGarc8
Novice
64 Views

Hello JPMontero_Intel,

Thank you very much for your response. Now it works fine, I have continuos transmission and reception by changing the EthernetClient::available() timeout to 50ms.

Regards,

Fran

Reply