0

I am trying to send AT commands to a Telit modem from C. Simply interfacing with the modem through system() calls works fine, but there are some issues that arise when I try to transfer a python script with AT#WSCRIPT. The ">>>" portion also gets transferred into the chip, corrupting the script.

Anyway, so I am now trying to do it within C using termios library. The problem is, I can only send the chip one "AT" command, it responds with an OK and every attempt to send another AT commands results in an ERROR response. Further, after runnning my C code, I can't interface with the chip even through the terminal. I suspect something is off about the termios configuration, which is listed below.

Any ideas? Thanks

char command[] = "AT\r\n";
fd = open(serialport, O_RDWR | O_NOCTTY | O_NDELAY);
termios_config.c_cflag &= ~PARENB;
termios_config.c_cflag &= ~CSTOPB;
termios_config.c_cflag &= ~CSIZE;
termios_config.c_cflag |= CS8;
termios_config.c_cflag &= ~CRTSCTS;
termios_config.c_cflag |= CREAD | CLOCAL;
termios_config.c_cflag &= ~(IXON | IXOFF | IXANY);
termios_config.c_cflag &= ~(ICANON | ECHO | ECHOE | ISIG);
termios_config.c_cflag &= ~OPOST;
tcsetattr(fd, TCANOW, &termios_config);
write(fd, send_str, strlen(send_str));
Dark
  • 323
  • 2
  • 5
  • 13
  • @FiddlingBits Just to the modem, I'm just stuck trying to send multiple "AT" commands, but if you know of another way to send a script that I can do using system() calls, that would be a much simpler solution. – Dark Aug 26 '16 at 19:27
  • The `c_cflag |= ~CREAD | CLOCAL` looks suspect. `~CREAD` means all bits _except_ `CREAD`, so adding `CLOCAL` is superfluous. This might be either `c_cflag &= ~CREAD; c_flag |= CLOCAL;` or `c_cflag |= CREAD | CLOCAL` or something else depending upon whether you want `CREAD` and/or `CLOCAL` on/off – Craig Estey Aug 26 '16 at 19:39
  • @CraigEstey Actually that was a typo when posting the question. Actual line is c_cflag |= CREAD | CLOCAL. – Dark Aug 26 '16 at 20:37
  • 1
    You are writing `send_str`, not the `char command[]` that is listed in your code excerpt. Is that what you mean to do? – Tim Aug 26 '16 at 22:07
  • Btw, you should terminate an AT command line with only `\r` and nothing else, see [this answer](http://stackoverflow.com/a/21503919/23118). – hlovdal Aug 26 '16 at 22:39
  • 1
    Your code doesn't show it, so how did you initialize the termios_config structure...??? If you didn't initialize it, that could be "a" problem (if not "the" problem). – TonyB Aug 26 '16 at 23:28

0 Answers0