Go Down

Topic: Ethernet TCP send eror (Read 522 times) previous topic - next topic

Asbuild

Hallo,

I started with programming a Arduino UNO R3 with a Ethernet shield R3.

Some example sketches won't word on my new controller.

I wright a program to sent an array of char to a client.
The protocol is fixed by the vendor, and there use printable and non-printable characters.
The non-printable characters are 0x1 (SOH), 0x2 (STX) , 0x3 (ETX) and 0x4 (EOT).

Code: [Select]

#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <SPI.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x19, 0x1C };
byte ip[] = { 192, 168, 115, 135 };
byte server[] = { 192, 168, 115, 213 };

char cmd1[18] = {0x01,0x5A,0x30,0x30,0x02,0x47,0x42,0x32,0x33,0x2E,0x37,0x38,0x04};

EthernetClient client;

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  delay(5000);
  Serial.println("connecting...");
}

void loop()
{
    if (client.connect(server, 3001))
  {
    delay(1000);
    Serial.println("connected ");
    Serial.println();
    EthernetClient::write(cmd1, 18);   //---> Error
    Serial.println("_01Z00_02GB23.78_04); // command string by vendor. _0x are non printable characters
  }
  else
  {
    Serial.println("connection failed");
  }
  delay(1000);
  client.stop();
  delay(10000);
}


In the line with --> error i get this

Client_IP_PORT.ino: In function 'void loop()':
Client_IP_PORT:29: error: cannot call member function 'virtual size_t EthernetClient::write(const uint8_t*, size_t)' without object


I have google but i fond not a solution.

Can somebody help me?

Thanks
Jacques

PaulS

Code: [Select]
   EthernetClient::write(cmd1, 18);   //---> Error
And the compiler is right. The write() method is not a static function. You can't call it like this.

You are replying to some specific client, right? The method call should be
Code: [Select]
   client.write(cmd1, 18);   //---> No error

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