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
Solved

How to get permissions from code to use serial port

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
LDAP server on Linux Redhat 6 2 510
Need bundled ATFTP tool for use with ESXi 4 95
whats a headless user in linux 3 314
what does getent do 3 52
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 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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 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