Solved

How to get permissions from code to use serial port

Posted on 2006-07-14
4
258 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 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