MODSERIAL, attach with member methods not working

09 May 2011

Hello All,

I am trying to use MODSERIAL in one of my drivers and cant seem to get the attach to happen when setting up a callback to a member method

void Driver::uartRead(MODSERIAL_IRQ_INFO *) {
    _pc->putc(_uart.getc());
    rxLed =! rxLed;
}

Driver::Driver(PinName tx, PinName rx, Serial* pc) : _uart(tx, rx) {
    _pc = pc;
    
    _uart.baud(DEFAULT_BAUD);
    _uart.attach(this, &Driver::uartRead, MODSERIAL::RxIrq);

    // make sure we are not in config mode!
    _uart.printf("Q%s",LINE_END);
}

Which gives me the compile time error. "No instance of overloaded function "AjK::MODSERIAL::attach" matches the argument list (E304)

Since I am new to CPP I am having a hard time locating the issue or is it simply a bug in MODSERIAL?

Thanks for any pointers, Serge

09 May 2011

Note, in the latest version the function prototype for the callback has changed from void funcname(void); to void funcname(MODSERIAL_IRQ_INFO *q);. See the docs and examples.

edit: if it's not working as expected, make sure you are using the latest library.

09 May 2011

Got it ...

Actually its connect and not attach in this case ... my bad.

Thanks, Serge

09 May 2011

I think this is what you are looking for:-

void Driver::uartRead(MODSERIAL_IRQ_INFO *q) {
    MODSERIAL *s = q->serial;
    s->putc(_uart.getc());
    rxLed =! rxLed;
}

// ** OR **

void Driver::uartRead(MODSERIAL_IRQ_INFO *q) { // NOTE, you still need the "q" even if not used.
    _pc->putc(_uart.getc());
    rxLed =! rxLed;
}


Driver::Driver(PinName tx, PinName rx, Serial* pc) : _uart(tx, rx) {
    _pc = pc;
    
    _uart.baud(DEFAULT_BAUD);
    _uart.attach(this, &Driver::uartRead, MODSERIAL::RxIrq);

    // make sure we are not in config mode!
    _uart.printf("Q%s",LINE_END);
}

09 May 2011

Serge Sozonoff wrote:

Actually its connect and not attach in this case

Oh, connect() is just supposed to be an alias of attach(). Maybe I missed something when adding the new callback system. I'll have a look.

10 May 2011

Fixed in v1.21 (just released). Thx.

10 May 2011

Thx Andy,

Confirmed ok.

16 Jan 2012

Right, the documentation should be fixed to match the library - it still specifies a void parameter for the callback function.

11 Dec 2012

Hello Andy,

I am getting compiler error on lines 61 and 68 in INIT.cpp:

"no instance of overloaded function "mbed::Serial::attach" matches the argument list" in file "MODSERIALINIT.cpp", Line: 61, Col: 66

I am using v27 of MOSERIAL and v53 of mbed.lib

thanks, ...kevin

12 Dec 2012

This was more a very old topic regarding a problem, see the cookbook page: http://mbed.org/cookbook/MODSERIAL (but yeah you were the first to report this one).