Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 2 months ago.
How do I use serial write for uint8 buffer array?
I cannot compile if I use serial write(). It comes up with error: virtual ssize_t mbed::Stream::write(const void*, size_t)' is protected. Here is the function:
void serialWrite(Serial* _fd, uint8_t* buf, uint8_t len) { int remain = len; int offset = 0; while (remain > 0) { int sub = (remain >= 8 ? 8 : remain); _fd->write(buf + offset, sub); wait(0.01); remain -= 8; offset += 8; } return; }
The passed array like uint8_t cmd[] = { 0xAB, 0, 0xAC, 0xBC, 0xFE, 0x45, 0x68, 0xEA, 0x85, 0xBC, 0x62};
Develop env.: WIN7, Eclipse, Cross ARM GCC.
How do I fix it? Thanks.
Question relating to:
1 Answer
9 years, 2 months ago.
That is not the error I would have expected you would get, since as far as I am aware serial write function does not exist for the LPC1768. All those asynchronous functions are only available on a few Silicon Labs boards, and just polluting the documentation for all other platforms. One option you have is simply using putc on each byte you want to send in a loop.
If you do want to send it asynchronously you can have a look at either MODSERIAL of BufferedSerial libraries for your device.