LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-24-2012, 09:08 AM   #1
batman4
Member
 
Registered: Jul 2012
Posts: 47

Rep: Reputation: Disabled
opening a comport in linux


pls help
i am not able to open the comport in linux
the code is giving error that port cannot be opend

[code[
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <string.h>
#include <errno.h>



int main()
{
int fd; /* File descriptor for the port */

fd = open ("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd < 0)
{ /* Could not open the port */
fprintf (stderr, "open_port: Unable to open /dev/ttyS1 - %s\n",
strerror (errno));
printf("error in opening com port\n");
return 0;
}
else
return (fd);
}


}

[/code]

Last edited by batman4; 09-24-2012 at 09:20 AM.
 
Old 09-24-2012, 09:15 AM   #2
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,159

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
please edit your post and fix the [code[ line (at the beginning)
Can you tell us the error message you got?
do you really want to open /dev/ttyS1111?
 
Old 09-24-2012, 09:21 AM   #3
batman4
Member
 
Registered: Jul 2012
Posts: 47

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
please edit your post and fix the [code[ line (at the beginning)
Can you tell us the error message you got?
do you really want to open /dev/ttyS1111?
DONE
 
Old 09-24-2012, 09:35 AM   #4
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,455

Rep: Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172
For one thing ... you almost always want to use a communication-protocol library that will get you as close as possible to the finishing-point of the job that you are trying to do. IMHO, if you are thinking "way down at the device level," you're probably creating far too much work for yourself in most cases. That's why there is such a booming business in the manufacture of prefabricated building-parts, like doors and windows.
 
Old 09-24-2012, 10:12 AM   #5
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 3,220

Rep: Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154Reputation: 1154
Make sure the user that's running this code has permission to access the device. You could attempt to open it with minicom to confirm.
 
  


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
Starnge behavior of bash or comport Mabbus Programming 5 03-31-2008 10:03 AM
How to detect the ComPort in the minicom Nishant Desai Linux - Hardware 2 01-31-2007 12:32 AM
Why is my ComPort not accepting the data, I am writing? maheshnimje Linux - Networking 2 05-09-2006 12:38 AM
comport communication neerukamra Linux - General 0 09-06-2004 01:18 AM
comport? kalleanka Programming 4 02-24-2004 04:36 AM


All times are GMT -5. The time now is 03:17 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration