32 #include "FlirThermalCameraSerialControl.hh"
34 #include <Utils/Checksum.hh>
35 #include <Base/Debug/Error.hh>
39 #include <Base/Common/W32Compat.hh>
54 if(connected_) DisconnectCamera();
60 FLIR_STATUS_MESSAGE ret = CAM_OK;
61 cout<<
"trying to open "<<port<<
" for serial communication...";
62 bool res = serialIO_.OpenPort(port);
64 cout<<
"failed!"<<endl;
67 cout<<
"success!"<<endl;
69 serialIO_.SetTimeOuts(5,1,10,1,10);
78 if(!connected_)
return CAM_NOT_READY;
80 bool ret = serialIO_.ClosePort();
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;
104 unsigned int msb = crc1>>8;
105 unsigned int lsb = (
unsigned char)crc1;
106 buffer[6]=(
unsigned char)msb;
107 buffer[7]=(
unsigned char)lsb;
110 lsb = (
unsigned char)(crc2);
111 buffer[8]=(
unsigned char)msb;
112 buffer[9]=(
unsigned char)lsb;
113 ret = SendCommand_(buffer,10);
114 if(ret !=CAM_OK){ cout<<__LINE__<<StatusCodeToString(ret)<<endl;
return ret;}
116 unsigned char buffer2[18];
117 ret = GetAnswer_(buffer2,18,
false);
118 if(ret !=CAM_OK){ cout<<__LINE__<<StatusCodeToString(ret)<<endl;
return ret;}
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;
126 unsigned int c1 = (unsigned)buffer2[4];
127 unsigned int c2 = (unsigned)buffer2[5];
128 cout<<
"Byte counts:"<<c1<<
","<<c2<<endl;
130 if(c1 !=0 || c2 != 8) {
131 return CAM_BYTE_COUNT_ERROR;
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};
143 int camSerNum= tmp[0];
144 camSerNum= camSerNum<<8;
146 camSerNum= camSerNum<<8;
148 camSerNum= camSerNum<<8;
151 int senSerNum= tmp2[0];
152 senSerNum= senSerNum<<8;
154 senSerNum= senSerNum<<8;
156 senSerNum= senSerNum<<8;
159 stringstream txt; txt << camSerNum <<
":"<<senSerNum;
160 serialNumber_ = txt.str();
161 serial=serialNumber_;
167 unsigned char buffer[10];
168 unsigned int crc1,crc2;
179 unsigned int msb = crc1>>8;
180 unsigned int lsb = (
unsigned char)crc1;
183 buffer[6]=(
unsigned char)msb;
184 buffer[7]=(
unsigned char)lsb;
190 lsb = (
unsigned char)(crc2);
194 buffer[8]=(
unsigned char)msb;
195 buffer[9]=(
unsigned char)lsb;
197 FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,10);
198 if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl;
return ret;}
199 ret = GetAnswer_(buffer,10);
205 cout<<
"Setting Video color:"<<color<<endl;
206 if(color > 12)
return CAM_RANGE_ERROR;
208 unsigned char buffer[12];
209 unsigned int crc1,crc2;
221 unsigned int msb = crc1>>8;
222 unsigned int lsb = (
unsigned char)crc1;
225 buffer[6]=(
unsigned char)msb;
226 buffer[7]=(
unsigned char)lsb;
230 buffer[9]=(
unsigned char)(color);
235 lsb = (
unsigned char)(crc2);
239 buffer[10]=(
unsigned char)msb;
240 buffer[11]=(
unsigned char)lsb;
242 FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
243 if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl;
return ret;}
244 ret = GetAnswer_(buffer,12);
250 cout<<noshowbase<<dec<<endl;
251 cout<<
"Setting FFC Mode:"<<mode<<endl;
252 if(mode != 0 && mode != 1 && mode != 2)
return CAM_RANGE_ERROR;
254 unsigned char buffer[12];
255 unsigned int crc1,crc2;
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;
272 buffer[7]=(
unsigned char)lsb;
276 buffer[9]=(
unsigned char)(mode);
279 cout<<
"Checksum2: "<<hex <<crc2<<endl;
281 lsb = (
unsigned char)(crc2);
282 cout<<
"msb: "<<showbase<<hex<<msb<<endl;
283 cout<<
"lsb: "<<showbase<<hex<<lsb<<endl;
285 buffer[10]=(
unsigned char)msb;
286 buffer[11]=(
unsigned char)lsb;
288 FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
289 if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl;
return ret;}
290 ret = GetAnswer_(buffer,12);
296 { cout<<noshowbase<<dec<<endl;
297 cout<<
"Setting FFC Interval:"<<interval<<
","<<intervalLG<<endl;
298 unsigned char buffer[14];
299 unsigned int crc1,crc2;
309 cout<<showbase<<endl;
311 unsigned int msb = crc1>>8;
312 unsigned int lsb = (
unsigned char)crc1;
314 buffer[6]=(
unsigned char)msb;
315 buffer[7]=(
unsigned char)lsb;
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);
327 lsb = (
unsigned char)(crc2);
329 buffer[12]=(
unsigned char)msb;
330 buffer[13]=(
unsigned char)lsb;
332 FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,14);
333 if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl;
return ret;}
334 ret = GetAnswer_(buffer,14);
341 cout<<noshowbase<<dec<<endl;
342 cout<<
"Setting FFC TmpChange:"<<tmpChange<<
","<<tmpChangeLG<<endl;
343 unsigned char buffer[14];
344 unsigned int crc1,crc2;
354 cout<<showbase<<endl;
356 unsigned int msb = crc1>>8;
357 unsigned int lsb = (
unsigned char)crc1;
359 buffer[6]=(
unsigned char)msb;
360 buffer[7]=(
unsigned char)lsb;
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);
372 lsb = (
unsigned char)(crc2);
374 buffer[12]=(
unsigned char)msb;
375 buffer[13]=(
unsigned char)lsb;
377 FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,14);
378 if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl;
return ret;}
379 ret = GetAnswer_(buffer,14);
385 cout<<
"Setting Gain Mode:"<<mode<<endl;
386 if(mode > 3)
return CAM_RANGE_ERROR;
388 unsigned char buffer[12];
389 unsigned int crc1,crc2;
400 unsigned int msb = crc1>>8;
401 unsigned int lsb = (
unsigned char)crc1;
402 buffer[6]=(
unsigned char)msb;
403 buffer[7]=(
unsigned char)lsb;
407 buffer[9]=(
unsigned char)(mode);
411 lsb = (
unsigned char)(crc2);
413 buffer[10]=(
unsigned char)msb;
414 buffer[11]=(
unsigned char)lsb;
416 FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
417 if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl;
return ret;}
418 ret = GetAnswer_(buffer,12);
425 cout<<
"Setting External Sync Mode:"<<mode<<endl;
426 if(mode > 2)
return CAM_RANGE_ERROR;
428 unsigned char buffer[12];
429 unsigned int crc1,crc2;
440 unsigned int msb = crc1>>8;
441 unsigned int lsb = (
unsigned char)crc1;
442 buffer[6]=(
unsigned char)msb;
443 buffer[7]=(
unsigned char)lsb;
447 buffer[9]=(
unsigned char)(mode);
451 lsb = (
unsigned char)(crc2);
453 buffer[10]=(
unsigned char)msb;
454 buffer[11]=(
unsigned char)lsb;
456 FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
457 if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl;
return ret;}
458 ret = GetAnswer_(buffer,12);
464 cout<<
"Setting Video Mode:"<<level<<endl;
465 if(level != 0 && level != 1 && level != 4 && level != 8)
466 return CAM_RANGE_ERROR;
468 unsigned char buffer[12];
469 unsigned int crc1,crc2;
480 unsigned int msb = crc1>>8;
481 unsigned int lsb = (
unsigned char)crc1;
482 buffer[6]=(
unsigned char)msb;
483 buffer[7]=(
unsigned char)lsb;
487 buffer[9]=(
unsigned char)(level);
491 lsb = (
unsigned char)(crc2);
493 buffer[10]=(
unsigned char)msb;
494 buffer[11]=(
unsigned char)lsb;
496 FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
497 if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl;
return ret;}
498 ret = GetAnswer_(buffer,12);
505 cout<<
"Set AGC algorithm:"<<algo<<endl;
506 if(algo > 5)
return CAM_RANGE_ERROR;
508 unsigned char buffer[12];
509 unsigned int crc1,crc2;
520 unsigned int msb = crc1>>8;
521 unsigned int lsb = (
unsigned char)crc1;
522 buffer[6]=(
unsigned char)msb;
523 buffer[7]=(
unsigned char)lsb;
527 buffer[9]=(
unsigned char)(algo);
531 lsb = (
unsigned char)(crc2);
533 buffer[10]=(
unsigned char)msb;
534 buffer[11]=(
unsigned char)lsb;
537 FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
538 if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl;
return ret;}
539 ret = GetAnswer_(buffer,12);
546 cout<<
"Setting Video Orientation:"<<orientation<<endl;
547 if(orientation > 3)
return CAM_RANGE_ERROR;
549 unsigned char buffer[12];
550 unsigned int crc1,crc2;
561 unsigned int msb = crc1>>8;
562 unsigned int lsb = (
unsigned char)crc1;
563 buffer[6]=(
unsigned char)msb;
564 buffer[7]=(
unsigned char)lsb;
568 buffer[9]=(
unsigned char)(orientation);
572 lsb = (
unsigned char)(crc2);
574 buffer[10]=(
unsigned char)msb;
575 buffer[11]=(
unsigned char)lsb;
578 FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
579 if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl;
return ret;}
580 ret = GetAnswer_(buffer,12);
587 if(std > 1)
return CAM_RANGE_ERROR;
589 unsigned char buffer[12];
590 unsigned int crc1,crc2;
601 unsigned int msb = crc1>>8;
602 unsigned int lsb = (
unsigned char)crc1;
603 buffer[6]=(
unsigned char)msb;
604 buffer[7]=(
unsigned char)lsb;
608 buffer[9]=(
unsigned char)(std);
612 lsb = (
unsigned char)(crc2);
614 buffer[10]=(
unsigned char)msb;
615 buffer[11]=(
unsigned char)lsb;
617 FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
618 if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl;
return ret;}
619 ret = GetAnswer_(buffer,12);
626 if(spotmeter > 2)
return CAM_RANGE_ERROR;
628 unsigned char buffer[12];
629 unsigned int crc1,crc2;
640 unsigned int msb = crc1>>8;
641 unsigned int lsb = (
unsigned char)crc1;
642 buffer[6]=(
unsigned char)msb;
643 buffer[7]=(
unsigned char)lsb;
647 buffer[9]=(
unsigned char)(spotmeter);
651 lsb = (
unsigned char)(crc2);
653 buffer[10]=(
unsigned char)msb;
654 buffer[11]=(
unsigned char)lsb;
655 cout<<
"Setting spot meter mode:"<<spotmeter<<endl;
657 FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
658 if(ret !=CAM_OK){ cout<<StatusCodeToString(ret)<<endl;
return ret;}
659 ret = GetAnswer_(buffer,12);
666 if(display > 3)
return CAM_RANGE_ERROR;
668 unsigned char buffer[12];
669 unsigned int crc1,crc2;
680 unsigned int msb = crc1>>8;
681 unsigned int lsb = (
unsigned char)crc1;
682 buffer[6]=(
unsigned char)msb;
683 buffer[7]=(
unsigned char)lsb;
687 buffer[9]=(
unsigned char)(display);
691 lsb = (
unsigned char)(crc2);
693 buffer[10]=(
unsigned char)msb;
694 buffer[11]=(
unsigned char)lsb;
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);
707 unsigned char buffer[10];
708 unsigned int crc1,crc2;
719 unsigned int msb = crc1>>8;
720 unsigned int lsb = (
unsigned char)crc1;
721 buffer[6]=(
unsigned char)msb;
722 buffer[7]=(
unsigned char)lsb;
728 lsb = (
unsigned char)(crc2);
729 buffer[8]=(
unsigned char)msb;
730 buffer[9]=(
unsigned char)lsb;
732 cout<<
"Get spot value:"<<endl;
735 for(
unsigned i=0;i<10;i++)
736 cout<<showbase<<hex<<(
int)buffer[i]<<
" ";
737 cout<<noshowbase<<dec<<endl;
739 FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,10);
740 if(ret !=CAM_OK)
return ret;
742 unsigned char buffer2[12];
743 ret = GetAnswer_(buffer2,12);
744 if(ret!= CAM_OK)
return ret;
746 for(
unsigned i=0;i<12;i++)
747 cout<<showbase<<hex<<(
int)buffer2[i]<<
" ";
748 cout<<noshowbase<<dec<<endl;
758 unsigned char buffer[12];
759 unsigned int crc1,crc2;
770 unsigned int msb = crc1>>8;
771 unsigned int lsb = (
unsigned char)crc1;
772 buffer[6]=(
unsigned char)msb;
773 buffer[7]=(
unsigned char)lsb;
780 lsb = (
unsigned char)(crc2);
781 buffer[10]=(
unsigned char)msb;
782 buffer[11]=(
unsigned char)lsb;
784 cout<<
"Get sensor tmp:"<<endl;
787 for(
unsigned i=0;i<12;i++)
788 cout<<showbase<<hex<<(
int)buffer[i]<<
" ";
789 cout<<noshowbase<<dec<<endl;
791 FLIR_STATUS_MESSAGE ret = SendCommand_(buffer,12);
792 if(ret !=CAM_OK)
return ret;
794 ret = GetAnswer_(buffer,12);
795 if(ret!= CAM_OK)
return ret;
797 for(
unsigned i=0;i<12;i++)
798 cout<<showbase<<hex<<(
int)buffer[i]<<
" ";
799 cout<<noshowbase<<dec<<endl;
810 return CAM_NOT_READY;
815 return CAM_NOT_READY;
820 return CAM_NOT_READY;
826 if(!connected_ || length < 2)
return CAM_NOT_READY;
827 serialIO_.WriteBytes(buf,length);
834 if(!connected_ || length < 2)
return CAM_NOT_READY;
836 for (
int i=0;i<length;i++) buf[i]=0;
837 serialIO_.ReadBytes(buf,length,wait);
838 return CheckCameraReply_(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;
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";
FLIR_STATUS_MESSAGE SetSpotMeterDisplay(unsigned spotmeter)
FLIR_STATUS_MESSAGE DisconnectCamera()
disconnnect camera control
FLIR_STATUS_MESSAGE SetSpotMeterMode(unsigned spotmeter)
FLIR_STATUS_MESSAGE GetSpotMeterCelcius(double °ree)
FlirThermalCameraSerialControl()
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.
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.
virtual ~FlirThermalCameraSerialControl()
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 °ree)
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)