I have TS-MODEM2 additional board with MultiTech socket modem on it.
The device is recognized at boot procedure. It's visible on
/dev/tty/3. So until this moment everything looks fine. The board is
responding - because I have RTC on it and date is backed up during
power off time.
I tried to send any command: "ATZ\r" and "AT\r" and "AT+WOPEN=1\r" and
modem doesn't seems to respond. Serial settings for /dev/tty/3 are:
baudrate 115200, 8N1. What's wrong? Modem should respond "OK". I got
nothing.
What could be wrong with following code?
Alus
===========
/*
RS simple test
Arkadiusz Lipiec - arkadiusz.lipiec AT NO_SPAM gazeta.pl
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/time.h>
int fd; //! RS file descriptor
int rs_open()
{
struct termios options;
fd = open("/dev/tts/3", O_RDWR | O_NOCTTY | O_NONBLOCK);
if(fd == -1)
{
perror("cannot open port\n");
return fd;
}
fcntl(fd, F_SETFL, FASYNC);
tcgetattr(fd, &options);
bzero(&options, sizeof(options));
options.c_cflag |= (CS8 | B115200 | CREAD | CLOCAL);
// Enable data to be processed as raw input
options.c_lflag &= ~(ICANON | ECHO | ISIG);
options.c_iflag = IGNPAR;
options.c_oflag = 0;
tcflush(fd, TCIFLUSH);
// Set the new options for the port
tcsetattr(fd, TCSANOW, &options);
return 0;
}
// timeout in ms...
int receive_data(int fd, unsigned char* rcvbuffer, int buflen, int
timeout)
{
unsigned long now;
unsigned long diff;
int i=0;
int bytes;
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
now = tv.tv_sec * 1000 + (tv.tv_usec/1000);
diff = 0;
while(diff < (unsigned long) timeout)
{
gettimeofday(&tv, &tz);
diff = ((tv.tv_sec * 1000) + (tv.tv_usec/1000) - now);
ioctl(fd, FIONREAD, &bytes);
if(bytes > 0 && i < buflen)
{
read(fd, rcvbuffer+i, bytes);
i+=bytes;
}
usleep(1);
}
return i;
}
void rs_close()
{
if(fd != -1 && fd != 0)
{ close(fd); }
}
//-----------------------------------------------
int main()
{
int i,j,k;
unsigned char buf[512]; // buffer
if(rs_open() != 0)
{
perror("COM problem\n");
exit(EXIT_FAILURE);
}
j = sprintf(buf, "ATZ\r");
k = write(fd, buf, j);
memset(buf, 0, sizeof(buf));
i = receive_data(fd, buf, sizeof(buf), 3000);
if(i > 0)
{
printf("RESPONSE: %s\n", buf);
}
rs_close();
return 0;
}
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/KIlPFB/vlQLAA/TtwFAA/CFFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|