Extended ASCII code

Hi!

So im just trying to send a number in HEX to my Arduino wich is larger than 128. The Arduino says C0 = 195. Under 128 everything is correct. What can i do with it?

How do you send it?
What variable type?

Isn't that okay, higher than 128?

I send it from a Delphi program through socket and it is a byte. If the number is higher than 128 its value gonna be wrong. So for example C0 should be 192 but it says 195.

I didn't recognize that "C0" was meant to be a hex number. Could it be a byte variable or constant of value 195?

192 is correct, but who says it's 195? Which function?

If you say that you send a byte then try sending 192 (decimal).

I send this from the Delphi side:

FIXIP[21] := byte(192); //This is a byte array 
//or
FIXIP[21] := $C0;

In both cases the output is wrong.
And on the Arduinos side the readedData[21] (this is a char array) equals to 195 .I can see it from the Serial monitor.

What if you try sending other values? Is the difference constant? What about the other array elements?

How is FIXIP declared?

The difference isn't constant.

FIXIP[21] := byte(195); //On the Arduino's side equals to -61
FIXIP[22] := byte(168); //Equals to -125
FIXIP[23] := byte(0); //Equals to -62
FIXIP[24] := byte(24); //Equals to -88

The other values in the array are ok if they are below 128.
The fix ip is declared as byte array:
FIXIP : array[0..67] of byte;

Can you post the arduino code?

Sorry i can't post the whole code, because its 2000+ lines. But the value giving is here:

GivenAddress[0] = (unsigned long)readedData[21];
GivenAddress[1] = (unsigned long)readedData[22];
GivenAddress[2] = (unsigned long)readedData[23];
GivenAddress[3] = (unsigned long)readedData[24];

You need to show how the data is read from serial, how is readedData[] declared and populated?

Please post an MRE, the simplest possible complete sketch that demonstrates the problem. That should be easy in this case, send just one byte with a value over 127 and receive one byte, print the value.

void setup()
{
ws.onMessage([](WebSocket &ws, const WebSocket::DataType dataType, const char *message, uint16_t length) {
      switch (dataType) {
        case WebSocket::DataType::TEXT:

          Serial.print("Message");
          //getNtpTime();
          dataArrive(message, ws);
          ws.send(WebSocket::DataType::TEXT, message, strlen(message));
          ResetVariables(); 
          break;

        case WebSocket::DataType::BINARY:
          _SERIAL.println(F("Received binary data"));
          dataArrive(message, ws);
          ws.send(WebSocket::DataType::TEXT, message, strlen(message));
          ResetVariables();
          break;
      }
    });
}

void loop()
{
	wss.listen();
}

void dataArrive(char readedData[], WebSocket &ws) {
.
.
.

GivenIPAddress[0] = (unsigned long)readedData[21];
GivenIPAddress[1] = (unsigned long)readedData[22];
GivenIPAddress[2] = (unsigned long)readedData[23];
GivenIPAddress[3] = (unsigned long)readedData[24];
}

If I send 195 from the Delphi program the Arduino recieves -61, If i send 168 the Arduino recieves -125.

char is signed, you need an unsigned data type. If GivenIPAddress is signed, the value will still be converted back to signed even with the cast.

If you send the entire array, can it be received by the Arduino in full length?

Which Arduino do you use BTW?

Try casting ReadedData to unsigned char instead of unsigned long.

Yes the entire array can be recieved by the Arduino. Im using a mega 2560.

Casting doesen't solve the problem.

It's not a matter of the Arduino but of the WebSocket maximum transmission size.

The WebSocket maximum transmission size is far more than the data I am sending.

can you post the code reading the data?

can you post a smaller program that demonstrates the problem?