Go Down

Topic: serial.write(0x00); gives an error (Read 4 times) previous topic - next topic

Jan4ard

In my programm I have to sent a byte 0x00 to a serial device, I do so with the command: Ser1.write(0x00);

However the upoad-button of Arduino 1.0 generates the error message:
call of overloaded 'write(int)' is ambigious
serialtest00.cpp: In function 'void setup()':
serialtest00:11: error: call of overloaded 'write(int)' is ambiguous
E:\arduino-1.0\libraries\SoftwareSerial/SoftwareSerial.h:92: note: candidates are: virtual size_t SoftwareSerial::write(uint8_t)
E:\arduino-1.0\hardware\arduino\cores\arduino/Print.h:49: note:                 size_t Print::write(const char*)

Because according to the Syntax of Serial.write(val), in which -val: a value to send as a single byte- , it should be possible
to sent the byte 00 ( or 0 or 0x00), I therefore think that there is a bug in this piece of software.

Can somebody help me out because I have to sent data (incuding 0x00) to my serial device.      Jan.

Runaway Pancake

I get that, too.
But...
If I make a variable -
byte zero = 0;

and then
Serial.write(zero);
it compiles.

Test that out.
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

PaulS

Quote
I therefore think that there is a bug in this piece of software.

No, there isn't. The compiler is telling you EXACTLY what the problem is. The value 0x00 is not typed, so it could be a char (NULL), a byte, or an int. The compiler is refusing to guess which method you want to use.

You can do as runaway_pancake suggests, or you can simply tell the compiler how YOU want it to interpret the typeless value:
Ser1.write((byte)0x00);

Professor Chaos


Quote
I The value 0x00 is not typed, so it could be a char (NULL), a byte, or an int. The compiler is refusing to guess which method you want to use.


Actually, isn't the problem that the literal constant 0x00 is typed - but as an int?

PaulS

Quote
Actually, isn't the problem that the literal constant 0x00 is typed - but as an int?

No, it is not typed. However, in the absence of directives the the contrary, literals that can be interpreted as ints will be. Whether the value fits in an int, or not. The problem is that the literal can be interpreted as an int, but there is no write() method that takes an int, so the compiler needs to be told more information, so it can choose the right overloaded method to call.

Go Up