내 모바일에 SM5100b GSM (Rasberry Pi에 연결된 GSM)에서 메시지를 보내려는 다음 코드를 작성했습니다. 그것은 작동하지만 Okcomm, Ok, + CME ERROR : 4, Ok Cutecom 에뮬레이터를 열었을 때만 AT 명령의 결과를 확인할 수 있습니다. 이 코드에 "read"함수를 써서 한 줄씩 컴파일하는 동안 어떻게 결과를 얻을 수 있습니까? 나는 out = read (fd, n, sizeof (n))와 같은 것을 시도했지만 결과가 없었습니다. 나는 Raspian을 데비안 OS와 Codeblocks로 사용하고 있습니다.리눅스에서 C++ 코드로 AT 명령을 읽는 방법
#include <stdio.h> /* Standard input/output definitions */
#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 descriptor for the port */
int n,d,e,f,o,out;
fd = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
/* Could not open the port. */
perror("open_port: Unable to open /dev/ttyAMA0");
}
else
fcntl(fd, F_SETFL, 0);
sleep(2);
n = write(fd, "AT\r\n", 4);
if (n < 0)
fputs("write() of 4 bytes failed!\n", stderr);
sleep(2);
d = write(fd, "AT+CMGF=1\r", 10);
if (d < 0)
fputs("write() of 10 bytes failed!\n", stderr);
sleep(2);
e = write(fd, "AT+CMGS=\"6034****\"\r", 20);
if (e < 0)
fputs("write() of 20 bytes failed!\n", stderr);
sleep(2);
f = write(fd, "hello\r\x1A", 10);
if (f < 0)
fputs("write() of 10 bytes failed!\n", stderr);
sleep(2);
return (fd);
}
int main(void)
{
open_port();
}
"컴파일하는 동안"- 컴파일 타임에 런타임 정보를 검사하려면 어떻게합니까? –
또는 다른 사람에게 위와 같이 결과를 제공합니다. Ok, Ok, Ok, 컴파일 완료시 등. – dali1985