00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <vc820.h>
00021
00022 #include <iostream>
00023
00024 VC820::VC820() :
00025 DMMClass()
00026 {
00027 }
00028
00029 VC820::~VC820()
00030 {
00031 m_port.close();
00032 }
00033
00034 Port::Error VC820::open_impl( const std::string & config )
00035 {
00036 return m_port.open( config );
00037 }
00038
00039 Port::Error VC820::close()
00040 {
00041 return m_port.close();
00042 }
00043
00044 void VC820::run()
00045 {
00046 unsigned char buffer[64];
00047
00048 while (m_run)
00049 {
00050
00051
00052 int cnt = readData( buffer );
00053
00054 if (-1 != cnt)
00055 {
00056 unsigned char *byte = buffer+cnt-14;
00057
00058 m_mutex.lock();
00059
00060
00061
00062 std::string digits;
00063
00064 digits = digitFromSegments( byte[1], byte[2] );
00065 digits += digitFromSegments( byte[3], byte[4] );
00066 digits += digitFromSegments( byte[5], byte[6] );
00067 digits += digitFromSegments( byte[7], byte[8] );
00068
00069 double d_val;
00070 Util::fromString( &d_val, digits );
00071
00072
00073
00074 if (byte[12] & 0x01) m_lowBat = true;
00075 else m_lowBat = false;
00076
00077
00078
00079 if (byte[3] & 0x08) d_val /= 1000.0;
00080 else if (byte[5] & 0x08) d_val /= 100.0;
00081 else if (byte[7] & 0x08) d_val /= 10.0;
00082
00083
00084
00085 if (byte[1] & 0x08) d_val *= -1.0;
00086
00087
00088
00089 if (byte[9] & 0x02) m_unit[0] = "k";
00090 else if (byte[9] & 0x04) m_unit[0] = "n";
00091 else if (byte[9] & 0x08) m_unit[0] = "u";
00092 else if (byte[10] & 0x02) m_unit[0] = "M";
00093 else if (byte[10] & 0x08) m_unit[0] = "m";
00094 else if (byte[10] & 0x04) m_unit[0] = "%";
00095 else m_unit[0] = "";
00096
00097 if (byte[11] & 0x04) m_unit[0] += "Ohm";
00098 else if (byte[11] & 0x08) m_unit[0] += "F";
00099 else if (byte[12] & 0x02) m_unit[0] += "Hz";
00100 else if (byte[12] & 0x04) m_unit[0] += "V";
00101 else if (byte[12] & 0x08) m_unit[0] += "A";
00102 else if (byte[13] & 0x01) m_unit[0] += "C";
00103
00104 std::cout<<(int)byte[13]<<std::endl;
00105
00106
00107
00108 if (byte[12] & 0x0c)
00109 {
00110 if (byte[0] & 0x08) m_mode[0] = "AC";
00111 else m_mode[0] = "DC";
00112 }
00113 else if (byte[9] & 0x01) m_mode[0] = "DI";
00114 else if (byte[11] & 0x04) m_mode[0] = "OH";
00115 else if (byte[11] & 0x08) m_mode[0] = "CA";
00116 else if (byte[12] & 0x02) m_mode[0] = "FR";
00117 else if (byte[13] & 0x01) m_mode[0] = "TE";
00118 else m_mode[0] = "";
00119
00120 addValue( d_val, 0 );
00121
00122 m_hasValue = true;
00123 m_mutex.unlock();
00124 }
00125 else
00126 {
00127 m_hasValue = false;
00128 }
00129 }
00130 }
00131
00132 std::string VC820::digitFromSegments( unsigned char a,
00133 unsigned char b ) const
00134 {
00135 std::string digit;
00136
00137 unsigned test = (b & 0x0f) | ((a & 0x07) << 4);
00138
00139 switch (test)
00140 {
00141 case 0x7d:
00142 digit = "0";
00143 break;
00144 case 0x05:
00145 digit = "1";
00146 break;
00147 case 0x5b:
00148 digit = "2";
00149 break;
00150 case 0x1f:
00151 digit = "3";
00152 break;
00153 case 0x27:
00154 digit = "4";
00155 break;
00156 case 0x3e:
00157 digit = "5";
00158 break;
00159 case 0x7e:
00160 digit = "6";
00161 break;
00162 case 0x15:
00163 digit = "7";
00164 break;
00165 case 0x7f:
00166 digit = "8";
00167 break;
00168 case 0x3f:
00169 digit = "9";
00170 break;
00171 }
00172
00173 return digit;
00174 }
00175
00176 int VC820::readData( unsigned char *buffer ) const
00177 {
00178 int cnt=0;
00179 int byte;
00180
00181 do
00182 {
00183 if (m_port.readByte( &byte ) != Port::Ok)
00184 {
00185 return -1;
00186 }
00187 buffer[cnt++] = byte;
00188
00189 if ((byte & 0xf0) == 0xe0 && cnt >= 14) return cnt;
00190 }
00191 while (cnt < 14 && (byte & 0xf0) != 0xe0);
00192
00193 return -1;
00194 }
00195