Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FlirThermalCameraSerialControl.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 /*
26  * FlirThermalCameraSerialControl.cpp
27  *
28  * Created on: Jan 12, 2011
29  * Author: ischiller
30  */
31 
32 #include "FlirThermalCameraSerialControl.hh"
33 #include <iostream>
34 #include <Utils/Checksum.hh>
35 #include <Base/Debug/Error.hh>
36 #ifdef WIN32
37  #include <windows.h>
38 #endif
39 #include <Base/Common/W32Compat.hh>
40 
41 using namespace BIAS;
42 using namespace std;
43 
46 {
47  connected_ = false;
48  serialNumber_ = "";
49 }
50 
53 {
54  if(connected_) DisconnectCamera();
55 }
56 
57 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
58 ConnectCamera(std::string port)
59 {
60  FLIR_STATUS_MESSAGE ret = CAM_OK;
61  cout<<"trying to open "<<port<<" for serial communication...";
62  bool res = serialIO_.OpenPort(port);
63  if(!res){
64  cout<<"failed!"<<endl;
65  return CAM_NOT_READY;
66  }
67  cout<<"success!"<<endl;
68  serialIO_.SetOptions(57600,SPPM_NoParity,false,true,false,1);
69  serialIO_.SetTimeOuts(5,1,10,1,10);
70  connected_ = true;
71  return ret;
72 }
73 
74 
75 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
77 {
78  if(!connected_) return CAM_NOT_READY;
79  serialNumber_ ="";
80  bool ret = serialIO_.ClosePort();
81  if(ret){
82  connected_ = false;
83  return CAM_OK;
84  }
85  return CAM_NOT_READY;
86 }
87 
88 
89 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
90 GetSerialNumber(std::string &serial){
91  FLIR_STATUS_MESSAGE ret = CAM_OK;
92  unsigned char buffer[10];
93  for(int i=0;i<10;i++) buffer[i]=0;
94  unsigned int crc1,crc2;
95 
96  buffer[0]=0x6E; //process code
97  buffer[1]=0x00; //Status
98  buffer[2]=0x00; //Reserved
99  buffer[3]=0x04; //Function serial number
100  buffer[4]=0x00; //byte count MSB
101  buffer[5]=0x00; //byte count LSB
102 
103  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
104  unsigned int msb = crc1>>8;
105  unsigned int lsb = (unsigned char)crc1;
106  buffer[6]=(unsigned char)msb; //CRC1 MSB
107  buffer[7]=(unsigned char)lsb; //CRC1 LSB
108  Checksum::CalcCRC_CCITT16(crc2,buffer,8);
109  msb = crc2>>8;
110  lsb = (unsigned char)(crc2);
111  buffer[8]=(unsigned char)msb; //CRC2 MSB
112  buffer[9]=(unsigned char)lsb; //CRC2 LSB
113  ret = SendCommand_(buffer,10);
114  if(ret !=CAM_OK){ cout<<__LINE__<<StatusCodeToString(ret)<<endl; return ret;}
115  biasusleep(500);
116  unsigned char buffer2[18];
117  ret = GetAnswer_(buffer2,18,false);
118  if(ret !=CAM_OK){ cout<<__LINE__<<StatusCodeToString(ret)<<endl; return ret;}
119 
120  cout<<"GetSerial Answer:"<<endl;
121  for(unsigned i=0;i<18;i++)
122  cout<<showbase<<hex<<(int)buffer2[i]<<" ";
123  cout<<noshowbase<<dec<<endl;
124 
125  //5 and 6 is byte count
126  unsigned int c1 = (unsigned)buffer2[4];
127  unsigned int c2 = (unsigned)buffer2[5];
128  cout<<"Byte counts:"<<c1<<","<<c2<<endl;
129  //c2 must be 8 byte
130  if(c1 !=0 || c2 != 8) {
131  return CAM_BYTE_COUNT_ERROR;
132  }
133  serialNumber_ = "";
134 
135  //from bytes 8 to 8+c2 there is the data,
136  //4 bytes for camera serial number (0-1 high word, 2-3 low word)
137  //and 4 bytes for sensor serial number (0-1 high word, 2-3 low word)
138  char a = buffer2[8], b = buffer2[9], c = buffer2[10], d =buffer2[11];
139  char tmp[4]={a,b,c,d};
140  a = buffer2[12]; b = buffer2[13]; c = buffer2[14]; d =buffer2[15];
141  char tmp2[4]={a,b,c,d};
142 
143  int camSerNum= tmp[0];
144  camSerNum= camSerNum<<8;
145  camSerNum+= tmp[1];
146  camSerNum= camSerNum<<8;
147  camSerNum+= tmp[2];
148  camSerNum= camSerNum<<8;
149  camSerNum+= tmp[3];
150 
151  int senSerNum= tmp2[0];
152  senSerNum= senSerNum<<8;
153  senSerNum+= tmp2[1];
154  senSerNum= senSerNum<<8;
155  senSerNum+= tmp2[2];
156  senSerNum= senSerNum<<8;
157  senSerNum+= tmp2[3];
158 
159  stringstream txt; txt << camSerNum <<":"<<senSerNum;
160  serialNumber_ = txt.str();
161  serial=serialNumber_;
162  return ret;
163 }
164 
165 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
167  unsigned char buffer[10];
168  unsigned int crc1,crc2;
169 
170  buffer[0]=0x6E; //process code
171  buffer[1]=0x00; //Status
172  buffer[2]=0x00; //Reserved
173  buffer[3]=0x01; //Function
174  buffer[4]=0x00; //byte count MSB
175  buffer[5]=0x00; //byte count LSB
176 
177  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
178  //cout<<"Checksum1: "<<showbase<<hex<<crc1<<endl;
179  unsigned int msb = crc1>>8;
180  unsigned int lsb = (unsigned char)crc1;
181  //cout<<"msb: "<<showbase<<hex<<(int)msb<<endl;
182  //cout<<"lsb: "<<showbase<<hex<<(int)lsb<<endl;
183  buffer[6]=(unsigned char)msb; //CRC1 MSB
184  buffer[7]=(unsigned char)lsb; //CRC1 LSB
185  //no data
186 
187  Checksum::CalcCRC_CCITT16(crc2,buffer,8);
188  //cout<<"Checksum2: "<<hex<<crc2<<endl;
189  msb = crc2>>8;
190  lsb = (unsigned char)(crc2);
191  //cout<<"msb: "<<showbase<<hex<<msb<<endl;
192  //cout<<"lsb: "<<showbase<<hex<<lsb<<endl;
193 
194  buffer[8]=(unsigned char)msb; //CRC2 MSB
195  buffer[9]=(unsigned char)lsb; //CRC2 LSB
196 
197  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,10);
198  if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl; return ret;}
199  ret = GetAnswer_(buffer,10);
200  return ret;
201 }
202 
203 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
204 SetColoring(unsigned color){
205  cout<<"Setting Video color:"<<color<<endl;
206  if(color > 12) return CAM_RANGE_ERROR;
207 
208  unsigned char buffer[12];
209  unsigned int crc1,crc2;
210 
211  buffer[0]=0x6E; //process code
212  buffer[1]=0x00; //Status
213  buffer[2]=0x00; //Reserved
214  buffer[3]=0x10; //Function
215  buffer[4]=0x00; //byte count MSB
216  buffer[5]=0x02; //byte count LSB //2 bytes
217 
218  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
219 // cout<<showbase<<endl;
220 // cout<<"Checksum1: "<< hex <<crc1<<endl;
221  unsigned int msb = crc1>>8;
222  unsigned int lsb = (unsigned char)crc1;
223 // cout<<"msb: "<<showbase<<hex<<(int)msb<<endl;
224 // cout<<"lsb: "<<showbase<<hex<<(int)lsb<<endl;
225  buffer[6]=(unsigned char)msb; //CRC1 MSB
226  buffer[7]=(unsigned char)lsb; //CRC1 LSB
227 
228  //2 bytes data
229  buffer[8]=0x00;
230  buffer[9]=(unsigned char)(color);
231 
232  Checksum::CalcCRC_CCITT16(crc2,buffer,10);
233  //cout<<"Checksum2: "<<hex <<crc2<<endl;
234  msb = crc2>>8;
235  lsb = (unsigned char)(crc2);
236  //cout<<"msb: "<<showbase<<hex<<msb<<endl;
237  //cout<<"lsb: "<<showbase<<hex<<lsb<<endl;
238 
239  buffer[10]=(unsigned char)msb; //CRC2 MSB
240  buffer[11]=(unsigned char)lsb; //CRC2 LSB
241 
242  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
243  if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl; return ret;}
244  ret = GetAnswer_(buffer,12);
245  return ret;
246 }
247 
248 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
249 SetFFCMode(unsigned mode){
250  cout<<noshowbase<<dec<<endl;
251  cout<<"Setting FFC Mode:"<<mode<<endl;
252  if(mode != 0 && mode != 1 && mode != 2) return CAM_RANGE_ERROR;
253 
254  unsigned char buffer[12];
255  unsigned int crc1,crc2;
256 
257  buffer[0]=0x6E; //process code
258  buffer[1]=0x00; //Status
259  buffer[2]=0x00; //Reserved
260  buffer[3]=0x0B; //Function
261  buffer[4]=0x00; //byte count MSB
262  buffer[5]=0x02; //byte count LSB //2 bytes
263 
264  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
265  cout<<showbase<<endl;
266  cout<<"Checksum1: "<< hex <<crc1<<endl;
267  unsigned int msb = crc1>>8;
268  unsigned int lsb = (unsigned char)crc1;
269  cout<<"msb: "<<showbase<<hex<<(int)msb<<endl;
270  cout<<"lsb: "<<showbase<<hex<<(int)lsb<<endl;
271  buffer[6]=(unsigned char)msb; //CRC1 MSB
272  buffer[7]=(unsigned char)lsb; //CRC1 LSB
273 
274  //2 bytes data
275  buffer[8]=0x00;
276  buffer[9]=(unsigned char)(mode);
277 
278  Checksum::CalcCRC_CCITT16(crc2,buffer,10);
279  cout<<"Checksum2: "<<hex <<crc2<<endl;
280  msb = crc2>>8;
281  lsb = (unsigned char)(crc2);
282  cout<<"msb: "<<showbase<<hex<<msb<<endl;
283  cout<<"lsb: "<<showbase<<hex<<lsb<<endl;
284 
285  buffer[10]=(unsigned char)msb; //CRC2 MSB
286  buffer[11]=(unsigned char)lsb; //CRC2 LSB
287 
288  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
289  if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl; return ret;}
290  ret = GetAnswer_(buffer,12);
291  return ret;
292 }
293 
294 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
295 SetFFCInterval(unsigned interval, unsigned intervalLG)
296 { cout<<noshowbase<<dec<<endl;
297  cout<<"Setting FFC Interval:"<<interval<<","<<intervalLG<<endl;
298  unsigned char buffer[14];
299  unsigned int crc1,crc2;
300 
301  buffer[0]=0x6E; //process code
302  buffer[1]=0x00; //Status
303  buffer[2]=0x00; //Reserved
304  buffer[3]=0x0D; //Function, FFC_PERIOD
305  buffer[4]=0x00; //byte count MSB
306  buffer[5]=0x04; //byte count LSB //2 bytes
307 
308  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
309  cout<<showbase<<endl;
310 
311  unsigned int msb = crc1>>8;
312  unsigned int lsb = (unsigned char)crc1;
313 
314  buffer[6]=(unsigned char)msb; //CRC1 MSB
315  buffer[7]=(unsigned char)lsb; //CRC1 LSB
316 
317  //4 bytes data
318  buffer[8]=(unsigned char)(interval>>8);
319  buffer[9]=(unsigned char)(interval);
320  buffer[10]=(unsigned char)(intervalLG>>8);
321  buffer[11]=(unsigned char)(intervalLG);
322 
323 
324  Checksum::CalcCRC_CCITT16(crc2,buffer,12);
325 
326  msb = crc2>>8;
327  lsb = (unsigned char)(crc2);
328 
329  buffer[12]=(unsigned char)msb; //CRC2 MSB
330  buffer[13]=(unsigned char)lsb; //CRC2 LSB
331 
332  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,14);
333  if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl; return ret;}
334  ret = GetAnswer_(buffer,14);
335  return ret;
336 }
337 
338 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
339 SetFFCTempChange(unsigned tmpChange,unsigned tmpChangeLG)
340 {
341  cout<<noshowbase<<dec<<endl;
342  cout<<"Setting FFC TmpChange:"<<tmpChange<<","<<tmpChangeLG<<endl;
343  unsigned char buffer[14];
344  unsigned int crc1,crc2;
345 
346  buffer[0]=0x6E; //process code
347  buffer[1]=0x00; //Status
348  buffer[2]=0x00; //Reserved
349  buffer[3]=0x0E; //Function, FFC_PERIOD
350  buffer[4]=0x00; //byte count MSB
351  buffer[5]=0x04; //byte count LSB //2 bytes
352 
353  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
354  cout<<showbase<<endl;
355 
356  unsigned int msb = crc1>>8;
357  unsigned int lsb = (unsigned char)crc1;
358 
359  buffer[6]=(unsigned char)msb; //CRC1 MSB
360  buffer[7]=(unsigned char)lsb; //CRC1 LSB
361 
362  //4 bytes data
363  buffer[8]=(unsigned char)(tmpChange>>8);
364  buffer[9]=(unsigned char)(tmpChange);
365  buffer[10]=(unsigned char)(tmpChangeLG>>8);
366  buffer[11]=(unsigned char)(tmpChangeLG);
367 
368 
369  Checksum::CalcCRC_CCITT16(crc2,buffer,12);
370 
371  msb = crc2>>8;
372  lsb = (unsigned char)(crc2);
373 
374  buffer[12]=(unsigned char)msb; //CRC2 MSB
375  buffer[13]=(unsigned char)lsb; //CRC2 LSB
376 
377  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,14);
378  if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl; return ret;}
379  ret = GetAnswer_(buffer,14);
380  return ret;
381 }
382 
383 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
384 SetGainMode(unsigned mode){
385  cout<<"Setting Gain Mode:"<<mode<<endl;
386  if(mode > 3) return CAM_RANGE_ERROR;
387 
388  unsigned char buffer[12];
389  unsigned int crc1,crc2;
390 
391  buffer[0]=0x6E; //process code
392  buffer[1]=0x00; //Status
393  buffer[2]=0x00; //Reserved
394  buffer[3]=0x0A; //Function
395  buffer[4]=0x00; //byte count MSB
396  buffer[5]=0x02; //byte count LSB //2 bytes
397 
398  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
399 
400  unsigned int msb = crc1>>8;
401  unsigned int lsb = (unsigned char)crc1;
402  buffer[6]=(unsigned char)msb; //CRC1 MSB
403  buffer[7]=(unsigned char)lsb; //CRC1 LSB
404 
405  //2 bytes data
406  buffer[8]=0x00;
407  buffer[9]=(unsigned char)(mode);
408 
409  Checksum::CalcCRC_CCITT16(crc2,buffer,10);
410  msb = crc2>>8;
411  lsb = (unsigned char)(crc2);
412 
413  buffer[10]=(unsigned char)msb; //CRC2 MSB
414  buffer[11]=(unsigned char)lsb; //CRC2 LSB
415 
416  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
417  if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl; return ret;}
418  ret = GetAnswer_(buffer,12);
419  return ret;
420 }
421 
422 
423 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
424 SetExternalSync(unsigned mode){
425  cout<<"Setting External Sync Mode:"<<mode<<endl;
426  if(mode > 2) return CAM_RANGE_ERROR;
427 
428  unsigned char buffer[12];
429  unsigned int crc1,crc2;
430 
431  buffer[0]=0x6E; //process code
432  buffer[1]=0x00; //Status
433  buffer[2]=0x00; //Reserved
434  buffer[3]=0x21; //Function
435  buffer[4]=0x00; //byte count MSB
436  buffer[5]=0x02; //byte count LSB //2 bytes
437 
438  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
439 
440  unsigned int msb = crc1>>8;
441  unsigned int lsb = (unsigned char)crc1;
442  buffer[6]=(unsigned char)msb; //CRC1 MSB
443  buffer[7]=(unsigned char)lsb; //CRC1 LSB
444 
445  //2 bytes data
446  buffer[8]=0x00;
447  buffer[9]=(unsigned char)(mode);
448 
449  Checksum::CalcCRC_CCITT16(crc2,buffer,10);
450  msb = crc2>>8;
451  lsb = (unsigned char)(crc2);
452 
453  buffer[10]=(unsigned char)msb; //CRC2 MSB
454  buffer[11]=(unsigned char)lsb; //CRC2 LSB
455 
456  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
457  if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl; return ret;}
458  ret = GetAnswer_(buffer,12);
459  return ret;
460 }
461 
462 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
463 SetVideoMode(unsigned level){
464  cout<<"Setting Video Mode:"<<level<<endl;
465  if(level != 0 && level != 1 && level != 4 && level != 8)
466  return CAM_RANGE_ERROR;
467 
468  unsigned char buffer[12];
469  unsigned int crc1,crc2;
470 
471  buffer[0]=0x6E; //process code
472  buffer[1]=0x00; //Status
473  buffer[2]=0x00; //Reserved
474  buffer[3]=0x0F; //Function
475  buffer[4]=0x00; //byte count MSB
476  buffer[5]=0x02; //byte count LSB //2 bytes
477 
478  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
479 
480  unsigned int msb = crc1>>8;
481  unsigned int lsb = (unsigned char)crc1;
482  buffer[6]=(unsigned char)msb; //CRC1 MSB
483  buffer[7]=(unsigned char)lsb; //CRC1 LSB
484 
485  //2 bytes data
486  buffer[8]=0x00;
487  buffer[9]=(unsigned char)(level);
488 
489  Checksum::CalcCRC_CCITT16(crc2,buffer,10);
490  msb = crc2>>8;
491  lsb = (unsigned char)(crc2);
492 
493  buffer[10]=(unsigned char)msb; //CRC2 MSB
494  buffer[11]=(unsigned char)lsb; //CRC2 LSB
495 
496  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
497  if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl; return ret;}
498  ret = GetAnswer_(buffer,12);
499  return ret;
500 }
501 
502 /** \brief Set the algorithm for Automatic Gain Control*/
503 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
504 SetAGCAlgorithm(unsigned algo){
505  cout<<"Set AGC algorithm:"<<algo<<endl;
506  if(algo > 5) return CAM_RANGE_ERROR;
507 
508  unsigned char buffer[12];
509  unsigned int crc1,crc2;
510 
511  buffer[0]=0x6E; //process code
512  buffer[1]=0x00; //Status
513  buffer[2]=0x00; //Reserved
514  buffer[3]=0x13; //Function
515  buffer[4]=0x00; //byte count MSB
516  buffer[5]=0x02; //byte count LSB //2 bytes
517 
518  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
519 
520  unsigned int msb = crc1>>8;
521  unsigned int lsb = (unsigned char)crc1;
522  buffer[6]=(unsigned char)msb; //CRC1 MSB
523  buffer[7]=(unsigned char)lsb; //CRC1 LSB
524 
525  //2 bytes data
526  buffer[8]=0x00;
527  buffer[9]=(unsigned char)(algo);
528 
529  Checksum::CalcCRC_CCITT16(crc2,buffer,10);
530  msb = crc2>>8;
531  lsb = (unsigned char)(crc2);
532 
533  buffer[10]=(unsigned char)msb; //CRC2 MSB
534  buffer[11]=(unsigned char)lsb; //CRC2 LSB
535 
536 
537  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
538  if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl; return ret;}
539  ret = GetAnswer_(buffer,12);
540  return ret;
541 }
542 
543 
544 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
545 SetVideoOrientation(unsigned orientation){
546  cout<<"Setting Video Orientation:"<<orientation<<endl;
547  if(orientation > 3) return CAM_RANGE_ERROR;
548 
549  unsigned char buffer[12];
550  unsigned int crc1,crc2;
551 
552  buffer[0]=0x6E; //process code
553  buffer[1]=0x00; //Status
554  buffer[2]=0x00; //Reserved
555  buffer[3]=0x11; //Function
556  buffer[4]=0x00; //byte count MSB
557  buffer[5]=0x02; //byte count LSB //2 bytes
558 
559  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
560 
561  unsigned int msb = crc1>>8;
562  unsigned int lsb = (unsigned char)crc1;
563  buffer[6]=(unsigned char)msb; //CRC1 MSB
564  buffer[7]=(unsigned char)lsb; //CRC1 LSB
565 
566  //2 bytes data
567  buffer[8]=0x00;
568  buffer[9]=(unsigned char)(orientation);
569 
570  Checksum::CalcCRC_CCITT16(crc2,buffer,10);
571  msb = crc2>>8;
572  lsb = (unsigned char)(crc2);
573 
574  buffer[10]=(unsigned char)msb; //CRC2 MSB
575  buffer[11]=(unsigned char)lsb; //CRC2 LSB
576 
577 
578  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
579  if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl; return ret;}
580  ret = GetAnswer_(buffer,12);
581  return ret;
582 }
583 
584 
585 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
586 SetVideoStandard(unsigned std){
587  if(std > 1) return CAM_RANGE_ERROR;
588 
589  unsigned char buffer[12];
590  unsigned int crc1,crc2;
591 
592  buffer[0]=0x6E; //process code
593  buffer[1]=0x00; //Status
594  buffer[2]=0x00; //Reserved
595  buffer[3]=0x72; //Function
596  buffer[4]=0x00; //byte count MSB
597  buffer[5]=0x02; //byte count LSB //2 bytes
598 
599  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
600 
601  unsigned int msb = crc1>>8;
602  unsigned int lsb = (unsigned char)crc1;
603  buffer[6]=(unsigned char)msb; //CRC1 MSB
604  buffer[7]=(unsigned char)lsb; //CRC1 LSB
605 
606  //2 bytes data
607  buffer[8]=0x00;
608  buffer[9]=(unsigned char)(std);
609 
610  Checksum::CalcCRC_CCITT16(crc2,buffer,10);
611  msb = crc2>>8;
612  lsb = (unsigned char)(crc2);
613 
614  buffer[10]=(unsigned char)msb; //CRC2 MSB
615  buffer[11]=(unsigned char)lsb; //CRC2 LSB
616 
617  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
618  if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl; return ret;}
619  ret = GetAnswer_(buffer,12);
620  return ret;
621 }
622 
623 
624 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
625 SetSpotMeterMode(unsigned spotmeter){
626  if(spotmeter > 2) return CAM_RANGE_ERROR;
627 
628  unsigned char buffer[12];
629  unsigned int crc1,crc2;
630 
631  buffer[0]=0x6E; //process code
632  buffer[1]=0x00; //Status
633  buffer[2]=0x00; //Reserved
634  buffer[3]=0x1F; //Function
635  buffer[4]=0x00; //byte count MSB
636  buffer[5]=0x02; //byte count LSB //2 bytes
637 
638  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
639 
640  unsigned int msb = crc1>>8;
641  unsigned int lsb = (unsigned char)crc1;
642  buffer[6]=(unsigned char)msb; //CRC1 MSB
643  buffer[7]=(unsigned char)lsb; //CRC1 LSB
644 
645  //2 bytes data
646  buffer[8]=0x00;
647  buffer[9]=(unsigned char)(spotmeter);
648 
649  Checksum::CalcCRC_CCITT16(crc2,buffer,10);
650  msb = crc2>>8;
651  lsb = (unsigned char)(crc2);
652 
653  buffer[10]=(unsigned char)msb; //CRC2 MSB
654  buffer[11]=(unsigned char)lsb; //CRC2 LSB
655  cout<<"Setting spot meter mode:"<<spotmeter<<endl;
656 
657  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
658  if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl; return ret;}
659  ret = GetAnswer_(buffer,12);
660  return ret;
661 }
662 
663 
664 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
665 SetSpotMeterDisplay(unsigned display){
666  if(display > 3) return CAM_RANGE_ERROR;
667 
668  unsigned char buffer[12];
669  unsigned int crc1,crc2;
670 
671  buffer[0]=0x6E; //process code
672  buffer[1]=0x00; //Status
673  buffer[2]=0x00; //Reserved
674  buffer[3]=0x2B; //Function
675  buffer[4]=0x00; //byte count MSB
676  buffer[5]=0x02; //byte count LSB //2 bytes
677 
678  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
679 
680  unsigned int msb = crc1>>8;
681  unsigned int lsb = (unsigned char)crc1;
682  buffer[6]=(unsigned char)msb; //CRC1 MSB
683  buffer[7]=(unsigned char)lsb; //CRC1 LSB
684 
685  //2 bytes data
686  buffer[8]=0x00;
687  buffer[9]=(unsigned char)(display);
688 
689  Checksum::CalcCRC_CCITT16(crc2,buffer,10);
690  msb = crc2>>8;
691  lsb = (unsigned char)(crc2);
692 
693  buffer[10]=(unsigned char)msb; //CRC2 MSB
694  buffer[11]=(unsigned char)lsb; //CRC2 LSB
695 
696  cout<<"Setting spot display:"<<display<<endl;
697  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
698  if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl; return ret;}
699  ret = GetAnswer_(buffer,12);
700 
701  return ret;
702 }
703 
704 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
705 GetSpotMeterCelcius(double& degree){
706 
707  unsigned char buffer[10];
708  unsigned int crc1,crc2;
709 
710  buffer[0]=0x6E; //process code
711  buffer[1]=0x00; //Status
712  buffer[2]=0x00; //Reserved
713  buffer[3]=0x43; //Function
714  buffer[4]=0x00; //byte count MSB
715  buffer[5]=0x00; //byte count LSB //2 bytes
716 
717  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
718 
719  unsigned int msb = crc1>>8;
720  unsigned int lsb = (unsigned char)crc1;
721  buffer[6]=(unsigned char)msb; //CRC1 MSB
722  buffer[7]=(unsigned char)lsb; //CRC1 LSB
723 
724  //No Data
725 
726  Checksum::CalcCRC_CCITT16(crc2,buffer,8);
727  msb = crc2>>8;
728  lsb = (unsigned char)(crc2);
729  buffer[8]=(unsigned char)msb; //CRC2 MSB
730  buffer[9]=(unsigned char)lsb; //CRC2 LSB
731 
732  cout<<"Get spot value:"<<endl;
733  //sent Get Message
734  cout<<"Writing:";
735  for(unsigned i=0;i<10;i++)
736  cout<<showbase<<hex<<(int)buffer[i]<<" ";
737  cout<<noshowbase<<dec<<endl;
738 
739  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,10);
740  if(ret !=CAM_OK) return ret;
741 
742  unsigned char buffer2[12];
743  ret = GetAnswer_(buffer2,12);
744  if(ret!= CAM_OK) return ret;
745 
746  for(unsigned i=0;i<12;i++)
747  cout<<showbase<<hex<<(int)buffer2[i]<<" ";
748  cout<<noshowbase<<dec<<endl;
749 
750  // in 8 the temperature in C*10 is stored
751  degree = buffer2[8];
752  degree*=0.1;
753  return ret;
754 }
755 
756 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
757 GetSensorTemp(double& degree){
758  unsigned char buffer[12];
759  unsigned int crc1,crc2;
760 
761  buffer[0]=0x6E; //process code
762  buffer[1]=0x00; //Status
763  buffer[2]=0x00; //Reserved
764  buffer[3]=0x20; //Function read sensor
765  buffer[4]=0x00; //byte count MSB
766  buffer[5]=0x00; //byte count LSB //2 bytes
767 
768  Checksum::CalcCRC_CCITT16(crc1,buffer,6);
769 
770  unsigned int msb = crc1>>8;
771  unsigned int lsb = (unsigned char)crc1;
772  buffer[6]=(unsigned char)msb; //CRC1 MSB
773  buffer[7]=(unsigned char)lsb; //CRC1 LSB
774 
775  //No Data
776  buffer[8] =0x00;
777  buffer[9] =0x00;
778  Checksum::CalcCRC_CCITT16(crc2,buffer,10);
779  msb = crc2>>8;
780  lsb = (unsigned char)(crc2);
781  buffer[10]=(unsigned char)msb; //CRC2 MSB
782  buffer[11]=(unsigned char)lsb; //CRC2 LSB
783 
784  cout<<"Get sensor tmp:"<<endl;
785  //sent Get Message
786  cout<<"Writing:";
787  for(unsigned i=0;i<12;i++)
788  cout<<showbase<<hex<<(int)buffer[i]<<" ";
789  cout<<noshowbase<<dec<<endl;
790 
791  FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
792  if(ret !=CAM_OK) return ret;
793 
794  ret = GetAnswer_(buffer,12);
795  if(ret!= CAM_OK) return ret;
796 
797  for(unsigned i=0;i<12;i++)
798  cout<<showbase<<hex<<(int)buffer[i]<<" ";
799  cout<<noshowbase<<dec<<endl;
800 
801  // in 8 the temperature in C*10 is stored
802  degree = buffer[8];
803  degree*=0.1;
804  return ret;
805 }
806 
807 
808 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
809 SetOptimization(unsigned optimization){
810  return CAM_NOT_READY;
811 }
812 
813 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
814 SetContrast(unsigned contrast){
815  return CAM_NOT_READY;
816 }
817 
818 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
819 SetBrightness(unsigned brigthness){
820  return CAM_NOT_READY;
821 }
822 
823 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
824 SendCommand_(unsigned char* buf, int length)
825 {
826  if(!connected_ || length < 2) return CAM_NOT_READY;
827  serialIO_.WriteBytes(buf,length);
828  return CAM_OK;
829 }
830 
831 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
832 GetAnswer_(unsigned char* buf, int length, bool wait)
833 {
834  if(!connected_ || length < 2) return CAM_NOT_READY;
835  //clear buf to wipe memory
836  for (int i=0;i<length;i++) buf[i]=0;
837  serialIO_.ReadBytes(buf,length,wait);
838  return CheckCameraReply_(buf);
839 }
840 
841 FLIR_STATUS_MESSAGE FlirThermalCameraSerialControl::
842 CheckCameraReply_(unsigned char* buf){
843  if(buf[1]==0x00) return CAM_OK;
844  else if(buf[1]==0x01) return CAM_BUSY;
845  else if(buf[1]==0x02) return CAM_NOT_READY;
846  else if(buf[1]==0x03) return CAM_RANGE_ERROR;
847  else if(buf[1]==0x04) return CAM_CHECKSUM_ERROR;
848  else if(buf[1]==0x05) return CAM_UNDEFINED_PROCESS_ERROR;
849  else if(buf[1]==0x06) return CAM_UNDEFINED_FUNCTION_ERROR;
850  else if(buf[1]==0x07) return CAM_TIMEOUT_ERROR;
851  else if(buf[1]==0x08) return CAM_BYTE_COUNT_ERROR;
852  else if(buf[1]==0x09) return CAM_FEATURE_ERROR;
853  else if(buf[1]==0x0a) return CAM_NOT_READY;
854  else return CAM_GENERAL_ERROR;
855 }
856 
858 StatusCodeToString(FLIR_STATUS_MESSAGE code){
859  if(code == CAM_OK) return "CAM_OK";
860  else if(code== CAM_BUSY)return "CAM_BUSY";
861  else if(code==CAM_NOT_READY)return "CAM_NOT_READY";
862  else if(code==CAM_RANGE_ERROR)return "CAM_RANGE_ERROR";
863  else if(code==CAM_CHECKSUM_ERROR)return "CAM_CHECKSUM_ERROR";
864  else if(code==CAM_UNDEFINED_PROCESS_ERROR)return "CAM_UNDEFINED_PROCESS_ERROR";
865  else if(code==CAM_UNDEFINED_FUNCTION_ERROR)return "CAM_UNDEFINED_FUNCTION_ERROR";
866  else if(code==CAM_TIMEOUT_ERROR)return "CAM_TIMEOUT_ERROR";
867  else if(code==CAM_BYTE_COUNT_ERROR)return "CAM_BYTE_COUNT_ERROR";
868  else if(code==CAM_FEATURE_ERROR)return "CAM_FEATURE_ERROR";
869  else if(code==CAM_NOT_READY)return "CAM_NOT_READY";
870  else return "CAM_GENERAL_ERROR";
871 }
FLIR_STATUS_MESSAGE SetSpotMeterDisplay(unsigned spotmeter)
FLIR_STATUS_MESSAGE DisconnectCamera()
disconnnect camera control
FLIR_STATUS_MESSAGE SetSpotMeterMode(unsigned spotmeter)
FLIR_STATUS_MESSAGE GetSpotMeterCelcius(double &degree)
FLIR_STATUS_MESSAGE SetFFCTempChange(unsigned tmpChange, unsigned tmpChangeLowGain)
Set the flat field correction max temp change.
std::string StatusCodeToString(FLIR_STATUS_MESSAGE code)
FLIR_STATUS_MESSAGE SetDefaults()
set default camera parameters
FLIR_STATUS_MESSAGE SetFFCInterval(unsigned interval, unsigned intervalLowGain)
Set the flat field correction interval in frames.
FLIR_STATUS_MESSAGE SetContrast(unsigned contrast)
static bool CalcCRC_CCITT16(unsigned int &crc, unsigned char *input, unsigned lenght)
Calculates CCITT-16 checksum with most significant bit first MSB.
Definition: Checksum.cpp:38
FLIR_STATUS_MESSAGE SetVideoOrientation(unsigned orientation)
set orientation of video allowed range 0,...,4 0 = normal 1 = Invert 2 = Revert 3 = Invert and Revert...
FLIR_STATUS_MESSAGE SetGainMode(unsigned mode)
sets the gain mode
FLIR_STATUS_MESSAGE SetVideoMode(unsigned level)
allowed values are 0,1,4,8 0=real time 1 = freeze frame 4 = 2x zoom 8 = 4x zoom
FLIR_STATUS_MESSAGE SendCommand_(unsigned char *buf, int length)
FLIR_STATUS_MESSAGE SetColoring(unsigned color)
set different color shemes allowed range 0,...,12
FLIR_STATUS_MESSAGE GetSerialNumber(std::string &serial)
FLIR_STATUS_MESSAGE SetFFCMode(unsigned mode)
Set the flat field correction allowed values 0,1,2.
FLIR_STATUS_MESSAGE SetOptimization(unsigned optimization)
FLIR_STATUS_MESSAGE SetExternalSync(unsigned sync)
sets the gain mode
FLIR_STATUS_MESSAGE ConnectCamera(std::string port)
connect over serial port
FLIR_STATUS_MESSAGE SetAGCAlgorithm(unsigned algo)
Set the algorithm for Automatic Gain Control.
FLIR_STATUS_MESSAGE SetVideoStandard(unsigned std)
set the video standard 0=NTSC 1=PAL
FLIR_STATUS_MESSAGE GetSensorTemp(double &degree)
FLIR_STATUS_MESSAGE GetAnswer_(unsigned char *buf, int length, bool wait=false)
FLIR_STATUS_MESSAGE CheckCameraReply_(unsigned char *buf)
FLIR_STATUS_MESSAGE SetBrightness(unsigned brigthness)