[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

How to get permissions from code to use serial port

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
BlackRussian
Asked:
BlackRussian
  • 3
1 Solution
 
manish_regmiCommented:
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
 
manish_regmiCommented:
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
 
BlackRussianAuthor Commented:
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
 
manish_regmiCommented:
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now