No instance of overload function
- This topic has 2 replies, 2 voices, and was last updated 8 years, 6 months ago by Will Blight.
-
AuthorPosts
-
May 24, 2016 at 10:43 am #12654Will BlightParticipant
I am using the MTSSerial library and I get the following 2 errors when I try to use write(const char* data, int length) or read(const char* data, int length).
Error Messages
Error: No instance of overloaded function “mts::MTSSerial::write” matches the argument list in “main.cpp”, Line: 54, Col: 9
const char* data, int length
Error: No instance of overloaded function “mts::MTSSerial::read” matches the argument list in “main.cpp”, Line: 22, Col: 17Library code
/** This method enables bulk writes to the Tx or write buffer. This method * blocks until all the bytes are written. * * @param data the byte array to be written. * @param length the length of data to be written from the data parameter. * @returns the number of bytes written to the buffer, which should be * equal to the length parameter since this method blocks. */ int write(const char* data, int length);
My code
#include "mbed.h" #include <iostream> #include "MTSSerial.h" #include "stm32f4xx.h" DigitalOut bc_nce(PB_2); int main() { unsigned char Send_Buffer[160]; int i; bc_nce = 1; mts::MTSSerial sp(D1,D0); sp.baud(1200); for (i=0; i< 10; i++) Send_Buffer[i] = 0xFF; wait(1); int bytes = 10; sp.write(Send_Buffer,bytes); bytes = sp.read(Send_Buffer,160); while (1) { } }
- This topic was modified 8 years, 6 months ago by Will Blight.
May 24, 2016 at 11:39 am #12660Mike FioreBlockedWill,
The prototypes are actually as follows
/** This method enables bulk writes to the Tx or write buffer. This method * blocks until all the bytes are written. * * @param data the byte array to be written. * @param length the length of data to be written from the data parameter. * @returns the number of bytes written to the buffer, which should be * equal to the length parameter since this method blocks. */ int write(const char* data, int length); /** This method enables bulk reads from the Rx or read buffer. This method * blocks until the amount of data requested is received. * * @param data the buffer where data read will be added to. * @param length the amount of data in bytes to be read into the buffer. * @returns the total number of bytes that were read. This should be equal * to the length parameter since this is a blocking call. */ int read(char* data, int length);
I believe the issue is that your buffer is of type unsigned char[], while the write and read functions accept types const signed char[] and signed char[] respectively. Try casting to those types like this
sp.write((const char*)Send_Buffer, bytes); bytes = sp.read((char*)Send_Buffer, 160);
Cheers,
Mike
May 24, 2016 at 1:46 pm #12662Will BlightParticipantHi Mike,
Your are correct. Can’t believe I made such a dumb mistake. I thought I had already changed the types. I am sure 4 hours sleep had nothing to do with it. Someone put more coffee on!Will.
-
AuthorPosts
- You must be logged in to reply to this topic.