SE955 激光扫描头设置 通过SSI串口进行设置

      扫描头是能够进行配置的,使其支持与禁用某些条码类型,设置有两种方式,一种是扫一下相应的设置条码,还有一种是通过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*/
}

write_com_data的API是平台相关性的,请依据自身平台不同改动实现。


posted @ 2017-05-30 17:16  cxchanpin  阅读(1118)  评论(0编辑  收藏  举报