Can't pass variable to function

18 Jun 2013

Hi

I'm writing a library for SIM900. I've got a function to read a message, but somehow it can't do a simple 'printf' when using additional arguments:

Snippet that doesn't work

char* SIM900::readMessage(char messagenumber)
{
    _serial.printf("AT+CMGR=%c",messagenumber);
    return _atcmdc("\r", "OK\r\n", 2000);
}

the _adcmdc function just sends the "\r" to my serialport, this function work, but I can't pass that darn variable for my function.

Any ideas?

I have tried a lot of different options now, trying to pass chars, char, bytes, everything. From my main I do this:

main.cpp for SIM900

if(strstr(GSM.readMessage('1'), "START1")){
     LED2 = 1;
}

Sniffing the serial port says that the char is not transferred. This is weird or is it me?

Thanks in advance. Lerche

18 Jun 2013

I just made a simple test library that does pretty much the same as what you showed here, and that works fine. So you probably have to cut things out until it does start working. When you replace %c with %d, what does it do then? Show a '0' or nothing?

18 Jun 2013

How did you declare _serial. It looks like a private class member. Perhaps it is not valid, directed at the wrong serial port or using a wrong setting (eg baud). Does it ever succesfully print anything?

19 Jun 2013

Hi

Thanks for the replies. I tested on another mbed, it works perfectly here. Must be my hardware, I'll test it and get back to you as soon as I got results.

Lerche

19 Jun 2013

Erik - wrote:

I just made a simple test library that does pretty much the same as what you showed here, and that works fine. So you probably have to cut things out until it does start working. When you replace %c with %d, what does it do then? Show a '0' or nothing?

I have tried int, char, string, and it works on another board.

Wim Huiskamp wrote:

How did you declare _serial. It looks like a private class member. Perhaps it is not valid, directed at the wrong serial port or using a wrong setting (eg baud). Does it ever succesfully print anything?

The _serial is private, the baudrate is being setup at the start. But thanks for pointing it out. It does print to my terminal, maybe my experiment with highvoltage around this board failed, causing the RAM to fail.

Thanks