Sending BYTE to serial port - C++

arunykand used Ask the Experts™
Hi, I have a 5 byte 'unsigned char' data structure: unsigned char m_TxBuf[5];, and I need to send one byte at a time to a function that will write the data to the serial port.  I have the functions in place, but I guess the way i'm trying to send each byte to the function that writes to the serial port is not correct.  


       unsigned char m_TxBuf[5];

        //Call function to write one byte at a time to serial port
	Serialport.WriteByte(m_TxBuf[0]);    //Problem compiling
        Serialport.WriteByte(m_TxBuf[1]);    //Problem compiling

        Serialport.WriteByte(m_TxBuf);  //No problem if I send the entire data structure

BOOL CSerialPort::WriteByte(BYTE *bybyte)
    return false;
     else return true;

Open in new window

I get the following error when compiling:

error C2664: 'CSerialPort::WriteByte' : cannot convert parameter 1 from 'unsigned char' to 'BYTE *'

Thanks for your help
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

The function
BOOL CSerialPort::WriteByte(BYTE *bybyte)
expects the parameter to be the address of a byte (BYTE *). So you've to pass the address.


mgh_mgharish:  Ok I understand your solution, but how come when I sent the entire structure (Serialport.WriteByte(m_TxBuf) ) it does not complain when compiling?

Because, when you pass the entire array, you're essentially passing the address of the first element of the array (Remember? Name of array = address of array = address of first element of array)


Thank you mgh_mgharish!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial