IOAccess.h
См. документацию.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00027
00028 #ifndef _IOACCESS_H_
00029 #define _IOACCESS_H_
00030
00031 #include <unistd.h>
00032 #include <fcntl.h>
00033 #include <iostream>
00034
00035 #include "Exceptions.h"
00036
00045 class IOAccess
00046 {
00047 public:
00048
00050 IOAccess()
00051 {
00052 fd_port = open("/dev/port", O_RDWR | O_NDELAY);
00053 if ( fd_port == -1 )
00054 throw UniSetTypes::IOBadParam();
00055 }
00056
00057 ~IOAccess()
00058 {
00059 close(fd_port);
00060 }
00061
00065 void get(int port, void* buf, int size) const
00066 {
00067 if ( lseek(fd_port, port, SEEK_SET) == -1 )
00068 throw UniSetTypes::IOBadParam();
00069 ssize_t s = read(fd_port, buf, size);
00070 if ( s != size )
00071 throw UniSetTypes::IOBadParam();
00072 }
00073
00075 int in(int port) const
00076 {
00077 char input;
00078 get(port, &input, 1);
00079 return input;
00080 }
00081
00085 void put(int port, const void* buf, int size) const
00086 {
00087 if ( lseek(fd_port, port, SEEK_SET) == -1 )
00088 throw UniSetTypes::IOBadParam();
00089 ssize_t s = write(fd_port, buf, size);
00090 if ( s != size )
00091 throw UniSetTypes::IOBadParam();
00092 }
00093
00095 void out(int port, int value) const
00096 {
00097 char output = value;
00098 put(port,&output,1);
00099 }
00100
00101 private:
00102
00104 int fd_port;
00105
00106 };
00107
00108 #endif