No instance of overload function

Home Forums Dragonfly No instance of overload function

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #12654
    Will Blight
    Participant

    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: 17

    Library 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 7 years, 11 months ago by Will Blight.
    #12660
    Mike Fiore
    Blocked

    Will,

    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

    #12662
    Will Blight
    Participant

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

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.