serijski port in gsm
gdb
gregor.malensek at k2.net
Mon Jan 28 22:20:30 CET 2002
Spesnil sem en programcek, ki naj bi preverjal, ce dobim "OK" odgovor od
modema. Na drugi strani ni navaden modem, ampak je GSM aparat Siemens
M35i.
Problem je v tem, da vedno dobin nazaj "smeti". Prebral sem ze na tone
manualov in FAQ-ov, pa mi zadeva nikakor na zaspila.
Prilagam source, ce bi mi kdo lahko pomagal.
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#define OPEN_ERR 1
#define WRITE_ERR 2
#define READ_ERR 3
int main(int argc, char *argv[])
{
char devfile[30];
struct termios options_new, options_save;
int fd;
int v_ret, i;
char *send_str[50];
char ch[2];
if (argc != 2)
{
printf("usage : test_at device !!!\n");
return 99;
}
sprintf(devfile,"%s%s","/dev/ttyS",argv[1]);
if ((fd = open(devfile, O_RDWR | O_NOCTTY)) < 0) /* | O_NONBLOCK); */
{
close(fd);
return OPEN_ERR;
}
tcgetattr(fd, &options_save);
/* bzero(&options_new, sizeof(options_new)); */
options_new.c_cflag |= B19200;
options_new.c_cflag |= CS8;
options_new.c_cflag |= CLOCAL | CREAD | HUPCL | CRTSCTS;
options_new.c_lflag = 0;
cfsetispeed (&options_new, B19200);
cfsetospeed (&options_new, B19200);
options_new.c_cc[VTIME] = 10;
options_new.c_cc[VMIN] = 0;
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &options_new);
*send_str = "AT\r";
if (write(fd, &send_str, strlen(*send_str)) < strlen(*send_str))
{
tcsetattr(fd, TCSANOW, &options_save);
close(fd);
return WRITE_ERR;
}
i=0;
while (read(fd, &ch, 1) > 0)
{
i += 1;
printf("%s", ch);
}
tcsetattr(fd, TCSANOW, &options_save);
close(fd);
if (i <= 0)
return READ_ERR;
else
return 0;
}
cu
More information about the lugos-prog
mailing list