GM65 two-dimensional code recognition module + command control

Introduction

MG65 barcode reading module, a scanning engine with excellent performance, not only can easily read all kinds of one-dimensional barcodes, but also can read two-dimensional barcodes at high speed, and has a very high scanning rate for linear barcodes. Barcodes on the screen can also be easily scanned.

1. Module parameters and scanning area distribution

2. Control module

1. Read the flag bit of the module

	发送命令格式:
	{Head1} {Types} {Lens} {Address} {Datas} {CRC}
			 Head1 :0x7E 0x00(2 bytes)
			Types	:0x07(1 byte)
			Lens	:0x01(1 byte)
			Address :0x0000~0x00FF(2 bytes),表示要读取的标志位的起始地址。
			Datas	:0x00~0xFF(1 byte),表示要连续读取的标志位的字节数,0x00 表示 256 个字节。
			CRC	:CRC_CCITT 校验值(2 bytes)。
			注:当用户不需要 CRC 校验功能时,可在 CRC 字节处填写 0xAB 0xCD,免校验。
	接收到数据格式:
			1:如果模块成功数据并且成功返回
			{Head2} {Types} {Lens} {Datas} {CRC}
			 Head2 :0x02 0x00
			Types	:0x00(读成功)
			Lens	:表示上传的 Datas 的字节个数,0x00 表示 256 个
			Datas	:0x00~0xFF,表示读上来的数据
			CRC   : CRC_CCITT 校 验 值 。 
			注:当用户不需要 CRC 校验功能时,可在 CRC 字节处填写 0xAB 0xCD,免校验。
			2: 下发 CRC 校验失败,无回应命令
			3:未知命令应答,无回应命令

The code is as follows (example):

unsigned int crc_cal_by_bit(unsigned char* ptr, unsigned int len)
{
    
    
	unsigned int crc = 0;
	while(len-- != 0)
	{
    
    
		for(unsigned char i = 0x80; i != 0; i /= 2)
		{
    
    
			crc *= 2;
			if((crc&0x10000) !=0) //上一位 CRC 乘 2 后,若首位是 1,则除以 0x11021
			crc ^= 0x11021;
			if((*ptr&i) != 0) //如果本位是 1,那么 CRC = 上一位的 CRC + 本位/CRC_CCITT
			crc ^= 0x1021;
		}
		ptr++;
	}
	return crc;
}

2. Write the module flag bit

	发送命令格式:
	{Head1} {Types} {Lens} {Address} {Datas} {CRC}
			 Head1 :0x7E 0x00(2 bytes)
			Types	:0x08(1 byte)
			Lens	:0x00~0xFF(1 byte),表示该命令中 Datas 字段的字节数,同时也表示要进行连续写操作的次数,而 0x00 表示有 256 个字节
			Address :0x0000~0xFFFF(2 bytes),表示要写入的标志位的起始地址
			Datas	:0x00~0xFF(1~256 bytes),表示写入标志位的数据
			CRC	:CRC_CCITT 校验值(2 bytes)。
			注:当用户不需要 CRC 校验功能时,可在 CRC 字节处填写 0xAB 0xCD,免校验。
	返回数据格式:
			1:写标志位成功
				{Head2} {Types} {Lens} {Datas} {CRC}
				 Head2 :0x02 0x00
				Types	:0x00(写成功)
				Lens	:0x01
				Datas	:0x00
				CRC	:CRC_CCITT  
			2:下发 CRC 校验失败,无回应命令
			3:未知命令应答,无回应命令
	示例:
			向地址为 0x000A 的标志位写入 0x3E
			1: 设置成功
				输入:0x7E 0x00 0x08 0x01 0x00 0x0A 0x3E 0x4C 0xCF
				返回:0x02 0x00 0x00 0x01 0x00 0x33 0x31
			2: 下发的 CRC 错误
				输入:0x7E 0x00 0x08 0x01 0x00 0x0A 0x3E 0x11 0x22
				返回:无
			3: 当发送的指令长度不够或发送 0x7e 0x00 后等待时间超过 400ms 时,当成未知命令处理
				输入:0x7E 0x00 0x08 0x01 0x00 0x0A 0x3E
				返回:无

Flag bit saved to EEPROM instruction

若要将设备标志位的内容保存到外挂的 EERPOM 中则需要发送保存命令。
	   数据发送命令格式:
			{Head1} {Types} {Lens} {Address} {Datas} {CRC}
			 Head1 :0x7E 0x00
			Types	:0x09
			Lens	:0x01
			Address :0x0000
			Datas	:0x00
			CRC	:CRC_CCITT 校验值(0xDE 0xC8)
	  接收数据格式:
			1:保存成功
				{Head2} {Types} {Lens} {Datas} {CRC}
				 Head2 :0x02 0x00
				Types	:0x00(写成功)
				Lens	:0x01
				Datas	:0x00
				CRC	:CRC_CCITT 校验值(0x33 0x31)
			2:下发 CRC 校验失败,无回应命令
			3:未知命令应答,无回应命令

Flag bit saved to EEPROM instruction

部分串口命令示例:
	 1:触发扫描串口指令为:7E 00 08 01 00 02 01 AB CD;识读模块收到触发指令后,会先输出七个字节的回应信息并同步启动扫描(回应信息内容:02 00 00 01 00 33 31)
	2:设置模块为命令触发模式,照明灯常亮,普通瞄准,启动静音,开启解码成功LED提示
		发送格式:7E 00 08 01 00 00 99 AB CD    
		接收成功后返回: 02 00 01 00 33 31
	3:设置模块为感应模式,照明灯关闭,瞄准常亮,关闭静音,关闭解码成功LED提示
		发送格式:7E 00 08 01 00 00 63 AB CD    
		接收成功后返回: 02 00 01 00 33 31
	4:从标志位0X0002中读取数据,判断是否输出解码状态提示符
		发送格式:7E 00 07 01 00 02 01 AB CD
		接收成功后返回;02 00 00 01 40 AB CD

Guess you like

Origin blog.csdn.net/qq_42250136/article/details/132283007