Using mbed api in own class

14 Aug 2011

Hi,

I want to use the serial API in my own class, but I can't get this to work. What am I doing wrong?

status.cpp:

#include "status.h"

Status::Status(Roer * r, Zeil * z){
    roer = r;
    zeil = z;
    
    
    zender.baud(9600);
    zender.attach(&Status::newData);
}

void Status::newData(void) {

    //buffer variables
    char lezen;

    //if data is ready in the buffer
    while (zender.readable()) {
        //read 1 character
        lezen = zender.getc();

        //if character is $ than it is the start of a sentence
        if (lezen == '$') {
            //so the pointer should be set to the first position
            plaats = 0;

        }
        //write buffer character to big buffer string
        buffer_recv[plaats] = lezen;

        //if the character is # than the end of the sentence is reached and some stuff has to be done
        if (lezen == '#') {
            zender.putc('A');
        }
    }

}

status.h:

#ifndef STATUS_H
#define STATUS_H

#include "roer.h"
#include "zeil.h"

#include "mbed.h"

class Status{

    Serial zender(p13,p14);
    
    Roer * roer;
    Zeil * zeil;
    
    char buffer_recv[128];
    int plaats;
    
    void newData(void);
    
    public:
        Status(Roer *, Zeil *);
        
        
};

#endif

The error is:

"constant "p13" is not a type name" in file "status.h/<a href="#" onClick="window.open('/cookbook/Compiler-Error-757');">757</a>"
"constant "p14" is not a type name" in file "status.h/<a href="#" onClick="window.open('/cookbook/Compiler-Error-757');">757</a>"
"nonstandard form for taking the address of a member function" in file "status.cpp/<a href="#" onClick="window.open('/cookbook/Compiler-Error-504-D');">504-D</a>"
"expression must have class type" in file "status.cpp/<a href="#" onClick="window.open('/cookbook/Compiler-Error-153');">153</a>"
etc.
14 Aug 2011

Never mind, problem solved. The working code:

#include "status.h"

Status::Status(Roer * r, Zeil * z) : zender(p13,p14){
    roer = r;
    zeil = z;
    
    
    zender.baud(9600);
    zender.attach(this, &Status::newData);
}

void Status::newData(void) {

    //buffer variables
    char lezen;

    //if data is ready in the buffer
    while (zender.readable()) {
        //read 1 character
        lezen = zender.getc();

        //if character is $ than it is the start of a sentence
        if (lezen == '$') {
            //so the pointer should be set to the first position
            plaats = 0;

        }
        //write buffer character to big buffer string
        buffer_recv[plaats] = lezen;

        //if the character is # than the end of the sentence is reached and some stuff has to be done
        if (lezen == '#') {
            zender.putc('A');
        }
    }

}