Pages: [1]   Go Down
Author Topic: Sending TCP Hex Command  (Read 640 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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);
    }
  }

}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46300
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
    char incomingString = Serial.read();
Do you have integer variables called somethingFloat or double variables called somethingInteger? A single char is not a string.

Code:
String code;
       if (code.equals("none")){
Seems unlikely to ever be true.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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");


Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46300
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Should I use the println?
No. You want to send the bytes as binary data, not ASCII data.

Code:
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));
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46300
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

But Thank You VERY Much it works !

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46300
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
it works !
Yeah!
Logged

Pages: [1]   Go Up
Jump to: