Pages: [1]   Go Down
Author Topic: serial.write(0x00); gives an error  (Read 3580 times)
0 Members and 1 Guest are viewing this topic.
The Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 64
Posts: 2453
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Test that out.
Logged

"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?"

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

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

0
Offline Offline
Full Member
***
Karma: 1
Posts: 225
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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

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

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

The Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the practical solution for my problem, for the theory behind it I have to start studying:
what I do not understand is that sending 0x01 (or other hex-values) does not give a problem (as being a hex-value for data) while 0x00 is not accepted as hex-data.
As PaulS stated ''The value 0x00 is not typed'', my (study)problem is then why is 0x01 ''typed''
or differently: if I have to declare 0x00 to be a byte ((byte)0x00),
why is it not necessary to have 0x01 also to be declared to be a byte ((byte)0x01).
I have just read the answer of PaulS on Professor Chaos: I have to admit it is above my knowledge-level.
Therefore again: thanks for the help.   Jan.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6637
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"0" is magic because it is also the value of a null pointer.
 
Quote
note: candidates are: virtual size_t SoftwareSerial::write(uint8_t)
 note:                 size_t Print::write(const char*)
The actual complaint from the compiler is that it can't tell an int (uint8_t) from a null pointer (const char *), not that it can't tell an int from a char.
I think this was/is because C compiler geeks are lazy and didn't want to write ((char*)0) around all the null pointers they were passing around.  Proper usage would be:
Code:
Serial.write((uint8_t) 0);
(please don't use "byte"; it's a terribly overloaded term that is being removed from all sorts of official libraries!)
Logged

Offline Offline
Faraday Member
**
Karma: 58
Posts: 2778
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How is 'byte' an overloaded term ?  It has precisely one meaning.

Where as 'char'  for example is very problematical.    Since someone decided that 127 chars were not
enough,  char has become a nightmare which I avoid as much as possible, because you can never
tell what it means any more.
Logged

Pages: [1]   Go Up
Jump to: