扫描头是可以进行配置的,使其支持与禁用某些条码类型,设置有两种方式,一种是扫一下对应的设置条码,另一种是通过SSI(simple serial interface)来设置,下面就讲一下SSI的设置方式。
扫描头在上电以后,就可以对其发送对应参数设置了,摩托罗拉建议设置临时参数,设置永久生效的参数会损害扫描头内部的flash,flash损坏后扫描头将无法使用,比如出现一个点的激光,正常情况是一条线。flash寿命有限,请慎重。临时设置会在扫描头断电以后丢失,每次上电的时候都要设置一次,所以建议将需要设置的参数写入到注册表中,每次上电以后从注册表读取。
附上设置的基本代码,仔细阅读注释部分(请根据自身平台修改部分实现):
static CHAR wakeup[] = {0x00}; //2's complement sum of message contents excluding checksum. static size_t __CheckSum(CHAR data[],size_t d_size) { size_t count=0; size_t sum=0; if(data == NULL || d_size <= 0) { return 0; } while(d_size--) { sum+=(data[d_size] & 0xFF); } return ((~sum)+1); } //store params to register,when power off int SetScannerSetValueToLocal(void *data,size_t len) { #ifdef WINCE HKEY hk; ULONG dw=REG_BINARY,dwDisp; ULONG dwSize=sizeof(dw); CHAR param[1024]={0}; size_t iRetVal=0; assert(data!=NULL && len>0); if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("HARDWARE\\SCANDev\\SETTING"),0,0,&hk)) { if(RegQueryValueEx(hk,_T("Value"),0,&dw,(LPBYTE)param,&dwSize)==ERROR_SUCCESS) { RegDeleteValue(hk,_T("Value")); RegSetValueEx(hk,_T("Value"),0,dw,(LPBYTE)data,len); }else { iRetVal=-1; } }else { if(ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE,_T("HARDWARE\\SCANDev\\SETTING"), 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hk, &dwDisp)) { RegSetValueEx(hk,_T("Value"),0,dw,(LPBYTE)data,len); }else { iRetVal=-1; } } RegCloseKey(hk); return iRetVal; #endif } static void __GetScannerSetValueFromLocal(void *data,size_t in_len,size_t * out_len) { #ifdef WINCE HKEY hk; ULONG dw=REG_BINARY; ULONG dwSize=sizeof(dw); CHAR param[1024]={0}; if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("HARDWARE\\SCANDev\\SETTING"),0,0,&hk)) { if(RegQueryValueEx(hk,_T("Value"),0,&dw,(LPBYTE)param,&dwSize)==ERROR_SUCCESS) { if(dwSize <=0) { return; }else { memcpy(data,param,dwSize); *out_len=dwSize; } } } RegCloseKey(hk); #endif /*end of macro WINCE*/ } //when scanner engine power on,you can call this function static size_t SetParamValues(void) { #ifdef WINCE size_t check_sum=0; CHAR param_list[1024]={0}; size_t count=0; size_t len=0,i=0; CHAR buffer[4096]={0}; //Attention!!! Temporary change - lost when power removed //Failure to meet these conditions can corrupt the scan engine's memory. //must be 0x00,0xFF,not is 0x01,0xFF CHAR temp[]={0xC6,0x04,0x00,0xFF}; __GetScannerSetValueFromLocal(param_list,sizeof(param_list),&count); if(param_list == NULL || count <= 0) { return -1; } len=sizeof(temp)/sizeof(CHAR); buffer[0]=((count+len+1)&0xFF); //length memcpy(buffer+1,temp,len); memcpy(buffer+len+1,param_list,count); check_sum=__CheckSum(buffer,len+count+1); buffer[len+count+1]=((check_sum>>8)&0xFF); //height byte buffer[len+count+2]=(check_sum&0xFF); //low byte write_com_data(wakeup,sizeof(wakeup)); _Sleep(100); //change from 70 to 100ms waiting for scanner wakeup write_com_data(buffer,len+count+3); //Length: 1 byte,CheckSum: 2 byte return 0; #endif /*end of macro WINCE*/ }
SE955 激光扫描头设置 通过SSI串口进行设置,布布扣,bubuko.com
原文地址:http://blog.csdn.net/code_style/article/details/27648031