0

I wrote this code (using the Code::Blocks IDE) in which I want to send a message for a GSM to my mobile. It includes some AT commands.

The problem is that I have this error in the printf with the AT command "at+cmgf=1". I think that my code is correct. Is there a problem with UTF or the ASCII?

#include <stdio.h> // standard input / output functions
#include <string.h> // string function definitions
#include <unistd.h> // UNIX standard function definitions
#include <fcntl.h> // File control definitions
#include <errno.h> // Error number definitions
#include <termios.h> // POSIX terminal control definitions


int open_port(void)
{
    int fd; // File description for the serial port

    fd = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);

    if(fd == -1) // If open is unsucessful
    {
        printf("open_port: Unable to open /dev/ttyAMA0. \n");
    }
    else
    {
        fcntl(fd, F_SETFL, 0);
        printf("port is open.\n");
    }

    return(fd);
 } //open_port

int configure_port(int fd) // Configure the port
{
    struct termios port_settings; // Structure to store the port settings in

    cfsetispeed(&port_settings, B9600); // Set baud rates
    cfsetospeed(&port_settings, B9600);

    port_settings.c_cflag &= ~PARENB;   // Set no parity, stop bits, data bits
    port_settings.c_cflag &= ~CSTOPB;
    port_settings.c_cflag &= ~CSIZE;
    port_settings.c_cflag |= CS8;

    tcsetattr(fd, TCSANOW, &port_settings); // Apply the settings to the port
    return(fd);
}

void init_gsm()
{
    printf("at+cmgf=1\r\n");
    printf("at+cmgs=\"60*****\"\r\n");
    printf("Hello\r\n%c", 26);
}

int main(void)
{
    int fd = open_port();
    configure_port(fd);
    //query_modem(fd);
    init_gsm();
    return(0);
} //main
4
  • 1
    The code posted does not have that error, could you post the exact code from the editor? Commented May 20, 2013 at 12:12
  • The code as posted does not contain any of the common stray characters (using regular expression \x{00A0}|\x{00AB}|\x{00BB}|\x{2003}|\x{2009}|\x{200B}|\x{200C}|\x{FEFF}|\x{2013}|\x{2014}|\x{2029}|\x{201C}|\x{201D}|\x{2060}|\x{2212}|\x{00E4}|\x{FFFC}|\x{FFFD}|\x{2217}|\x{200C}|\x{202B}|\x{202A}|\x{FF1A}|\x{21B5} - that is for NO-BREAK SPACE, ZERO WIDTH SPACE, ZERO WIDTH NON-JOINER, ZERO WIDTH NO-BREAK SPACE, EN DASH, EM DASH, LEFT DOUBLE QUOTATION MARK, RIGHT DOUBLE QUOTATION MARK, MINUS SIGN, LATIN SMALL LETTER A WITH DIAERESIS, OBJECT REPLACEMENT CHARACTER, REPLACEMENT CHARACTER, etc) Commented May 3, 2023 at 18:31
  • A hex dump is likely to reveal that all bytes are less than 128. Commented May 3, 2023 at 18:33
  • Stray errors are very common errors when copying code from web pages, PDF documents, through chat (e.g. Skype Chat or Facebook Messenger), etc. The canonical question is Compilation error: stray ‘\302’ in program, etc.. Commented May 3, 2023 at 18:46

1 Answer 1

2

The problem with stray '\302' is that the code contains a non-break-space instead of a normal space somewhere.

However fixing that, I see two additional problems which I address here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.