在我们的毕业设计中,我们应该将一个GSM模块(ADH8066)连接到运行嵌入式Linux (Qtopia)的ARM板(OK-6410)上,并与之通信。
当我们第一次操作模块时,它会发送一个“就绪”消息,然后我们可以通过AT命令与它通信。我们已经成功地使用超级终端与它通信,并设法发送了一条简单的SMS。
当我们试图从ARM主板与它通信时,问题就发生了。
我们设法接收到"Ready“消息,但随后没有任何响应。
以下是我们到目前为止开发的代码:
int main(void){
int fd;
char *dev ="/dev/ttySAC3";
struct termios options;
char buffer[20];
char buffer2[20];
char *bufptr;
char *bufptr2;
bufptr = buffer;
bufptr2 = buffer2;
int nbytes,nbytes2=0;
fd = open (dev, O_RDWR | O_NOCTTY);
tcflush(fd, TCIOFLUSH);
tcgetattr(fd, &options);
cfsetispeed(&options, B115200); //Set Baud-rate to 115200
cfsetospeed(&options, B115200);
options.c_cflag |= CLOCAL | CREAD; //Enable the receiver and set local mode
options.c_cflag &= ~PARENB; //No parity (8N1)
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_cflag &= ~CRTSCTS; //Disable hardware flow control
options.c_lflag |= (ICANON | ECHO | ECHOE); //enable input-canonical mode
options.c_iflag = IGNPAR; //Ignore parity errors
options.c_iflag &= ~(IXON | IXOFF | IXANY); //Disable software flow control
options.c_oflag |= OPOST; //enable output-processing mode
tcsetattr(fd, TCSANOW, &options);
printf("Hello GSM\n");
tcflush(fd, TCIOFLUSH);
//capture the "Ready" message
while(1){
nbytes = read(fd, bufptr, 1);
if (0!=strstr(buffer,"Ready")){
printf("\nReady Found!\n");
break;
}
bufptr += nbytes;
}
tcflush(fd, TCIOFLUSH);
// send simple "AT" AT command
int y = write(fd,"AT\r\n",4);
if (y==4)
printf("Written\n");
//trying to capture the "OK" response for the above AT command
while(1){
nbytes2 = read(fd, bufptr2, 1);
perror ("Read error: ");
printf("%c\n",*bufptr2);
}
return 1;
}我们得到的回应是:
Hello GSM
Ready Found!
Written然后它就会阻塞并保持空闲。
如果我们设法捕捉到"Ready“消息,这是否意味着"read”可以正常工作?如果上面打印了"write“,这是否意味着”write“可以正常工作?那么,为什么我们不能与模块通信呢?
谢谢。
发布于 2012-06-29 20:36:16
您能够接收到"Ready“,因为调制解调器发送此消息时没有任何命令。但是当您开始发出ATM命令时,您需要立即接收响应,没有任何延迟,因为Modem会在您发出命令后立即恢复。在这里,您需要运行两个应用程序,一个是发出命令,另一个是接收响应。也可以使用定时器中断或读取串口响应。
https://stackoverflow.com/questions/11001405
复制相似问题