Serial0.write not working

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
dawiinci
Posts: 48
Joined: 14 Oct 2017 10:54

Serial0.write not working

Post by dawiinci »

I want to use TX0 to send code to a computer.

Code: Select all

  uint8_t test[5] = { 0x02, 0xFF, 0xFF, 0x01, 0x02 }; 
  uint8_t command[5] = { 0x0F, 0x01, 0xF1, 0x00, 0x00 };
  memcpy(command, test, sizeof(command));
  Serial0.write(command, 5);
However, I get this error:

Code: Select all

no matching member function for call to 'write'
I am using the 2.1.1 test build.


In addition I can't use AltSoftSerial.h with Z-Uno. (not found)
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: Serial0.write not working

Post by petergebruers »

Welcome, dawiinci. Good catch... It seems HardwareSerial does not implement writing a buffer, while other classes do implement it.

Can you work around it like this? Works for me!

Code: Select all

uint8_t test[] = { 0x02, 0xFF, 0xFF, 0x01, 0x02 };
uint8_t command[] = { 0x0F, 0x01, 0xF1, 0x00, 0x00 };

void SerialWriteBuf(uint8_t *buffer, size_t size)
{
  while (size != 0) {
    Serial.write((uint8_t) * buffer);
    buffer++;
    size--;
  }
}
void setup() {
  Serial.begin();
}

void loop() {
  SerialWriteBuf(command, sizeof(command));
  delay(3000);
  SerialWriteBuf(test, sizeof(test));
  delay(3000);
}
dawiinci
Posts: 48
Joined: 14 Oct 2017 10:54

Re: Serial0.write not working

Post by dawiinci »

Thank you

I have to be honest I don't know why I had to use the buffer. But it worked like this and I don't want to break anything in the recipient. Maybe you have an explanation for this. The workaround seems plausible though.

I am also using it for Serial0.readBytes(status, 5), where ist seems to work. At least I don't get an error.
dawiinci
Posts: 48
Joined: 14 Oct 2017 10:54

Re: Serial0.write not working

Post by dawiinci »

Ok, I think I understand now. Serial ports only send one byte. With the buffer I can simply send multiple bytes.

Do you have an idea why Serial0.readBytes(status, 5); works? I'm using buffers as well. But I don't get any error. Is this supported?

Thanks for the workaround.
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: Serial0.write not working

Post by petergebruers »

Yes, readBytes is supported. I use it in my MH-Z19 sketch.
Post Reply