Solved

How to get permissions from code to use serial port

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

16 Experts available now in Live!

Get 1:1 Help Now