gdm703.cpp

Go to the documentation of this file.
00001 //======================================================================
00002 // File:        gdm703.cpp
00003 // Author:      Matthias Toussaint
00004 // Created:     Tue Nov 28 08:24:21 CET 2006
00005 // Project:     QtDMM
00006 // Description: Encapsulates a DMM class (protokoll)
00007 //----------------------------------------------------------------------
00008 // This file  may  be used under  the terms of  the GNU  General Public
00009 // License  version 2.0 as published   by the Free Software  Foundation
00010 // and appearing  in the file LICENSE.GPL included  in the packaging of
00011 // this file.
00012 // 
00013 // This file is provided AS IS with  NO WARRANTY OF ANY KIND, INCLUDING 
00014 // THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00015 // PURPOSE.
00016 //----------------------------------------------------------------------
00017 // Copyright 2006 Matthias Toussaint
00018 //======================================================================
00019 
00020 #include <gdm703.h>
00021 
00022 #include <iostream>
00023 
00024 GDM703::GDM703() :
00025   DMMClass()
00026 {
00027   setNumValues( 2 );
00028 }
00029 
00030 GDM703::~GDM703()
00031 {
00032   m_port.close();
00033 }
00034 
00035 Port::Error GDM703::open_impl( const std::string & config )
00036 {
00037   return m_port.open( config );
00038 }
00039 
00040 Port::Error GDM703::close()
00041 {
00042   return m_port.close();
00043 }
00044 
00045 void GDM703::setAscii( int start, int modeLen, 
00046                            const std::string & str, int index )
00047 {
00048   m_mutex.lock();
00049       
00050   double value;
00051   Util::fromString( &value, 
00052                      Util::strip_whitespace( str.substr( start+2, 6 )));
00053   addValue( value, index );
00054   m_mode[index] = Util::strip_whitespace( str.substr( start, modeLen ));      
00055   m_unit[index] = Util::strip_whitespace( str.substr( start+modeLen+6, 4 ));
00056       
00057   m_hasValue = true;
00058   m_overflow=false;
00059       
00060   m_mutex.unlock(); 
00061 }
00062 
00063 void GDM703::run()
00064 {
00065   char data[26*3+1];
00066   
00067   while (m_run)
00068   {
00069     int cnt = readData( &m_port, (unsigned char *)data, 
00070                         0x03, 26, 3*26 );
00071     
00072     if (-1 != cnt)
00073     {
00074       int start = cnt-26;
00075       data[cnt-1] = 0;
00076       std::string strData = data+start;
00077       //std::cerr << strData << std::endl;
00078       
00079       setAscii( 1, 2, strData, 0 );
00080       setAscii( 14, 1, strData, 1 );
00081     }
00082     else m_hasValue = false;
00083   }
00084 }

Generated on Mon Jan 22 23:24:18 2007 for cdmm by  doxygen 1.4.6