[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


How to get permissions from code to use serial port

Posted on 2006-07-14
Medium Priority
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?

When I run this same code under cygwin on a windows machine it works.
Question by:BlackRussian
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Expert Comment

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.)

Manish Regmi

Expert Comment

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


Manish Regmi


Author Comment

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?.

Accepted Solution

manish_regmi earned 800 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

you can just use /dev/ttys0 interface and use open, read, write and ioctl

Manish Regmi

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 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