Sponsored Content
Top Forums Programming unable to send read and write serial port Post 302563310 by yashwantkumar on Tuesday 11th of October 2011 01:02:53 AM
Old 10-11-2011
i am using geomeda device .. and opening serail port, mapped in /dev/modem.
i have checked these "AT" commands from terminal.. thats works fine..
i have tested a basic code :-

Code:
int main(int argc,char** argv)
{
        struct termios tio;
        struct termios stdio;
        int tty_fd;
        fd_set rdset;
        unsigned char c='D';
        printf("Please start with %s /dev/ttyS1 (for example)\n",argv[0]);
        memset(&stdio,0,sizeof(stdio));
        stdio.c_iflag=0;
        stdio.c_oflag=0;
        stdio.c_cflag=0;
        stdio.c_lflag=0;
        stdio.c_cc[VMIN]=1;
        stdio.c_cc[VTIME]=0;
        tcsetattr(STDOUT_FILENO,TCSANOW,&stdio);
        tcsetattr(STDOUT_FILENO,TCSAFLUSH,&stdio);
        fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);       // make the reads non-blocking
 

        memset(&tio,0,sizeof(tio));
        tio.c_iflag=0;
        tio.c_oflag=0;
        tio.c_cflag=CS8|CREAD|CLOCAL;           // 8n1, see termios.h for more information
        tio.c_lflag=0;
        tio.c_cc[VMIN]=1;
        tio.c_cc[VTIME]=5;
        tty_fd=open(argv[1], O_RDWR | O_NONBLOCK);
        cfsetospeed(&tio,B115200);            // 115200 baud
        cfsetispeed(&tio,B115200);            // 115200 baud
        tcsetattr(tty_fd,TCSANOW,&tio);
        while (c!='q')
        {
                if (read(tty_fd,&c,1)>0)        write(STDOUT_FILENO,&c,1);              // if new data is available on the serial port, print it out
                if (read(STDIN_FILENO,&c,1)>0)  write(tty_fd,&c,1);                     // if new data is available on the console, send it to the serial port
        }
        close(tty_fd);
}

its working for stdout but if i try to pass "AT" commands using c var. .. its not working properly !
thanx for help !

Last edited by pludi; 10-11-2011 at 03:47 AM..
 

10 More Discussions You Might Find Interesting

1. Programming

serial port reading

Hai there, Can any one provide me with a ansi c source code for opening com1 or com2 and read data. The port is connected to another serial communication device on rs232 port. The o/s is Sco Unix 5.0.6 Matter urgent Viswanath (0 Replies)
Discussion started by: viswanath
0 Replies

2. Solaris

serial port signal

hi i am using solaris 9 on sparc . i was wondering if there was a command to control my serial interface , as to send a signal periodically every interval of time to the input of a 555 timer . thanks for your help .... (0 Replies)
Discussion started by: ppass
0 Replies

3. AIX

Serial port in AIX

Hi, How can i configure my modem in AIX thru serial port (sa0-->tty0) I have two port serial card configured as sa0 I created tty1 which port is tty0 and which port is tty1 how can i know?? (1 Reply)
Discussion started by: pchangba
1 Replies

4. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

5. Shell Programming and Scripting

Need help with serial port

Hi, I have a external board connected to my serial port. I need to execute "shutdown -r now" command when system boot up. When system boots up it requires a username ans password. Then I need to run my command. I can use rc script but that is rebooting system before it asks for username and... (0 Replies)
Discussion started by: charlie.arya
0 Replies

6. Solaris

Unable to access serial port from non-global solaris zone on netra 240

I am trying to use a serial communications device that is connected to /dev/ttyb on a netra 240 server. This is a solaris zone configuration using solaris 10 0910. I am able to access /dev/ttyb from the global zone but not throught he non-global zone. I have enabled all of the tty devices in my... (0 Replies)
Discussion started by: disagreeable
0 Replies

7. Solaris

How to enable Serial port on ILOM, when Network Port is enabled in parallel

Hi Everyone, In my environment, I have few T5220. On the iLOM Management Card, I have both Network and Serial port are cabled, I don't have any issues while I try to connect using Network Management port, but when I try to connect the serial port for the same server which is actually connected... (3 Replies)
Discussion started by: bobby320
3 Replies

8. Programming

Wrong data with Read from a serial port.

hi, I've a problem on my C/C++ program with Posix Library. I have to read data from the serial but I have incorrect data, in fact I get a bunch of zeros: "2953.3174, 2785.2126, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0 , 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ,... (24 Replies)
Discussion started by: enaud
24 Replies

9. Programming

Read from serial port

Hi I try to communicate with a GSM modem, from C, for sending SMS. I use standart AT-commands. Working well with terminal. There is no problem writing ti the port. But when I try to read I only get a echo, I write "ATI" and get "ATI" back, I should get somthing like "SIEMENS 35... (4 Replies)
Discussion started by: dmiller
4 Replies

10. Solaris

Cabling and adapters to communicate to service processor serial port from Windows PC with USB port.

Hello, I have an unloaded T5140 machine and want to access the ILOM for the first time and subsequently the network port after that., and then load Solaris 10 the final January 2011 build. The first part is what confuses me -the cabling. I am coming from a Windows machine (w/appropriate... (5 Replies)
Discussion started by: joboy
5 Replies
cfsetispeed(3C) 					   Standard C Library Functions 					   cfsetispeed(3C)

NAME
cfsetispeed, cfsetospeed - set input and output baud rate SYNOPSIS
#include <termios.h> int cfsetispeed(struct termios *termios_p, speed_t speed); int cfsetospeed(struct termios *termios_p, speed_t speed); DESCRIPTION
The cfsetispeed() function sets the input baud rate stored in the structure pointed to by termios_p to speed. The cfsetospeed() function sets the output baud rate stored in the structure pointed to by termios_p to speed. There is no effect on the baud rates set in the hardware until a subsequent successful call to tcsetattr(3C) on the same termios structure. RETURN VALUES
Upon successful completion, cfsetispeed() and cfsetospeed() return 0. Otherwise -1 is returned, and errno may be set to indicate the error. ERRORS
The cfsetispeed() and cfsetospeed() functions may fail if: EINVAL The speed value is not a valid baud rate. EINVAL The value of speed is outside the range of possible speed values as specified in <termios.h>. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-------------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-------------------------------+ |Interface Stability |Standard | +-----------------------------+-------------------------------+ |MT-Level |MT-Safe, and Async-Signal-Safe | +-----------------------------+-------------------------------+ SEE ALSO
cfgetispeed(3C), tcsetattr(3C), attributes(5), standards(5), termio(7I) SunOS 5.11 24 Jul 2002 cfsetispeed(3C)
All times are GMT -4. The time now is 04:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy