LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-10-2009, 10:02 AM   #1
nathan
LQ Newbie
 
Registered: Aug 2009
Location: california
Distribution: fedora
Posts: 21

Rep: Reputation: 15
sending AT commands to wavecom through C code


Hi all,

I am testing sending sms through wavecom modem.

I tested with minicom, its responding correctly..

commands are
AT
OK

AT+CMGS="mobilenum" (then press Enter key)
>"message" (then press ctrl+z)

its sending sms properly.

Same thing i want to implement using a code.

I am able to open serial port and done initialization


now i want to send AT COMMANDS to wavecom modem using C code.

can any one provide sample code for this.(In this how to include Enter key and Ctrl+z keys.)



Thanks in advance


nathan
 
Old 08-10-2009, 03:31 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,343

Rep: Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905
Quote:
Originally Posted by nathan View Post
Hi all,

I am testing sending sms through wavecom modem.
I tested with minicom, its responding correctly..
commands are
AT
OK

AT+CMGS="mobilenum" (then press Enter key)
>"message" (then press ctrl+z)

its sending sms properly.
Same thing i want to implement using a code.
I am able to open serial port and done initialization
now i want to send AT COMMANDS to wavecom modem using C code.
can any one provide sample code for this.(In this how to include Enter key and Ctrl+z keys.)
We'll be glad to help you with what you've written. Post what you've written so far, along with what error(s) you're getting, and some information about your hardware and version/distro of Linux, and we can help.

But I doubt that anyone is going to write code for you...also, there is LOTS of sample code on the Internet, for serial communication. Have you checked?
 
Old 08-11-2009, 10:27 AM   #3
nathan
LQ Newbie
 
Registered: Aug 2009
Location: california
Distribution: fedora
Posts: 21

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by TB0ne View Post
We'll be glad to help you with what you've written. Post what you've written so far, along with what error(s) you're getting, and some information about your hardware and version/distro of Linux, and we can help.

But I doubt that anyone is going to write code for you...also, there is LOTS of sample code on the Internet, for serial communication. Have you checked?

Hi,

Here i am pasting my code.
1).

I am using read and write commands? is it proper way of using ?
any other method, instead of using read and write commands?

kindly suggest me where i went wrong.

int main()
{
unsigned char char1[10];
unsigned char char_buf[8]="AT+CSQ\n";
// unsigned char sms_buf[20] = "AT+CMGS="xxxxxxxxx";

int wc_fd;
/********* Init of serial port ************/
wc_fd = init_wc(wc_fd);
sleep(3);
//writing to serial port
write(wc_fd,char_buf,sizeof(char_buf));
usleep(40000);
//reading from serial port
read(wc_fd,char1,sizeof(char1));

sleep(2);
close(wc_fd);

return 0;
} // end of main

// initialization of serial port

struct termios options;

ttys5_fd = open("/dev/ttyS5", O_RDWR );
if (ttys5_fd < 0)
{
printf("\nFail to open serial port 2\n");
return 0;
}
init_tty( ttys5_fd ,BAUD_RATE);
return ttys5_fd;

-----------------------------------
//initializing baud rate
int init_tty( int fd ,long wBaud)
{

long baud;

switch (wBaud)
{
case 9600:
baud = B9600;
break;
case 19200:
baud = B19200;
break;
case 38400:
baud = B38400;
break;
case 57600 :
baud = B57600;
break;
case 115200:
baud = B115200;
break;
default:
return 0;
break;
}

options.c_cflag = baud | CS8 | CREAD | CLOCAL;

options.c_cflag &= ~HUPCL;
options.c_lflag = 0;

options.c_iflag = IGNPAR;

options.c_oflag = 0;
options.c_cc[VTIME] = 0;

options.c_cc[VMIN] = 0;

tcflush(fd, TCIFLUSH); /* flush the buffer */

/* apply the settings */
if(tcsetattr(fd, TCSANOW, &options) < 0){ /* apply the settings */
printf("initport: Error in setting serial port params in non-canonical mode\n");
return (-1);
}
else{
return 1;
}
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending AT commands to a SMS modem narmida Linux - Hardware 2 09-24-2009 02:05 PM
Sending HP Printer Commands cmnorton Programming 2 12-10-2007 08:58 AM
sending at commands over pppoe? sti2envy Linux - Networking 3 10-18-2005 07:35 AM
sending windows commands from linux dubman Linux - Networking 1 11-13-2003 08:34 PM
sending telnet commands non-interactively JustinHoMi Linux - Networking 4 09-29-2001 02:20 PM


All times are GMT -5. The time now is 05:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration