MODSERIAL attach help

31 Jan 2014

I am attempting to attach a method to MODSERIAL callback, but it is not working as expected. How do I attach a method to MODSERIAL? My code and errors are listed below.

main file:

#include "mbed.h"
#include "droBot.h"
#include "TextLCD.h"
#include "MODSERIAL.h"
#include <string>

//TextLCD lcd(p15, p16, p25, p24, p23, p22, TextLCD::LCD16x2); // rs, e, d4-d7

MODSERIAL pc(USBTX, USBRX);
MODSERIAL sensor(p13, p14);

droBot drobot(&sensor);

int main() {
    string id = "droBotv1";
    string restemp;
    string ph;
    string ec;
        
    while (1) 
    {
        wait(0.5);
        drobot.getPhValue();
    }
}

.cpp file

#include "mbed.h"
#include "droBot.h"
#include "LinearTempSensor.h"
#include "configFileWrapper.h"
#include "MODSERIAL.h"

//#include "Sensors.h"
//#include "MbedJSONValue.h"

DigitalOut epin(p19);
DigitalOut s0(p21);
DigitalOut s1(p22);

LinearTempSensor tempSensor(p20, 100, LinearTempSensor::MCP9701);

droBot::droBot(MODSERIAL *sensor)
{
    _sensor = sensor;
    _sensor->baud(38400);
    
    epin = 0;
    
    _sensor->attach(&rxCallback, MODSERIAL::RxIrq);
}

void rxCallback(MODSERIAL_IRQ_INFO *q) {
    MODSERIAL *serial = q->serial;
    if ( serial->rxGetLastChar() == '\n') {
        //newline_detected = true;
    }
}

void droBot::enablePhSensor()
{
    s0 = 0;
    s1 = 0;
}

void droBot::getPhValue()
{
    enablePhSensor();
    
    wait(0.2);
    sensor->puts("r\r");
}

char* droBot::getResTempValue()
{
    Vout = tempSensor.Sense();          // Sample data (read sensor)
    Tav  = tempSensor.GetAverageTemp(); // Calculate average temperature from N samples
    To   = tempSensor.GetLatestTemp();  // Calculate temperature from the latest sample

    ftemp = Tav*9/5 + 32;

    sprintf(cVal,"%.2f", ftemp);
    
    //printf("%s\r", cVal);
    return cVal;
}

.h file

#include "mbed.h"
#include "MODSERIAL.h"

class droBot
{
public:
    droBot(MODSERIAL *sensor);
    
    int wifiConnect();
    
    float Vout;
    float Tav;
    float To;
    float ftemp;
    
    char cVal[5];
    char* Tav_str;
    
    void rxCallback(MODSERIAL_IRQ_INFO *q);
    
    void getPhValue();
    float getEcValue();
    char* getResTempValue();
    float getRoomTemp();
    float getRoomHumidity();

    void enablePhSensor();
    void enableEcSensor();
    
private:
    MODSERIAL *_sensor;             //pointer to MODSERIAL object
};

My errors are:

Quote:

Error: Nonstandard form for taking the address of a member function in "droBot/droBot.cpp", Line: 23, Col: 21 Error: No instance of overloaded function "AjK::MODSERIAL::attach" matches the argument list in "droBot/droBot.cpp", Line: 23, Col: 14 Error: Identifier "sensor" is undefined in "droBot/droBot.cpp", Line: 44, Col: 5

31 Jan 2014

I fixed the the Identifier "sensor" is undefined error. The code I changed was sensor->puts("r\r"); to _sensor->puts("r\r"); I forgot the underscore.

As for the first error, I modified the code a little to:

droBot::droBot(MODSERIAL *sensor)
{
    _sensor = sensor;
    _sensor->baud(38400);
    
    epin = 0;
    
    _sensor->attach(&droBot::rxCallback, MODSERIAL::RxIrq); //Changed to this line
}

void droBot::rxCallback(MODSERIAL_IRQ_INFO *q) { //I forgot the droBot:: infront of the method
    MODSERIAL *serial = q->serial;
    if ( serial->rxGetLastChar() == '\n') {
        //newline_detected = true;
    }
}

The new error I received is:

<<quote> Error: No instance of overloaded function "AjK::MODSERIAL::attach" matches the argument list in "droBot/droBot.cpp", Line: 23, Col: 14 <</quote>>

31 Jan 2014

My code seems to compile successfully now. Steps I took:

Deleted the MODSERIAL library from my program. Loaded MODSERIAL from: http://mbed.org/users/Sissors/code/MODSERIAL/ I then changed the attached code to:

_sensor->attach(this, &droBot::rxCallback, MODSERIAL::RxIrq);