Can read from /dev/ttyS0, but not write?
Hello,
I have a Siemens C45 GSM connected to my serial port. I can play with its modem using the AT commands via minicom. I want to bypass minicom and use the serial modem in my own scripts/programs. I've run simple experiments and it seems I can only read from /dev/ttyS0, but not write. I've tried in bash: Code:
### write session I've tried in C: Code:
fp = fopen(serial, "rw"); Code:
BUF: Here are the device permissions: Code:
$ ls -l /dev/ttyS0 |
For starters, in your C code, try
Code:
fp = fopen("/dev/ttyS0", "rw"); Have you studied Serial Programming Guide for POSIX Operating Systems, or Serial Programming HOWTO? These have working code that can be used as the basis for your application. --- rod. |
Oh, I forgot to complete the copy-paste from the code :) I have that in variable declarations:
Code:
char *serial = "/dev/ttyS0"; ----------------------------------------------------------------------------------- I've tried some source from these links, like that: Code:
#include <stdio.h> /* Standard input/output definitions */ Reading is not fine too - read() returns only about 8 characters at once and sometimes I see only garbage: Code:
Sent: AT+CLIP=1 I think I should not set anything in special (baud rate, flow control, etc), becouse minicom is communicating well enough without special settings. |
Quote:
BTW, what evidence is telling you that writes are not happening? --- rod. |
Quote:
|
Perhaps you need to flush the output buffer, &/or append a linefeed &/or carriage return to your output string.
--- rod. |
I've tried sending "command" as well as "command\n", "command\r" and combinations of both.
Quote:
|
Okay, a few other ideas. The serial port may be inhibited from sending without the presence of the required signals on modem control lines. This can be over-ridden with the correct settings either in termios (see in particular CLOCAL & CRTSCTS, maybe more) or using stty, or may be supplied using a properly configured cable.
Since this is evidently a modem that you are talking to, I wouldn't expect it to matter, but perhaps 'command\r\n' or 'command\n\r' are worth a try. --- rod. |
All times are GMT -5. The time now is 07:02 PM. |