Go Down

Topic: Sending TCP Hex Command (Read 1 time) previous topic - next topic

cre4tix

Hello,

I try to send an HEX command with my arduino Uno, in order to control a SNELL Frame.

My command is : 000C0018000011010000000000000000000A100008CB000100000000

Arduino UNO IP : 192.168.1.222
SNELL Frame : 192.168.1.221
Port : 2050

For the moment I just send the command by writing in the serial console...

Could you help me to established the program ?

Thanks by advance.

cre4tix

Code: [Select]
#include <SPI.h>
#include <Ethernet.h>

/**** DEFINITION DES VARIABLES ****/
// Adresse MAC de la carte Ethernet
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x9E, 0x16 };
// Adresse IP de la carte Ethernet si pas DHCP
byte ip[] = { 192,168,1,222 };
// Adresse du chassis SNELL
byte rollcall[] = { 192,168,1,221 };
// Client Ethernet
EthernetClient clientRollCall;
// Varible réception série
String code;


/**** SETUP DU SYSTEME ****/
void setup() {
// Ouvre la connexion série pour la console
    Serial.begin(9600);
    Serial.println("Connection Serie etablie");
  delay(500);
    Serial.println("Vitesse du port 9600 bps");
  delay(500);
// Connection Ethernet
  Ethernet.begin(mac,ip);
  delay(500);
    Serial.println("Connection IP en cours ...");
  delay(1000);
     if(clientRollCall.connect(rollcall, 2050)) {
       Serial.println("Connection au chassis SNELL etablie.");
     }
     else {
       Serial.println("Echec de la connection au chassis SNELL.");
     }
}

/**** CONVERSION RS232 > IP ****/
void loop(){
  // Lecture des données entrantes sur le port série (Arduino Uno).
  // Changer numéro de port si Board différente du UNO.
  // Nécessite une interface TLL vers RS232.
  if(Serial.available()){
    char incomingString = Serial.read();

       if (code.equals("none")){
          Serial.println("Aucune commande recue");
       } else {
          Serial.println("Commande recue :"+incomingString);
          clientRollCall.connect(rollcall, 2050);
          delay(100);
          clientRollCall.println("000C0018000011010000000000000000000A100008CB000100000000");
          delay(100);
          clientRollCall.println();
          delay(100);
          //clientRollCall.stop();
      }
    delay(100);
  }

  if(clientRollCall.available()){
    char c = clientRollCall.read();
    Serial.print(c);
  }

  while (Serial.available() > 0) {
    char inChar = Serial.read();
    if (clientRollCall.connected()) {
      clientRollCall.print(inChar);
    }
  }

}

PaulS

Quote
My command is : 000C0018000011010000000000000000000A100008CB000100000000

No, it isn't. It might be:
0x00, 0x0C, 0x00, 0x18, 0x00...

Tools + Auto Format
                       is a good thing. It
   will stop your
            code wandering
   all over the page
                                          like that.

Code: [Select]
    char incomingString = Serial.read();
Do you have integer variables called somethingFloat or double variables called somethingInteger? A single char is not a string.

Code: [Select]
String code;
       if (code.equals("none")){

Seems unlikely to ever be true.

cre4tix

Ok thanks for your answer.

Should I use the println?
If yes, what is the correct syntax?

Like this ?
clientRollCall.println("0x00,0x0C,0x00,0x18,0x00,0x00,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0A,0x10,0x00,0x08,0xCB,0x00,0x01,0x00,0x00,0x00,0x00");



PaulS

Quote
Should I use the println?

No. You want to send the bytes as binary data, not ASCII data.

Code: [Select]
byte command[] = {0x00, 0x0C, 0x00, 0x18, 0x00,
      0x00, 0x11, 0x01, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x0A, 0x10, 0x00,
      0x08, 0xCB, 0x00, 0x01, 0x00,
      0x00, 0x00, 0x00};
clientRollCall.write(command, sizeof(command));

cre4tix

byte command[] = {
  0x00, 0x0C, 0x00, 0x18, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x10, 0x00, 0x08, 0xCB, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};

In this case the size of the command is 28 ?

client.write(command,28);

PaulS

Quote
In this case the size of the command is 28 ?

Why do you want to count them? The compiler can, and it has never miscounted.

cre4tix

Sorry i'm really a noob :-s ...

But Thank You VERY Much it works !


PaulS


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy