Hardware I/O Port
Hardware I/O Port
Hi All
I have converted a fairly large project from XPe to Linux, but before I tell the customer that I can do this
there is no way for me to test my hardware I/O ports.(because I dont have an ISA bus or I/O board)
For example:
ISA Bus
Plug in I/O board at &H1B0 address
First I/O bit would be turned on in
Dos
Out &H1b0,1
In XPe
InitializeWinIo (a library)
Out &H1b0,1
However what would be the equivalent in Linux ?
Regards
I have converted a fairly large project from XPe to Linux, but before I tell the customer that I can do this
there is no way for me to test my hardware I/O ports.(because I dont have an ISA bus or I/O board)
For example:
ISA Bus
Plug in I/O board at &H1B0 address
First I/O bit would be turned on in
Dos
Out &H1b0,1
In XPe
InitializeWinIo (a library)
Out &H1b0,1
However what would be the equivalent in Linux ?
Regards
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: Hardware I/O Port
Hi All
D.J Peters thanks for the response.
I had already spent a lot of time browsing but came to an obstacle.
Print ioperm(&H1B0, 16, 1) will return -1 if not at Root and 0 when the program is executed as Root.
However my problem is how to get in & out of root before and after the IOPerm statement.
Hopefully without "Shell". It is written that once you have issued the IOPerm statement you can revert back to user level.
Is there a way to use SetUID from within my application, and what are the declare statements.
Most of the browsing shows that a certain ".h" file has to be included, but that that doesn't work in FB of course.
Regards
Edit: I guess another way is to start the Program as Root, then once the IOPerm calls are done, call SetUid to cancel Root.
Edit2: The other question that I cant find an answer to is: Does the calling program have to stay in privileged mode to allow the IO ?
D.J Peters thanks for the response.
I had already spent a lot of time browsing but came to an obstacle.
Print ioperm(&H1B0, 16, 1) will return -1 if not at Root and 0 when the program is executed as Root.
However my problem is how to get in & out of root before and after the IOPerm statement.
Hopefully without "Shell". It is written that once you have issued the IOPerm statement you can revert back to user level.
Is there a way to use SetUID from within my application, and what are the declare statements.
Most of the browsing shows that a certain ".h" file has to be included, but that that doesn't work in FB of course.
Regards
Edit: I guess another way is to start the Program as Root, then once the IOPerm calls are done, call SetUid to cancel Root.
Edit2: The other question that I cant find an answer to is: Does the calling program have to stay in privileged mode to allow the IO ?
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: Hardware I/O Port
directly access (as none driver) hardware is a security hole so it must be done with root rights !
I thing (but i'm not sure) a normal user can use /dev/parport0 /dev/lpt0 ... to access the lpt ports as file
1 On the Linux host system, use the ls command to determine the owner and group for the device.
For example: ls –la /dev/parport0
The third and fourth columns of the output show the owner and group, respectively. In most cases, the owner of the device is root and the associated group is lp.
2 To add the user to the device group, become root and open the /etc/group file in a text editor.
3 On the line that defines the lp group, add the Workstation username.
For example: lp::7:daemon,lp,username
Joshy
I thing (but i'm not sure) a normal user can use /dev/parport0 /dev/lpt0 ... to access the lpt ports as file
1 On the Linux host system, use the ls command to determine the owner and group for the device.
For example: ls –la /dev/parport0
The third and fourth columns of the output show the owner and group, respectively. In most cases, the owner of the device is root and the associated group is lp.
2 To add the user to the device group, become root and open the /etc/group file in a text editor.
3 On the line that defines the lp group, add the Workstation username.
For example: lp::7:daemon,lp,username
Joshy
Last edited by D.J.Peters on Dec 26, 2016 21:18, edited 1 time in total.
Re: Hardware I/O Port
Hi All
However the hardware is not a LPT port, it is a digital I/O board.
Would that work by simply changing the address as if it was an LPT port.
Like instead of &h378 let it be &H1b0
REgards
However the hardware is not a LPT port, it is a digital I/O board.
Would that work by simply changing the address as if it was an LPT port.
Like instead of &h378 let it be &H1b0
REgards
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: Hardware I/O Port
sorry I was meant IO port = LPT
my fault :-(
why not ask the manufacturer to solve your problem ?
Joshy
my fault :-(
why not ask the manufacturer to solve your problem ?
Joshy
Re: Hardware I/O Port
Hi All
Joshy
I am the manufacturer of the equipment, and write the software to control it.
Regards
Joshy
I am the manufacturer of the equipment, and write the software to control it.
Regards
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: Hardware I/O Port
then write a linux driver that can use any user without root rights
what are the problem there are many examples in the kernel tree ?
Joshy
what are the problem there are many examples in the kernel tree ?
Joshy
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: Hardware I/O Port
Linux Device Drivers Training 01, Simple Loadable Kernel Module
https://www.youtube.com/watch?v=Zn8mEZX ... freload=10
Linux Device Drivers Training 02, module_init() and module_exit()
https://www.youtube.com/watch?v=IiHrZcZ ... freload=10
Linux Device Drivers Training 03, Modules from Multiple C Files, MODULE_LICENSE(), __init
https://www.youtube.com/watch?v=78YkQ4K ... freload=10
Linux Device Drivers Training 04, Exporting Symbols
Linux Device Drivers Training 05, Module Parameters
...
https://www.youtube.com/watch?v=Zn8mEZX ... freload=10
Linux Device Drivers Training 02, module_init() and module_exit()
https://www.youtube.com/watch?v=IiHrZcZ ... freload=10
Linux Device Drivers Training 03, Modules from Multiple C Files, MODULE_LICENSE(), __init
https://www.youtube.com/watch?v=78YkQ4K ... freload=10
Linux Device Drivers Training 04, Exporting Symbols
Linux Device Drivers Training 05, Module Parameters
...
Re: Hardware I/O Port
Hi All
Thank you Joshy, some reading to do.
REgards
Thank you Joshy, some reading to do.
REgards
Re: Hardware I/O Port
I'm not convinced that a linux kernel driver is necessary nor desired.
In CNC applications it's common to interface with controllers via a parallel-port, and this can be accomplished without root, provided the /dev/lp# entry has read and write perms for normal users. I believe you can read and write to signals in a manner similar to how you describe in Windows.
Another possible solution is to use a USB to general-purpose i/o adapter and use libusb to communicate with it, requiring no drivers whatsoever. How many digital logic signals do you need to work with and do you require special, strict timing on those signals? Do you need interrupt routines to fire on a signal changing or can you poll for the signal change from your application?
In CNC applications it's common to interface with controllers via a parallel-port, and this can be accomplished without root, provided the /dev/lp# entry has read and write perms for normal users. I believe you can read and write to signals in a manner similar to how you describe in Windows.
Another possible solution is to use a USB to general-purpose i/o adapter and use libusb to communicate with it, requiring no drivers whatsoever. How many digital logic signals do you need to work with and do you require special, strict timing on those signals? Do you need interrupt routines to fire on a signal changing or can you poll for the signal change from your application?
Re: Hardware I/O Port
Hi All
caseih thanks for your reply.
So far I have concluded that if I start my program as Root, then using "IOPerm(&H1B0,16,1)" the ports seem to be accessible.
By using "Shell su newuser" I can cancel the Root user, which according to the docs will then still allow the port IO.
However that is not the cleanest solution.
Basically I am fixed with hardware, the system already exists and the purpose of the exercise is to evaluate if I can
convert from XPe to Linux. The cpu boards used are becoming obsolete, and there is a need to replace them and thus the need to go to Linux.
There are in fact 5 x 48 bit I/O boards with Timer/counters in this particular installation. WinXPe demands new licenses for the new cpu boards, plus the
fact that new compact flash images have to be created.
REgards
caseih thanks for your reply.
So far I have concluded that if I start my program as Root, then using "IOPerm(&H1B0,16,1)" the ports seem to be accessible.
By using "Shell su newuser" I can cancel the Root user, which according to the docs will then still allow the port IO.
However that is not the cleanest solution.
Basically I am fixed with hardware, the system already exists and the purpose of the exercise is to evaluate if I can
convert from XPe to Linux. The cpu boards used are becoming obsolete, and there is a need to replace them and thus the need to go to Linux.
There are in fact 5 x 48 bit I/O boards with Timer/counters in this particular installation. WinXPe demands new licenses for the new cpu boards, plus the
fact that new compact flash images have to be created.
REgards
Re: Hardware I/O Port
I think setuid() is what you're looking for.Dinosaur wrote: So far I have concluded that if I start my program as Root, then using "IOPerm(&H1B0,16,1)" the ports seem to be accessible.
By using "Shell su newuser" I can cancel the Root user, which according to the docs will then still allow the port IO.
However that is not the cleanest solution.
Regards
Re: Hardware I/O Port
Hi All
After lots of trials, the following works in Terms of the Code.
But I have not actually confirmed it working on a system with an addressable I/O board.
In a Root Terminal give the program RawIO capabilities:setcap means set capabilities.
e Meaning Effective User
p Meaning Permission
To confirm the capabilities:If it prints 0 (zero) then success, -1 = Failure.
Would dearly love someone with the hardware to prove this for me.
Even just an LPT port.
Regards
After lots of trials, the following works in Terms of the Code.
But I have not actually confirmed it working on a system with an addressable I/O board.
In a Root Terminal give the program RawIO capabilities:
Code: Select all
setcap cap_sys_rawio=ep MyExecutable
e Meaning Effective User
p Meaning Permission
To confirm the capabilities:
Now in my code:getcap MyExecutable 'will print the following
MyExecutable = cap_sys_rawio+ep
Code: Select all
Declare Function ioperm Cdecl Alias "ioperm" (Byval Portbase As Integer,Byval nPorts As Integer,Byval value As Integer) As Integer
Print ioperm(&H140, 16, 1)
Would dearly love someone with the hardware to prove this for me.
Even just an LPT port.
Regards