Solved

How to get permissions from code to use serial port

Posted on 2006-07-14
4
257 Views
Last Modified: 2012-05-05
I writing code to talk out the com port ttys0. When I run this code I am unable to open a port and get back a -1 from the open command. I've been told that under linux i need to somehow get permission from within my code to use the port. I'm tried excuting loggged in as root and still bo luck. Can anyone help?

NOTE:
When I run this same code under cygwin on a windows machine it works.
0
Comment
Question by:BlackRussian
  • 3
4 Comments
 
LVL 8

Expert Comment

by:manish_regmi
ID: 17108878
You can easily use open, read, write and ioctl. The  permission bits in the device file needs to be arranged first.

you can grant the permission by issuing
chmod o+rw /dev/ttyS0


But you need to call ioperm(), if you are directly accessing hardware (like direct port programming.)

regards
Manish Regmi
0
 
LVL 8

Expert Comment

by:manish_regmi
ID: 17108900
If you are into I/O port programming, This howto is worth reading

http://www.faqs.org/docs/Linux-mini/IO-Port-Programming.html

regards
Manish Regmi

0
 

Author Comment

by:BlackRussian
ID: 17110032
Hi manish. The article shows using I/O ports. Do need to know what port 0x.. my serial port is to use this ?. is there a way to use /dev/ttys0 as a parameter?.
0
 
LVL 8

Accepted Solution

by:
manish_regmi earned 200 total points
ID: 17110159
You need that only if you are accessing hardware directly. But the Linux kernel already have a serial device driver. You might not need to use it.

if you are interested see the serial port specs here
http://www.nondot.org/~sabre/os/articles/CommunicationDevices/

you can just use /dev/ttys0 interface and use open, read, write and ioctl
http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/

regards
Manish Regmi
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now