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
Peter Mortensen
31.5k22 gold badges110 silver badges134 bronze badges
asked May 20, 2013 at 12:03
1 Answer 1
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.
answered May 21, 2013 at 22:19
Comments
lang-cpp
\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)