Hello,
I am writing a C program to enable my modem for caller id and extract the data. However, when I send some data to the modem, nothing happens, even though I have got a connection with the modem? I am compiling this under Suse Linux 8.2 using Kdevelop 2.1. If I use Hyperterminal under windows, I can enter the same commands and get the caller id from the modem when the phone rings. I am using a baud rate of 2400 when I use hyperterminal - the same in my program. I do not know why it is not working??? I know there are problems in the code (an infinite loop), but I just want to be able to send the stringsto the modem and get that working first!
Any help would be appreciated with this problem.
Kind Regards,
David.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#define BAUDRATE B2400
#define SERIALPORT "/dev/ttyS0" // I have got rw access to this port.
int main()
{
int openPortResult, readResult, output;
struct termios newTio;
char tempBuffer[100];
printf ("\n going to open modem device ....\n");
openPortResult = open(SERIALPORT, "w+");
if (openPortResult < 0)
{
perror(SERIALPORT);
exit(-1);
}
printf("\nmodem device %d\n", openPortResult); // OpenPortResult is assigned the value of 9
tcgetattr(openPortResult,&
newTio);
newTio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD | HUPCL;
newTio.c_iflag = IGNBRK | IGNPAR;
output = tcsetattr(openPortResult,T
CSANOW,&ne
wTio);
printf("\nsetting serial port details... value: %d\n", output); //output displays value of 0.
output = write (openPortResult, "AT");
printf("\nAT output is: %d\n", output); //output = -1 - I cannot ping the modem!
output = write (openPortResult, "ATZ");
printf("\nATZ output is: %d\n", output); //output = -1
output = write (openPortResult, "AT+GCI=B4");
printf("\nAT+GCI=B4 output is: %d\n", output); //output = -1
output = write (openPortResult, "AT+VCID=1");
printf("\nAT+VCID=1 output is: %d\n", output); //output = -1
//Infinite loop - just trying to get it to display something (not -1)
while (1)
{
readResult = read(openPortResult, tempBuffer, 100);
tempBuffer[readResult]=0;
printf(":%s:%d\n", tempBuffer, readResult); //yep you guessed it -1 again!
}
output = close(SERIALPORT); //will never be called!
return 0; //will never return.
}