Pages: [1]   Go Down
Author Topic: Ethernet TCP send eror  (Read 382 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46140
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
   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:
   client.write(cmd1, 18);   //---> No error
Logged

Pages: [1]   Go Up
Jump to: