00001 #ifndef ANALOGDETHERCATINPUTDEVICE_HPP
00002 #define ANALOGDETHERCATOUTPUTDEVICE_HPP
00003
00004 #include "rtt/dev/AnalogInInterface.hpp"
00005
00006 namespace RTT
00007 {
00012 struct AnalogEtherCATInputDevice :
00013 public AnalogInInterface
00014 {
00015 unsigned char* mstartaddress;
00016 unsigned int nbofchans;
00017 unsigned int mbin_range;
00018 double mlowest, mhighest;
00019
00020 AnalogEtherCATInputDevice(unsigned char* startaddress, unsigned int channels=2, unsigned int bin_range=4096, double lowest = -5.0, double highest = +5.0)
00021 : AnalogInInterface("AnalogInDevice"),
00022 mstartaddress(startaddress),
00023 nbofchans(channels),
00024 mbin_range( bin_range),
00025 mlowest( lowest),
00026 mhighest( highest)
00027 {}
00028
00029 ~AnalogEtherCATInputDevice() {}
00030
00031 virtual void rangeSet(unsigned int ,
00032 unsigned int ) {}
00033
00034 virtual void arefSet(unsigned int ,
00035 unsigned int ) {}
00036
00037 virtual unsigned int nbOfChannels() const {
00038 return nbofchans;
00039 }
00040
00041 virtual int rawRead( unsigned int chan, unsigned int& value ) {
00042 if (chan < nbofchans) {
00043 unsigned int tmp = mstartaddress[(chan * 3) + 2];
00044 tmp = tmp<<8;
00045 tmp = tmp | mstartaddress[(chan * 3) + 1];
00046 value = tmp;
00047 return 0;
00048 }
00049 return -1;
00050 }
00051
00052 virtual int read( unsigned int chan, double& value ) {
00053 if (chan < nbofchans) {
00054 unsigned int tmp;
00055 read(chan, tmp);
00056 value = 1.0 * tmp * (mhighest - mlowest) / mbin_range + mlowest;
00057 return 0;
00058 }
00059 return -1;
00060 }
00061
00062 virtual unsigned int binaryRange() const
00063 {
00064 return mbin_range;
00065 }
00066
00067 virtual unsigned int binaryLowest() const
00068 {
00069 return 0;
00070 }
00071
00072 virtual unsigned int binaryHighest() const
00073 {
00074 return mbin_range;
00075 }
00076
00077 virtual double lowest(unsigned int ) const
00078 {
00079 return mlowest;
00080 }
00081
00082 virtual double highest(unsigned int ) const
00083 {
00084 return mhighest;
00085 }
00086
00087 virtual double resolution(unsigned int ) const
00088 {
00089 return mbin_range/(mhighest-mlowest);
00090 }
00091
00092 };
00093
00094 }
00095
00096 #endif