LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
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
 
LinkBack Search this Thread
Old 07-07-2004, 06:16 PM   #1
SeanatIL
LQ Newbie
 
Registered: Jun 2004
Location: IL
Posts: 24

Rep: Reputation: 15
Serial port communication programming


I am going to use serial port to do some communication stuff. when the program comes to
main()
{
...
open("/dev/ttyS0", O_RDWR|O_NOCTTY );
...
}
programme hangs with output "pemission denied".

What's the problem? Is it because I used wrong device name? How can I know which tty device my serial port is using? My Linux box has a ps2 mouse and a keyboard. and there is one COM port, which I am trying to use.

Thanks,
 
Old 07-07-2004, 06:51 PM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
checkout 'man setserial' for serport info.
 
Old 07-17-2004, 01:02 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,524

Rep: Reputation: 93
Re: Serial port communication programming

Quote:
programme hangs with output "pemission denied".

What's the problem? Is it because I used wrong device name?
No. Obviously, "permission denied" means that the user that runs the program doesn't have permission to open /dev/ttyS0 ...

Running the program as root will most probably not give this error. It's better though to run it as a normal user. To give a normal user permission to open the serial port check what is the group of /dev/ttyS0. On my (Debian) system this is the group "dialout", as you can find out with:
Code:
bash$ ls -l /dev/ttyS0
crw-rw---- 1 root dialout 4, 64 Mar 14 2002 /dev/ttyS0
Then give your user ("hko" in my case) permission to open the device file by making it a member of the group "dialout" (in case of debian) with (as root):
Code:
bash# adduser hko dialout
(Once again: use the username and groupname of your system)
Then re-login as the user and he/she/it will be able to run your program.

Quote:
How can I know which tty device my serial port is using? My Linux box has a ps2 mouse and a keyboard. and there is one COM port, which I am trying to use.
The first serial port on your computer will be /dev/ttyS0, the second /dev/ttyS1...etc. As you only have one, the device file for the serial port will be /dev/ttyS0.
 
Old 07-17-2004, 08:26 PM   #4
osvaldomarques
Member
 
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519

Rep: Reputation: 34
To discover what serial ports are active on your box, as root enter
Code:
/bin/setserial -bg /dev/ttyS?
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
serial port communication prems Linux - Newbie 1 04-17-2005 02:31 AM
Help! Serial Communication Port programming in Assembly(Partial code inside) laksi Programming 4 10-12-2004 01:38 AM
serial port communication vidyaraj Linux - Software 2 03-14-2004 11:32 PM
communication with serial port vidyaraj Linux - Hardware 0 03-09-2004 08:32 PM
serial port communication vidyaraj Linux - Software 6 03-02-2004 06:46 PM


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

Main Menu
 
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
Open Source Consulting | Domain Registration