19 #ifdef FAUDES_IODEVICE_COMEDI
25 AutoRegisterType<cDevice> gRtiRegisterComediDevice(
"ComediDevice");
28 cDevice::cDevice(
void) : sDevice(), mDev(0) {
29 FD_DHV(
"cDevice(" << mName <<
")::cDevice()");
31 mDefaultLabel =
"ComediDevice";
38 cDevice::~cDevice(
void) {
39 FD_DHV(
"cDevice(" << mName <<
")::~cDevice()");
44 void cDevice::DoWritePreface(TokenWriter& rTw,
const std::string& rLabel,
const Type* pContext)
const {
45 FD_DHV(
"cDevice("<<mName<<
")::DoWritePreface()");
47 sDevice::DoWritePreface(rTw,
"",pContext);
50 sysf.SetBegin(
"DeviceFile");
51 sysf.InsAttribute(
"value",mSystemFile);
57 void cDevice::DoReadPreface(TokenReader& rTr,
const std::string& rLabel,
const Type* pContext){
58 FD_DHV(
"cDevice("<<mName<<
")::DoReadPreface()");
60 sDevice::DoReadPreface(rTr,
"",pContext);
65 if(token.IsString()) {
66 mSystemFile = rTr.ReadString();
75 if(token.IsBegin(
"DeviceFile")) {
76 rTr.ReadBegin(
"DeviceFile", token);
77 mSystemFile=token.AttributeStringValue(
"value");
78 rTr.ReadEnd(
"DeviceFile");
88 void cDevice::Start(
void) {
90 if(mState!=Down)
return;
91 FD_DH(
"cDevice(" << mName <<
")::Start(): open devices");
92 mDev=comedi_open(mSystemFile.c_str());
96 std::stringstream errstr;
97 errstr <<
"cannot open device /dev/comedi0 (inputs)";
98 throw Exception(
"cDevice()::Start()", errstr.str(), 552);
102 for(
int bit=0; bit<=mMaxBitAddress; bit++) {
138 if((!mInputPosEdgeIndexMap[bit].Empty()) || (!mInputNegEdgeIndexMap[bit].Empty())) {
139 if(comedi_data_read(mDev,sub,chan,0,AREF_GROUND,&val)!=1) {
140 std::stringstream errstr;
141 errstr <<
"cannot open device " << mSystemFile <<
": failed to test read from digital input at bit address " << bit;
142 throw Exception(
"cDevice()::Start()", errstr.str(), 552);
149 mComediSubdevs = (mMaxBitAddress / 32) + 1;
150 if(mComediSubdevs<=0) mComediSubdevs=1;
151 mpInputImage =
new ComediInt32[mComediSubdevs];
152 mpOutputImage =
new ComediInt32[mComediSubdevs];
154 for(
int bit=0; bit<32; ++bit) mComediMask[bit] = 0x000000001U << bit;
161 void cDevice::Stop(
void) {
163 if(mState != Up && mState != StartUp)
return;
164 FD_DHV(
"cDevice(" << mName <<
")::Stop()");
172 delete mpOutputImage;
180 bool cDevice::DoReadSignalsPre(
void) {
182 for(
int sub =0 ; sub<mComediSubdevs; ++sub)
183 comedi_dio_bitfield2(mDev, sub, 0, &mpInputImage[sub], 0);
190 void cDevice::DoReadSignalsPost(
void) {
195 bool cDevice::DoReadSignal(
int bit){
203 return (mpInputImage[bit/32] & mComediMask[bit%32]) != 0;
208 bool cDevice::DoWriteSignalsPre(
void) {
return true; }
209 void cDevice::DoWriteSignalsPost(
void) {}
213 void cDevice::DoWriteSignal(
int bit,
bool value){
216 lsampl_t output= (value ? 1 : 0);
217 comedi_data_write(mDev,bit/32,bit%32,0,AREF_GROUND,output);
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
faudes type implementation macros, overall
Hardware access via comedi.
libFAUDES resides within the namespace faudes.