/*C*****************************************************************************
 * NAME:         .c
 *-------------------------------------------------------------------------------
 * RELEASE:
 * REVISION:     1.0
 *-------------------------------------------------------------------------------
 * PURMDE:
 *
 *******************************************************************************/

/*_____ I N C L U D E S ______________________________________________________*/

#include "config.h" //全局声明

/*_____ M A C R O S __________________________________________________________*/

volatile u8 MD_ConnectRX1Task_Flag = 0; // MD_Connect卡通讯任务标志位，1允许运行
volatile u8 MD_ConnectRX2Task_Flag = 0; // MD_Connect卡通讯任务标志位，1允许运行
volatile u8 MD_ConnectRX3Task_Flag = 0; // MD_Connect卡通讯任务标志位，1允许运行
volatile u8 MD_ConnectRX4Task_Flag = 0; // MD_Connect卡通讯任务标志位，1允许运行

/***********************WIFI*************************/
const char MD_WifiWSSSID[] = "AT+WAP=TXH04,45535142,1\r\n";
const char MD_WifiSOCKET[] = "AT+Socket=0,3,192.168.4.1,50000\r\n";
const char MD_WifiRSSI[] = "AT+CWJAP?\r\n";
const char MD_WifiRST[] = "AT+RES\r\n";
const char MD_ATRec[] = "AT+E=OFF\r\n";
const char MD_WMODE[] = "AT+WMODE=AP\r\n";
/*******************************L510指令***

/*_____ D E F I N I T I O N __________________________________________________*/

volatile u8 MD_Connect_TX_Buff[4][600];	 // MD_Connect卡发送缓存，DMA方式
volatile u8 MD_Connect_RX_Buff[4][1000]; // MD_Connect卡接受缓存

volatile u8 MD_Connect_TX_Flag = 1; // MD_Connect卡通讯DMA发送允许标志
/*_____ D E C L A R A T I O N ________________________________________________*/
LORA_Set_Type LORA_Set[4];

unsigned short crc16_ccitt_table[256] =
	{
		0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
		0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
		0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
		0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
		0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
		0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
		0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
		0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
		0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
		0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
		0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
		0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
		0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
		0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
		0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
		0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
		0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
		0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
		0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
		0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
		0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
		0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
		0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
		0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
		0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
		0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
		0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
		0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
		0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
		0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
		0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
		0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78};

unsigned short do_crc(unsigned char *message, unsigned int len)
{
	unsigned short crc_reg = 0;

	while (len--)
		crc_reg = (crc_reg >> 8) ^ crc16_ccitt_table[(crc_reg ^ *message++) & 0xff];

	return crc_reg;
}
/****************************************************
函数名：MD_Connect_IO_Configuration
功能  ：MD_Connect卡通讯部分用到的IO初始化
参数  ：无
返回值：无
****************************************************/
void MD_Connect_IO_Configuration(void)
{
	GPIO_InitTypeDef GPIO_InitStructure; // 定义GOIP配置结构体

	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);

	GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2);
	GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2);
	GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
	GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4);
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4);
	GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_UART5);
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_UART5);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_8 | GPIO_Pin_9;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	GPIO_Init(GPIOD, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	GPIO_Init(GPIOC, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_7 | GPIO_Pin_10;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_Init(GPIOD, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_13 | GPIO_Pin_12 | GPIO_Pin_11;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_Init(GPIOG, &GPIO_InitStructure);
	MD_Connect_LORA_IdleMode1;
	MD_Connect_LORA_IdleMode2;
	MD_Connect_LORA_IdleMode3;
	MD_Connect_LORA_IdleMode4;
}
/****************************************************
函数名：MD_Connect_NVMD_Connect_Configuration
功能  ：MD_Connect卡通讯部分用到的中断向量配置
参数  ：无
返回值：无
****************************************************/
void MD_Connect_NVIC_Configuration(void)
{
	NVIC_InitTypeDef NVIC_InitStructure; // 定义中断配置结构体

	// USART2_DMA
	NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream6_IRQn; // USART2_TX_DMA
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;		  // USART2
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;		  //
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;			  //
	NVIC_Init(&NVIC_InitStructure);							  //

	// USART3_DMA
	NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream3_IRQn; // USART2_TX_DMA
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;		  // USART2
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;		  //
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;			  //
	NVIC_Init(&NVIC_InitStructure);							  //

	// USART4_DMA
	NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream4_IRQn; // USART2_TX_DMA
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;		  // USART2
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;		  //
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;			  //
	NVIC_Init(&NVIC_InitStructure);							  //

	// USART5_DMA
	NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream7_IRQn; // USART2_TX_DMA
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;		  // USART2
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;		  //
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;			  //
	NVIC_Init(&NVIC_InitStructure);							  //
}

/****************************************************
函数名：MD_Connect_NVMD_Connect_Configuration
功能  ：MD_Connect卡通讯部分用到的串口配置
参数  ：无
返回值：无
****************************************************/
void MD_Connect_USART_Configuration(u8 PortNum, u32 Baud, u16 USART_WordLength, u8 Check)
{
	USART_InitTypeDef USART_InitStructure;

	switch (PortNum)
	{
	case 0:
	{
		RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
		USART_InitStructure.USART_BaudRate = Baud; // Baud;//?????
		if (Check == Check_EVEN)
		{
			USART_InitStructure.USART_WordLength = USART_WordLength_9b;
			USART_InitStructure.USART_Parity = USART_Parity_Even;
		}
		else if (Check == Check_ODD)
		{
			USART_InitStructure.USART_WordLength = USART_WordLength_9b;
			USART_InitStructure.USART_Parity = USART_Parity_Odd;
		}
		else if (Check == Check_NONE)
		{
			USART_InitStructure.USART_WordLength = USART_WordLength;
			USART_InitStructure.USART_Parity = USART_Parity_No;
		}
		USART_InitStructure.USART_StopBits = USART_StopBits_1;
		USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
		USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
		USART_Init(USART2, &USART_InitStructure);
		USART_Cmd(USART2, ENABLE);
		USART_ITConfig(USART2, USART_IT_IDLE, ENABLE);
		USART_ClearFlag(USART2, USART_FLAG_IDLE);

		USART_DMACmd(USART2, USART_DMAReq_Tx | USART_DMAReq_Rx, ENABLE);
	}
	break;
	case 1:
	{
		RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
		USART_InitStructure.USART_BaudRate = Baud; // Baud;//?????
		if (Check == Check_EVEN)
		{
			USART_InitStructure.USART_WordLength = USART_WordLength_9b;
			USART_InitStructure.USART_Parity = USART_Parity_Even;
		}
		else if (Check == Check_ODD)
		{
			USART_InitStructure.USART_WordLength = USART_WordLength_9b;
			USART_InitStructure.USART_Parity = USART_Parity_Odd;
		}
		else if (Check == Check_NONE)
		{
			USART_InitStructure.USART_WordLength = USART_WordLength;
			USART_InitStructure.USART_Parity = USART_Parity_No;
		}
		USART_InitStructure.USART_StopBits = USART_StopBits_1;
		USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
		USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
		USART_Init(UART4, &USART_InitStructure);
		USART_Cmd(UART4, ENABLE);

		USART_ITConfig(UART4, USART_IT_IDLE, ENABLE);
		USART_ClearFlag(UART4, USART_FLAG_IDLE);

		USART_DMACmd(UART4, USART_DMAReq_Tx | USART_DMAReq_Rx, ENABLE);
	}
	break;
	case 2:
	{
		RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
		USART_InitStructure.USART_BaudRate = Baud; // Baud;//?????
		if (Check == Check_EVEN)
		{
			USART_InitStructure.USART_WordLength = USART_WordLength_9b;
			USART_InitStructure.USART_Parity = USART_Parity_Even;
		}
		else if (Check == Check_ODD)
		{
			USART_InitStructure.USART_WordLength = USART_WordLength_9b;
			USART_InitStructure.USART_Parity = USART_Parity_Odd;
		}
		else if (Check == Check_NONE)
		{
			USART_InitStructure.USART_WordLength = USART_WordLength;
			USART_InitStructure.USART_Parity = USART_Parity_No;
		}
		USART_InitStructure.USART_StopBits = USART_StopBits_1;
		USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
		USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
		USART_Init(UART5, &USART_InitStructure);
		USART_Cmd(UART5, ENABLE);

		USART_ITConfig(UART5, USART_IT_IDLE, ENABLE);
		USART_ClearFlag(UART5, USART_FLAG_IDLE);

		USART_DMACmd(UART5, USART_DMAReq_Tx | USART_DMAReq_Rx, ENABLE);
	}
	break;
	case 3:
	{
		RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
		USART_InitStructure.USART_BaudRate = Baud; // Baud;//?????
		if (Check == Check_EVEN)
		{
			USART_InitStructure.USART_WordLength = USART_WordLength_9b;
			USART_InitStructure.USART_Parity = USART_Parity_Even;
		}
		else if (Check == Check_ODD)
		{
			USART_InitStructure.USART_WordLength = USART_WordLength_9b;
			USART_InitStructure.USART_Parity = USART_Parity_Odd;
		}
		else if (Check == Check_NONE)
		{
			USART_InitStructure.USART_WordLength = USART_WordLength;
			USART_InitStructure.USART_Parity = USART_Parity_No;
		}
		USART_InitStructure.USART_StopBits = USART_StopBits_1;
		USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
		USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
		USART_Init(USART3, &USART_InitStructure);
		USART_Cmd(USART3, ENABLE);

		USART_ITConfig(USART3, USART_IT_IDLE, ENABLE);
		USART_ClearFlag(USART3, USART_FLAG_IDLE);

		USART_DMACmd(USART3, USART_DMAReq_Tx | USART_DMAReq_Rx, ENABLE);
	}
	break;
	}
}
/*************************************************
函数名  ：DMA_Configuration（）
功能    ：DMA初始化
传入参数：无
返回值  ：无
**************************************************/
void MD_Connect_DMA_Configuration(u8 Port, u8 DateSize)
{
	DMA_InitTypeDef DMA_InitStructure;

	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
	switch (Port)
	{
	case 0:
	{
		/*******************发送TX1*********************/
		DMA_DeInit(DMA1_Stream6);
		DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
		// DMA_InitStructure.DMA_BufferSize = UART_DMA_SEND_LEN;
		DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
		DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
		if (DateSize == 8)
		{
			DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
			DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
		}
		else if (DateSize == 16)
		{
			DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
			DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
		}
		DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
		DMA_InitStructure.DMA_Priority = DMA_Priority_High;
		DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
		DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
		DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
		DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
		DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART2->DR;
		DMA_InitStructure.DMA_Channel = DMA_Channel_4;
		DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)MD_Connect_TX_Buff[0];

		DMA_Init(DMA1_Stream6, &DMA_InitStructure);
		DMA_ITConfig(DMA1_Stream6, DMA_IT_TC, ENABLE);
		// DMA_Cmd(DMA1_Stream3, ENABLE);

		/*******************RX1*********************/
		DMA_DeInit(DMA1_Stream5);
		DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
		DMA_InitStructure.DMA_BufferSize = 1000;
		DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
		DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
		DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
		DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
		DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
		DMA_InitStructure.DMA_Priority = DMA_Priority_High;
		DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
		DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
		DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
		DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
		DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART2->DR;
		DMA_InitStructure.DMA_Channel = DMA_Channel_4;
		DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)MD_Connect_RX_Buff[0];

		DMA_Init(DMA1_Stream5, &DMA_InitStructure);
		DMA_Cmd(DMA1_Stream5, ENABLE);
	}
	break;
	case 1:
	{
		/*******************发送TX2*********************/
		DMA_DeInit(DMA1_Stream4);
		DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
		// DMA_InitStructure.DMA_BufferSize = UART_DMA_SEND_LEN;
		DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
		DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
		if (DateSize == 8)
		{
			DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
			DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
		}
		else if (DateSize == 16)
		{
			DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
			DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
		}
		DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
		DMA_InitStructure.DMA_Priority = DMA_Priority_High;
		DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
		DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
		DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
		DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
		DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&UART4->DR;
		DMA_InitStructure.DMA_Channel = DMA_Channel_4;
		DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)MD_Connect_TX_Buff[1];

		DMA_Init(DMA1_Stream4, &DMA_InitStructure);
		DMA_ITConfig(DMA1_Stream4, DMA_IT_TC, ENABLE);
		// DMA_Cmd(DMA1_Stream3, ENABLE);

		/*******************RX2*********************/
		DMA_DeInit(DMA1_Stream2);
		DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
		DMA_InitStructure.DMA_BufferSize = 1000;
		DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
		DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
		DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
		DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
		DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
		DMA_InitStructure.DMA_Priority = DMA_Priority_High;
		DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
		DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
		DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
		DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
		DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&UART4->DR;
		DMA_InitStructure.DMA_Channel = DMA_Channel_4;
		DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)MD_Connect_RX_Buff[1];

		DMA_Init(DMA1_Stream2, &DMA_InitStructure);
		DMA_Cmd(DMA1_Stream2, ENABLE);
	}
	break;
	case 2:
	{
		/*******************发送TX3*********************/
		DMA_DeInit(DMA1_Stream7);
		DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
		// DMA_InitStructure.DMA_BufferSize = UART_DMA_SEND_LEN;
		DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
		DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
		if (DateSize == 8)
		{
			DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
			DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
		}
		else if (DateSize == 16)
		{
			DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
			DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
		}
		DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
		DMA_InitStructure.DMA_Priority = DMA_Priority_High;
		DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
		DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
		DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
		DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
		DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&UART5->DR;
		DMA_InitStructure.DMA_Channel = DMA_Channel_4;
		DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)MD_Connect_TX_Buff[2];

		DMA_Init(DMA1_Stream7, &DMA_InitStructure);
		DMA_ITConfig(DMA1_Stream7, DMA_IT_TC, ENABLE);
		// DMA_Cmd(DMA1_Stream7, ENABLE);

		/*******************RX3*********************/
		DMA_DeInit(DMA1_Stream0);
		DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
		DMA_InitStructure.DMA_BufferSize = 1000;
		DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
		DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
		DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
		DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
		DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
		DMA_InitStructure.DMA_Priority = DMA_Priority_High;
		DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
		DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
		DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
		DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
		DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&UART5->DR;
		DMA_InitStructure.DMA_Channel = DMA_Channel_4;
		DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)MD_Connect_RX_Buff[2];

		DMA_Init(DMA1_Stream0, &DMA_InitStructure);
		DMA_Cmd(DMA1_Stream0, ENABLE);
	}
	break;
	case 3:
	{
		/*******************发送TX4*********************/
		DMA_DeInit(DMA1_Stream3);
		DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
		// DMA_InitStructure.DMA_BufferSize = UART_DMA_SEND_LEN;
		DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
		DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
		if (DateSize == 8)
		{
			DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
			DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
		}
		else if (DateSize == 16)
		{
			DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
			DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
		}
		DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
		DMA_InitStructure.DMA_Priority = DMA_Priority_High;
		DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
		DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
		DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
		DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
		DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART3->DR;
		DMA_InitStructure.DMA_Channel = DMA_Channel_4;
		DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)MD_Connect_TX_Buff[3];

		DMA_Init(DMA1_Stream3, &DMA_InitStructure);
		DMA_ITConfig(DMA1_Stream3, DMA_IT_TC, ENABLE);
		// DMA_Cmd(DMA1_Stream3, ENABLE);

		/*******************RX4*********************/
		DMA_DeInit(DMA1_Stream1);
		DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
		DMA_InitStructure.DMA_BufferSize = 1000;
		DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
		DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
		DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
		DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
		DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
		DMA_InitStructure.DMA_Priority = DMA_Priority_High;
		DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
		DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
		DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
		DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
		DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART3->DR;
		DMA_InitStructure.DMA_Channel = DMA_Channel_4;
		DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)MD_Connect_RX_Buff[3];

		DMA_Init(DMA1_Stream1, &DMA_InitStructure);
		DMA_Cmd(DMA1_Stream1, ENABLE);
	}
	break;
	}
}
// F*****************************************************************************
//* NAME:    MD_Connect_DMATX_IRQHandler
//* PURMDE: MD_Connect卡键盘通讯DMA发送完成中断
//* PARAMS: 无
//* return:	 无
//******************************************************************************
void MD_Connect_DMATX1_IRQHandler(void)
{
	u16 i = 0;
	DMA_ClearFlag(DMA1_Stream6, DMA_IT_TCIF6);
	MD_Connect_TX1_DMAStop(); // 关闭DMA传输
	while (!USART_GetFlagStatus(USART2, USART_FLAG_TC))
		NULL;
	MD_Connect_RS485_Rx1EN;
	DMA_ClearFlag(DMA1_Stream5, DMA_IT_TCIF5);
	MD_Connect_RX1_DMAStart(); // 打开DMA传输(Gas就收)长度在选择发送队列时设置
	MD_Connect_TX_Flag = 1;
}
// F*****************************************************************************
//* NAME:    MD_Connect_DMARX_IRQHandler
//* PURMDE: DMA传输完成中断，Gas ModBus
//* PARAMS: 无
//* return:	 无
//******************************************************************************
volatile u8 DTTDYS = 0;
void MD_Connect_DMARX1_IRQHandler(void)
{
	u8 i = 0;
	if (USART_GetITStatus(USART2, USART_IT_IDLE) == SET) //?????????
	{
		i = USART2->SR;
		i = USART2->DR;
		USART_ClearFlag(USART2, USART_IT_IDLE);
		TXHData.MBCountRXIDLETimer[0].ON_OFF = 1;
		TXHData.MD_Rec_NummberB[0] = 1000 - DMA1_Stream5->NDTR;
		//		MD_Connect_RX1_DMAStop();   //关闭DMA接收
		//		DMA_ClearFlag(DMA1_Stream5, DMA_IT_TCIF5);
		//    MD_ConnectRX1Task_Flag = 1;            //使能Gas接收任务
		//		MD_Connect_RX1_DMALenSet(1000);//重置接受长度
		//		MD_Connect_RX1_DMAStart();   //打开DMA接收
	}
}
// F*****************************************************************************
//* NAME:    MD_Connect_DMATX_IRQHandler
//* PURMDE: MD_Connect卡键盘通讯DMA发送完成中断
//* PARAMS: 无
//* return:	 无
//******************************************************************************
void MD_Connect_DMATX2_IRQHandler(void)
{
	u16 i = 0;
	DMA_ClearFlag(DMA1_Stream4, DMA_IT_TCIF4);
	MD_Connect_TX2_DMAStop(); // 关闭DMA传输
	while (!USART_GetFlagStatus(UART4, USART_FLAG_TC))
		NULL;
	MD_Connect_RS485_Rx2EN;
	DMA_ClearFlag(DMA1_Stream2, DMA_IT_TCIF2);
	MD_Connect_RX2_DMAStart(); // 打开DMA传输(Gas就收)长度在选择发送队列时设置
	MD_Connect_TX_Flag = 1;
}
// F*****************************************************************************
//* NAME:    MD_Connect_DMARX_IRQHandler
//* PURMDE: DMA传输完成中断，Gas ModBus
//* PARAMS: 无
//* return:	 无
//******************************************************************************
void MD_Connect_DMARX2_IRQHandler(void)
{
	u8 i = 0;
	if (USART_GetITStatus(UART4, USART_IT_IDLE) == SET) //?????????
	{
		i = UART4->SR;
		i = UART4->DR;
		TXHData.MBCountRXIDLETimer[1].ON_OFF = 1;
		TXHData.MD_Rec_NummberB[1] = 1000 - DMA1_Stream2->NDTR;
		//		MD_Connect_RX2_DMAStop();   //关闭DMA接收
		//		DMA_ClearFlag(DMA1_Stream2, DMA_IT_TCIF2);
		//    MD_ConnectRX2Task_Flag = 1;            //使能Gas接收任务
		//		MD_Connect_RX2_DMALenSet(1000);//重置接受长度
		//		MD_Connect_RX2_DMAStart();   //打开DMA接收
	}
}
// F*****************************************************************************
//* NAME:    MD_Connect_DMATX_IRQHandler
//* PURMDE: MD_Connect卡键盘通讯DMA发送完成中断
//* PARAMS: 无
//* return:	 无
//******************************************************************************
void MD_Connect_DMATX3_IRQHandler(void)
{
	u16 i = 0;
	DMA_ClearFlag(DMA1_Stream7, DMA_IT_TCIF7);
	MD_Connect_TX3_DMAStop(); // 关闭DMA传输
	while (!USART_GetFlagStatus(UART5, USART_FLAG_TC))
		NULL;
	MD_Connect_RS485_Rx3EN;
	DMA_ClearFlag(DMA1_Stream0, DMA_IT_TCIF0);
	MD_Connect_RX3_DMAStart(); // 打开DMA传输(Gas就收)长度在选择发送队列时设置
	MD_Connect_TX_Flag = 1;
}
// F*****************************************************************************
//* NAME:    MD_Connect_DMARX_IRQHandler
//* PURMDE: DMA传输完成中断，Gas ModBus
//* PARAMS: 无
//* return:	 无
//******************************************************************************
void MD_Connect_DMARX3_IRQHandler(void)
{
	u8 i = 0;
	if (USART_GetITStatus(UART5, USART_IT_IDLE) == SET) //?????????
	{
		i = UART5->SR;
		i = UART5->DR;
		TXHData.MBCountRXIDLETimer[2].ON_OFF = 1;
		TXHData.MD_Rec_NummberB[2] = 1000 - DMA1_Stream0->NDTR;
		//		MD_Connect_RX3_DMAStop();   //关闭DMA接收
		//		DMA_ClearFlag(DMA1_Stream0, DMA_IT_TCIF0);
		//    MD_ConnectRX3Task_Flag = 1;            //使能Gas接收任务
		//		MD_Connect_RX3_DMALenSet(1000);//重置接受长度
		//		MD_Connect_RX3_DMAStart();   //打开DMA接收
	}
}
// F*****************************************************************************
//* NAME:    MD_Connect_DMATX_IRQHandler
//* PURMDE: MD_Connect卡键盘通讯DMA发送完成中断
//* PARAMS: 无
//* return:	 无
//******************************************************************************
void MD_Connect_DMATX4_IRQHandler(void)
{
	u16 i = 0;
	DMA_ClearFlag(DMA1_Stream3, DMA_IT_TCIF3);
	MD_Connect_TX4_DMAStop(); // 关闭DMA传输
	while (!USART_GetFlagStatus(USART3, USART_FLAG_TC))
		NULL;
	MD_Connect_RS485_Rx4EN;
	DMA_ClearFlag(DMA1_Stream1, DMA_IT_TCIF1);
	MD_Connect_RX4_DMAStart(); // 打开DMA传输(Gas就收)长度在选择发送队列时设置
	MD_Connect_TX_Flag = 1;
}
// F*****************************************************************************
//* NAME:    MD_Connect_DMARX_IRQHandler
//* PURMDE: DMA传输完成中断，Gas ModBus
//* PARAMS: 无
//* return:	 无
//******************************************************************************
void MD_Connect_DMARX4_IRQHandler(void)
{
	u8 i = 0;
	if (USART_GetITStatus(USART3, USART_IT_IDLE) == SET) //?????????
	{
		i = USART3->SR;
		i = USART3->DR;
		TXHData.MBCountRXIDLETimer[3].ON_OFF = 1;
		TXHData.MD_Rec_NummberB[3] = 1000 - DMA1_Stream1->NDTR;
		//		MD_Connect_RX4_DMAStop();   //关闭DMA接收
		//		DMA_ClearFlag(DMA1_Stream1, DMA_IT_TCIF1);
		//    MD_ConnectRX4Task_Flag = 1;            //使能Gas接收任务
		//		MD_Connect_RX4_DMALenSet(1000);//重置接受长度
		//		MD_Connect_RX4_DMAStart();   //打开DMA接收
	}
}
// F*****************************************************************************
//* NAME:    LTMD_TXDataCheck
//* PURMDE: LTMD通信校验函数
//* PARAMS: pData需要检验的数组地址，len数据长度
//* return:	 无
//******************************************************************************
u8 MD_Connect_TXDataCheck(volatile u8 *pData, u16 len)
{
	u8 result;
	if (len == 0)
		len = 16;
	result = *pData++;
	do
	{
		result ^= *pData++;
	} while (--len);

	return result & 0x7f;
}

u8 InteiHEXCheck(volatile u8 *pData, u16 len)
{
	u8 i;
	u8 checksum = 0;

	for (i = 0; i < len; i++)
	{
		checksum += *pData++;
	}
	return (0 - checksum);
}
// F*****************************************************************************
//* NAME:    MD_Connect_u64ToBCD
//* PURMDE: 用于u64类型转成BCD码类型
//* PARAMS: pData要转换的数据，Len长度
//* return:	 BCD类型
//******************************************************************************
u64 MD_Connect_u64ToBCD(u64 Dat)
{
	u8 i = 0;
	u64 T64 = 0, Temp = 0;
	u8 *pData;
	pData = (u8 *)&T64;
	for (i = 0; i < 8; i++)
	{
		Temp = Dat % 100;
		*(pData + i) = ((Temp / 10) << 4) + ((Temp % 10) & 0x0F);
		Dat /= 100;
	}

	return T64;
}
/**************TCP/IP校验和，IC卡通讯***************/
u16 CheckSum(u8 *buf, u16 nword)
{
	unsigned long long sum;

	for (sum = 0; nword > 0; nword--)
		sum += *buf++;

	sum = (sum >> 16) + (sum & 0xffff);
	sum += (sum >> 16);

	return ~sum;
}
u8 CheckSum8(u8 *buf, u8 len) // BCC校验函数
{
	u8 i;
	u8 checksum = 0;

	for (i = 0; i < len; i++)
	{
		checksum += *buf++;
	}
	return checksum;
}
u16 TrueCharBuffSize(char *Buff)
{
	u16 i = 0;
	while (*(Buff++))
		i++;
	return i;
}
/*************字符串转浮点数******************/
float StrToFloat(u8 *str, u8 len)
{
	u8 i = 0;
	int Temp = 0;
	float TempF = 0;
	u8 *Pi = (u8 *)&Temp;
	u8 *Pf = (u8 *)&TempF;
	for (i = 0; i < len; i++)
	{
		if (*(str + i) >= 0x30 && *(str + i) < 0x40)
		{
			Temp = Temp << 4;
			Temp |= *(str + i) - 0x30;
		}
		else if (*(str + i) > 0x40 && *(str + i) < 0x47)
		{
			Temp = Temp << 4;
			Temp |= *(str + i) - 0x37;
		}
		else
			return -1;
	}
	for (i = 0; i < len / 2; i++)
		*(Pf + i) = *(Pi + i);
	return TempF;
}
/*************字符串转整数******************/
int StrToInt(u8 *str, u8 len)
{
	u8 i = 0;
	int Temp = 0;

	for (i = 0; i < len; i++)
	{
		if (*(str + i) >= 0x30 && *(str + i) < 0x40)
		{
			Temp = Temp << 4;
			Temp |= *(str + i) - 0x30;
		}
		else if (*(str + i) > 0x40 && *(str + i) < 0x47)
		{
			Temp = Temp << 4;
			Temp |= *(str + i) - 0x37;
		}
		else
			return -1;
	}

	return Temp;
}
// F*****************************************************************************
//* NAME:    MD_Connect_BCDTou64
//* PURMDE: 用于BCD类型转成u64码类型
//* PARAMS: pData要转换的数据，Len长度
//* return:	 u64类型
//******************************************************************************
u64 MD_Connect_BCDTou64(u64 Dat)
{
	u8 i = 0;
	u64 T64 = 0;
	u8 Temp;
	for (i = 0; i < 8; i++)
	{
		Temp = Dat >> (8 * i);
		T64 += ((Temp >> 4) * 10 + (Temp & 0x0f)) * pow(100, i);
	}
	return T64;
}
u8 BCC_CheckSum(u8 *buf, u8 len) // BCC校验函数
{
	u8 i;
	u8 checksum = 0;

	for (i = 0; i < len; i++)
	{
		checksum ^= *buf++;
	}

	return checksum;
}
// 加密函数
void Bluesky_Encrypt(unsigned char *data, unsigned int len, unsigned int key)
{
	unsigned char bytes[4];
	int i = 0, j = 0;
	// 提取随机数的每个字节
	for (i = 0; i < 4; i++)
	{
		bytes[i] = (key >> (i * 8)) & 0xFF;
	}

	// 遍历数组中的每个字节
	for (i = 0; i < len; i++)
	{
		// 判断索引位置是否满足条件
		int order = (i / 2) == 0 ? 1 : -1;

		// 根据条件选择正序或倒序加密
		for (j = 0; j < 4; j++)
		{
			data[i] ^= bytes[(order == 1) ? j : (3 - j)];
		}
	}
}

// 解密函数
void Bluesky_Decrypt(unsigned char *data, unsigned int len, unsigned int key)
{
	// 解密过程与加密过程相同
	Bluesky_Encrypt(data, len, key);
}
void MD_Connect_Init(void)
{
	u8 i = 0, j = 0, Port = 0;
	MD_Connect_IO_Configuration();
	TXHData.MD_Port_Num_Top = 4;
	for (Port = 0; Port < TXHData.MD_Port_Num_Top; Port++)
	{
		MD_Connect_DMA_Configuration(Port, 8);
		MD_Port_Init(Port);
	}
	MD_Connect_NVIC_Configuration();
	TXHData.MD_LORA_SlaveTimer.Init = 0;			 // 清除初始化标志
	TXHData.MD_LORA_SlaveTimer.Flag = 0;			 // 清除到时标志
	TXHData.MD_LORA_SlaveTimer.ON_OFF = 0;			 // 打开
	TXHData.MD_LORA_SlaveTimer.Cycle = 1;			 // 设置为循环模式，发送时启动
	TXHData.MD_LORA_SlaveTimer.TimerCountMax = 1000; // 周期1000（1s）
}
void MD_Port_LORASet(u8 Port, u8 Mode)
{
	u32 MCU_ID = *(u32 *)(0x1fff7a18);

	if (Mode == LORA_Master)
	{
		switch (Port)
		{
		case 0:
			MD_Connect_LORA_SetMode1;
			break;
		case 1:
			MD_Connect_LORA_SetMode2;
			break;
		case 2:
			MD_Connect_LORA_SetMode3;
			break;
		case 3:
			MD_Connect_LORA_SetMode4;
			break;
		}
	}
	else
	{
		switch (Port)
		{
		case 0:
			MD_Connect_LORA_IdleMode1;
			break;
		case 1:
			MD_Connect_LORA_IdleMode2;
			break;
		case 2:
			MD_Connect_LORA_IdleMode3;
			break;
		case 3:
			MD_Connect_LORA_IdleMode4;
			break;
		}
	}
	delay_ms(100);
	// 设置成LORA配置参数
	MD_Connect_USART_Configuration(Port, 9600, USART_WordLength_8b, Check_NONE);
	// 暂停油机通讯
	TXHData.MBCountTimer[Port].Flag = 0;
	TXHData.MBCountTimer[Port].TimerCount = 0;
	// 计算超时
	TXHData.MD_LORA_SlaveTimer.TimerCountMax = TXHData.MD_Port_Data[Port].PortData.MBCountTime;
	TXHData.MD_LORA_SlaveTimer.ON_OFF = 1;
	LORA_Set[Port].Communication = 0x77;
	switch (TXHData.MD_Port_Data[Port].PortData.POSType)
	{
	case PosBlueSky:
		LORA_Set[Port].Communication = 0x77;
		break;
	case PosLY:
		LORA_Set[Port].Communication = 0x97;
		break;
	case PosJP:
		LORA_Set[Port].Communication = 0x97;
		break;
	case PosDart:
		LORA_Set[Port].Communication = 0x6F;
		break;
	case PosYWY:
		LORA_Set[Port].Communication = 0x67;
		break;
	case PosYGao:
		LORA_Set[Port].Communication = 0x77;
		break;
	case PosSSLan:
		LORA_Set[Port].Communication = 0x97;
		break;
	case PosBlueSkyPlus:
		LORA_Set[Port].Communication = 0xD7;
		break;
	}
	MD_Connect_TX_Buff[Port][0] = 0xC0;
	MD_Connect_TX_Buff[Port][1] = 0x00;
	MD_Connect_TX_Buff[Port][2] = 0x08;
	MD_Connect_TX_Buff[Port][3] = (MCU_ID >> 24) & 0xFF;
	MD_Connect_TX_Buff[Port][4] = (MCU_ID & 0xF0) + Port * 3;
	MD_Connect_TX_Buff[Port][5] = LORA_Set[Port].Communication;
	MD_Connect_TX_Buff[Port][6] = 0x20;
	MD_Connect_TX_Buff[Port][7] = (MCU_ID & 0x0f) + Port * 7;
	MD_Connect_TX_Buff[Port][8] = 0x80;
	MD_Connect_TX_Buff[Port][9] = 'L';
	MD_Connect_TX_Buff[Port][10] = 'T';
	switch (Port)
	{
	case 0:
	{
		MD_Connect_RS485_Tx1EN;
		MD_Connect_TX1_DMALenSet(11);
		MD_Connect_TX1_DMAStart();
	}
	break;
	case 1:
	{
		MD_Connect_RS485_Tx2EN;
		MD_Connect_TX2_DMALenSet(11);
		MD_Connect_TX2_DMAStart();
	}
	break;
	case 2:
	{
		MD_Connect_RS485_Tx3EN;
		MD_Connect_TX3_DMALenSet(11);
		MD_Connect_TX3_DMAStart();
	}
	break;
	case 3:
	{
		MD_Connect_RS485_Tx4EN;
		MD_Connect_TX4_DMALenSet(11);
		MD_Connect_TX4_DMAStart();
	}
	break;
	}
	if (TXHData.UDisk_Flag)
		Log_Task(&MD_Connect_TX_Buff[Port][0], 11, Port, Info_Issue);
	delay_ms(500);
	TXHData.MD_LORA_Slave_Flag = 1;
	switch (Port)
	{
	case 0:
		MD_Connect_LORA_IdleMode1;
		break;
	case 1:
		MD_Connect_LORA_IdleMode2;
		break;
	case 2:
		MD_Connect_LORA_IdleMode3;
		break;
	case 3:
		MD_Connect_LORA_IdleMode4;
		break;
	}
	BEEP_OFF;
}

void MD_Port_Init(u8 Port)
{
	u8 i = 0, j = 0, DeviceNum = 0;
	u8 block_count = 0, start = 0, length = 1;

	// TXHData.MD_Port_Data[0].PortData.POSType = PosSSLan;

	if (TXHData.MD_Port_Data[Port].PortData.MDConnectType == MD_LORA)
	{
		MD_Port_LORASet(Port, LORA_Master);
	}
	
	TXHData.MDConnectState[Port].Flag.WorkMode = 1;
	TXHData.MBCountRXIDLETimer[Port].Init = 0;			// 清除初始化标志
	TXHData.MBCountRXIDLETimer[Port].Flag = 0;			// 清除到时标志
	TXHData.MBCountRXIDLETimer[Port].ON_OFF = 0;		// 打开
	TXHData.MBCountRXIDLETimer[Port].Cycle = 0;			// 设置为循环模式，发送时启动
	TXHData.MBCountRXIDLETimer[Port].TimerCountMax = 5; // 周期5（0.005）

	TXHData.MBCountTimer[Port].Init = 0;															 // 清除初始化标志
	TXHData.MBCountTimer[Port].Flag = 0;															 // 清除到时标志
	TXHData.MBCountTimer[Port].ON_OFF = 1;															 // 打开
	TXHData.MBCountTimer[Port].Cycle = 1;															 // 设置为循环模式，发送时启动
	TXHData.MBCountTimer[Port].TimerCountMax = TXHData.MD_Port_Data[Port].PortData.MBCountTime * 10; // 周期
	MD_Connect_DMA_Configuration(Port, 8);
	MD_Connect_USART_Configuration(Port, TXHData.MD_Port_Data[Port].PortData.BaudRate, USART_WordLength_8b, TXHData.MD_Port_Data[Port].PortData.Parity_Even);
	switch (TXHData.MD_Port_Data[Port].PortData.POSType)
	{
	case PosBlueSky:
		TXHData.MD_Port_Info[Port].Handshake_Top = 0x05;
		break;
	case PosLY:
		TXHData.MD_Port_Info[Port].Handshake_Top = 0x11;
		break;
	case PosJP:
		TXHData.MD_Port_Info[Port].Handshake_Top = 0x07;
		break;
	case PosDart:
		TXHData.MD_Port_Info[Port].Handshake_Top = 0x04;
		break;
	case PosYWY:
		TXHData.MBCountTimer[Port].TimerCountMax = TXHData.MD_Port_Data[Port].PortData.MBCountTime * 100;
	  TXHData.MBCountRXIDLETimer[Port].TimerCountMax = 50; // 周期5（0.005）
		break;
	case PosRFID:
		TXHData.MD_Port_Info[Port].Handshake_Top = 0x03;
		break;
	case PosYGao:
		TXHData.MD_Port_Info[Port].Handshake_Top = 0x04;
		break;
	case PosHongYang:
		TXHData.MD_Port_Info[Port].Handshake_Top = 0x06;
		MD_Connect_DMA_Configuration(Port, 16);
		MD_Connect_USART_Configuration(Port, TXHData.MD_Port_Data[Port].PortData.BaudRate, USART_WordLength_9b, 0);
		break;
	case PosLanFeng:
		TXHData.MD_Port_Info[Port].Handshake_Top = 0x03;
		break;
	case PosSSLan:
		TXHData.MD_Port_Info[Port].Handshake_Top = 0x011;
		break;
	case PosBlueSkyPlus:
		TXHData.MD_Port_Info[Port].Handshake_Top = 0x03;
		break;
	case PosPLC:
		TXHData.MD_Port_Info[Port].Handshake_Top = 0x00;
		MD_Connect_USART_Configuration(Port, 9600, USART_WordLength_8b, TXHData.MD_Port_Data[Port].PortData.Parity_Even);
		break;
	case PosPrice1_4:
		TXHData.MD_Port_Info[Port].Handshake_Top = 0x02;
		TXHData.MBCountTimer[Port].TimerCountMax = TXHData.MD_Port_Data[Port].PortData.MBCountTime * 100;
		break;
	}
	if (TXHData.POS_MonitorModel == 1) // 监管模式
	{
		TXHData.MD_Port_Info[Port].Handshake_Top = 0;
		TXHData.MBCountRXIDLETimer[Port].TimerCountMax = 1; // 周期5（0.005）
		MD_Connect_RS485_Rx1EN;
		MD_Connect_RS485_Rx2EN;
		MD_Connect_RS485_Rx3EN;
		MD_Connect_RS485_Rx4EN;
	}
	/*****************************************计算多枪相关设备***************************************************/
	TXHData.MD_Port_Info[Port].GunInfo[0].FatherNum = 0; // 记录每个设备的付设备号
	TXHData.MD_Port_Info[Port].GunInfo[0].SonNum = 0;	 // 记录每个设备在付设备中的位置
	for (DeviceNum = 1; DeviceNum < TXHData.MD_Port_Data[Port].PortData.DeviceNumber; DeviceNum++)
	{
		if (TXHData.MD_Port_Data[Port].GunData[DeviceNum].GunAddr == TXHData.MD_Port_Data[Port].GunData[DeviceNum - 1].GunAddr) // 和上一个枪地址相同，属于同一个泵
		{
			length++; // 子设备数增加
		}
		else
		{
			TXHData.MD_Port_Info[Port].FatherDevice[block_count].SonStart = start;
			TXHData.MD_Port_Info[Port].FatherDevice[block_count].Address = TXHData.MD_Port_Data[Port].GunData[DeviceNum - 1].GunAddr;
			TXHData.MD_Port_Info[Port].FatherDevice[block_count].SonNumber = length;
			block_count++; // 泵号增加
			start = DeviceNum;
			length = 1;
		}
		TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].FatherNum = block_count; // 记录每个设备的付设备号
		TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].SonNum = length - 1;	   // 记录每个设备在付设备中的位置
	}
	TXHData.MD_Port_Info[Port].FatherDeviceTop = block_count + 1;
	TXHData.MD_Port_Info[Port].FatherDevice[block_count].SonStart = start;
	TXHData.MD_Port_Info[Port].FatherDevice[block_count].Address = TXHData.MD_Port_Data[Port].GunData[DeviceNum - 1].GunAddr;
	TXHData.MD_Port_Info[Port].FatherDevice[block_count].SonNumber = length;
	TXHData.MD_Port_Info[Port].FatherDevice[block_count].LTDelayTimer.Init = 0;																													// 清除初始化标志
	TXHData.MD_Port_Info[Port].FatherDevice[block_count].LTDelayTimer.Flag = 0;																													// 清除到时标志
	TXHData.MD_Port_Info[Port].FatherDevice[block_count].LTDelayTimer.ON_OFF = 0;																													// 打开
	TXHData.MD_Port_Info[Port].FatherDevice[block_count].LTDelayTimer.Cycle = 0;																													// 设置为循环模式，发送时启动
	TXHData.MD_Port_Info[Port].FatherDevice[block_count].LTDelayTimer.TimerCountMax = 1000;
	
	for (DeviceNum = 0; DeviceNum < TXHData.MD_Port_Data[Port].PortData.DeviceNumber; DeviceNum++)
	{
		TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].LTDelayTimer.Init = 0;																													// 清除初始化标志
		TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].LTDelayTimer.Flag = 0;																													// 清除到时标志
		TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].LTDelayTimer.ON_OFF = 0;																													// 打开
		TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].LTDelayTimer.Cycle = 0;																													// 设置为循环模式，发送时启动
		TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].LTDelayTimer.TimerCountMax = TXHData.MD_Port_Data[Port].PortData.MBCountTime * 10 * TXHData.MD_Port_Data[Port].PortData.DeviceNumber * 2; // 周期1000（1S）
		TXHData.MD_Port_Data[Port].GunData[DeviceNum].GunState.Flag.Online = 0;
		TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].Handshake = 0;
		TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].GunVersion.VersionFindFlag = 0;
		switch (TXHData.MD_Port_Data[Port].PortData.POSType)
		{
		case PosBlueSky:
			TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].MB_CMD_Next = C_MDConnectASKControlPower;
			break;
		case PosLY:
			TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].MB_CMD_Next = LY_MDConnectCmdPoll;
			break;
		case PosJP:
			TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].MB_CMD_Next = LY_MDConnectCmdPoll;
			break;
		case PosYWY:
			TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].MB_CMD_Next = YWY_MDConnectCmdReadData;
			break;
		case PosRFID:
		{
			TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].MB_CMD_Next = RFID_MDConnectCmdReadVersion;
			for (i = 0; i < TXHData.MD_Port_Num_Top; i++)
			{
				for (j = 0; j < TXHData.MD_Port_Data[i].PortData.DeviceNumber; j++)
				{
					if (TXHData.MD_Port_Data[i].GunData[j].GunNummber == TXHData.MD_Port_Data[Port].GunData[DeviceNum].RFIDBinding)
					{
						TXHData.MD_Port_Info[i].GunInfo[j].AssociatedDevices.Number = TXHData.MD_Port_Data[Port].GunData[DeviceNum].GunNummber;
						TXHData.MD_Port_Info[i].GunInfo[j].AssociatedDevices.Port = Port;
						TXHData.MD_Port_Info[i].GunInfo[j].AssociatedDevices.location = DeviceNum;
						TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].AssociatedDevices.Number = TXHData.MD_Port_Data[i].GunData[j].GunNummber;
						TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].AssociatedDevices.Port = i;
						TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].AssociatedDevices.location = j;
					}
				}
			}
		}
		break;
		case PosYGao:
			TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].MB_CMD_Next = YG_MDConnectControlMode;
			TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].Price = TXHData.PrintLastRecord[Port * 16 + DeviceNum].Price;
			break;
		case PosHongYang:
			TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].MB_CMD_Next = HY_MDConnectASKControlPower;
			break;
		case PosLanFeng:
			TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].MB_CMD_Next = LF_MDConnectASKControlPower;
			break;
		case PosBlueSkyPlus:
			TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].MB_CMD_Next = LTP_GunCMDReadStateAndData;
			break;
		case PosPLC:
			TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].MB_CMD_Next = PLC_MDConnectCmdReadData;
			break;
		case PosPrice1_4:
			TXHData.MD_Port_Info[Port].GunInfo[DeviceNum].MB_CMD_Next = Price_MDConnectCmdReadParameter;
			break;
		}
	}
	/***************************************************多枪协议**************************************************************/
	if (TXHData.MD_Port_Data[Port].PortData.POSType == PosDart || TXHData.MD_Port_Data[Port].PortData.POSType == PosSSLan || TXHData.MD_Port_Data[Port].PortData.POSType == PosBlueSkyPlus)
	{
		for (DeviceNum = 0; DeviceNum < TXHData.MD_Port_Info[Port].FatherDeviceTop; DeviceNum++)
		{
			switch (TXHData.MD_Port_Data[Port].PortData.POSType)
			{
			case PosDart:
				TXHData.MD_Port_Info[Port].FatherDevice[DeviceNum].MB_CMD_Next = DART_MDConnectCmdPoll;
				break;
			case PosSSLan:
				TXHData.MD_Port_Info[Port].FatherDevice[DeviceNum].MB_CMD_Next = LY_MDConnectCmdPoll;
				break;
			case PosBlueSkyPlus:
				TXHData.MD_Port_Info[Port].FatherDevice[DeviceNum].MB_CMD_Next = LTP_DriverCMDReadVerAndMac;
				break;
			}
		}
	}
	TXHData.MD_Gun_Num_Top = 0;
}
// F*****************************************************************************
//* NAME:    KeyBoardTask
//* PURMDE: KeyBoard键盘通讯处理任务
//* PARAMS: 无
//* return:	无
//******************************************************************************
volatile u16 HY_SendBuff[25];
volatile u8 zhtningzhuangtai = 0;
void MD_ConnectTXTask(u8 Port, u8 GunNum, u8 MD_TX_CMD)
{
	volatile u16 i = 0, j = 0, k = 0, l = 0;
	volatile u8 PosTypeTemp = 0, GunAddr = 0, FatherNum = 0;
	volatile u64 TempBCD = 0, Tempu64 = 0;
	volatile u16 MD_ConnectTX_Len = 0; // 长度
	u8 Encrypt_Flag1 = 0;
	u8 Encrypt_Flag2 = 0;
	volatile u16 MD_Port_Num = 0, DeviceNumber = 0;
	u8 MD_ConnectRX_Check = 0; // 校验变量
	u8 Data_201[7] = "i20100";
	u8 Data_20E[7] = "i20E00";

	u16 CRCTemp = 0;
	MD_Connect_TX_Flag = 0;
	{
		PosTypeTemp = TXHData.MD_Port_Data[Port].PortData.POSType;
		if (TXHData.MBCountCutNum[Port][GunNum] > 5)
		{
			TXHData.MBCountCutNum[Port][GunNum] = 6;
			if (TXHData.MD_Port_Data[Port].PortData.POSType == PosDart || TXHData.MD_Port_Data[Port].PortData.POSType == PosSSLan || TXHData.MD_Port_Data[Port].PortData.POSType == PosBlueSkyPlus) // 多枪
			{
				TXHData.MD_Port_Info[Port].FatherDevice[GunNum].Handshake = 0;
				for (i = 0; i < TXHData.MD_Port_Info[Port].FatherDevice[GunNum].SonNumber; i++)
				{
					TXHData.MD_Port_Data[Port].GunData[TXHData.MD_Port_Info[Port].FatherDevice[GunNum].SonStart + i].GunState.Flag.Online = 0;
					TXHData.MD_Port_Info[Port].GunInfo[TXHData.MD_Port_Info[Port].FatherDevice[GunNum].SonStart + i].ROM_UpData_State.Flag.BaudRateSync_Flag = 0;
					TXHData.MD_Port_Info[Port].GunInfo[TXHData.MD_Port_Info[Port].FatherDevice[GunNum].SonStart + i].ROM_UpData_State.Flag.Update_Flag = 0;
					TXHData.MD_Port_Info[Port].GunInfo[TXHData.MD_Port_Info[Port].FatherDevice[GunNum].SonStart + i].Handshake = 0;
					TXHData.MD_Port_Info[Port].GunInfo[TXHData.MD_Port_Info[Port].FatherDevice[GunNum].SonStart + i].MB_CMD_Next = LTP_GunCMDReadStateAndData;
				}
				switch (TXHData.MD_Port_Data[Port].PortData.POSType)
				{
				case PosDart:
					TXHData.MD_Port_Info[Port].FatherDevice[GunNum].MB_CMD_Next = DART_MDConnectCmdPoll;
					break;
				case PosSSLan:
					TXHData.MD_Port_Info[Port].FatherDevice[GunNum].MB_CMD_Next = LY_MDConnectCmdPoll;
					break;
				case PosBlueSkyPlus:
					TXHData.MD_Port_Info[Port].FatherDevice[GunNum].MB_CMD_Next = LTP_DriverCMDReadVerAndMac;
					break;
				}
			}
			else // 单枪
			{
				TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake = 0;
				TXHData.MD_Port_Data[Port].GunData[GunNum].GunState.Flag.Online = 0;
				// MD_Connect_USART_Configuration(Port,TXHData.MD_Port_Data[Port].PortData.BaudRate,TXHData.MD_Port_Data[Port].PortData.Parity_Even);
				TXHData.MD_Port_Info[Port].GunInfo[GunNum].ROM_UpData_State.Flag.BaudRateSync_Flag = 0;
				TXHData.MD_Port_Info[Port].GunInfo[GunNum].ROM_UpData_State.Flag.Update_Flag = 0;
				switch (TXHData.MD_Port_Data[Port].PortData.POSType)
				{
				case PosBlueSky:
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next = C_MDConnectASKControlPower;
					break;
				case PosLY:
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next = LY_MDConnectCmdPoll;
					break;
				case PosJP:
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next = LY_MDConnectCmdPoll;
					break;
				case PosYWY:
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next = YWY_MDConnectCmdReadData;
					break;
				case PosRFID:
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next = RFID_MDConnectCmdReadVersion;
					break;
				case PosYGao:
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next = YG_MDConnectControlMode;
					break;
				case PosHongYang:
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next = HY_MDConnectASKControlPower;
					break;
				case PosLanFeng:
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next = LF_MDConnectASKControlPower;
					break;
				case PosPLC:
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next = PLC_MDConnectCmdReadData;
					TXHData.CNGPLCState.Flag.Online = 0;
					break;
				case PosPrice1_4:
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next = Price_MDConnectCmdReadParameter;
					TXHData.MD_Port_Info[Port].PriceTagData.State.State = 0;
					break;
				}
			}
		}
	}
	if (TXHData.MDConnectState[Port].Flag.WorkMode == 1) // 数据模式
	{
		if (TXHData.POS_MonitorModel != 1 && PosTypeTemp) // 非监管模式有线模式
		{
			switch (PosTypeTemp)
			{
			case PosBlueSky:
			{
				GunAddr = MD_Connect_u64ToBCD(TXHData.MD_Port_Data[Port].GunData[GunNum].GunAddr);
				if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake == TXHData.MD_Port_Info[Port].Handshake_Top)
					TXHData.MD_Port_Info[Port].LoopGunNextFlag = 1;
				TXHData.MBCountCutNum[Port][GunNum]++;
				if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].ROM_UpData_State.Flag.BaudRateSync_Flag == 1)
				{
					MD_Connect_USART_Configuration(Port, BaudRateSync, USART_WordLength_9b, TXHData.MD_Port_Data[Port].PortData.Parity_Even);
				}
				else
				{
					MD_Connect_USART_Configuration(Port, TXHData.MD_Port_Data[Port].PortData.BaudRate, USART_WordLength_9b, TXHData.MD_Port_Data[Port].PortData.Parity_Even);
				}
				switch (MD_TX_CMD)
				{
				case C_MDConnectCmdReadState: // 读状态
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = C_MDConnectCmdReadState;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				case C_MDConnectCmdReadFuelState: // 读数据
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = C_MDConnectCmdReadFuelState;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				case C_MDConnectCmdWritePrsetSale: // 预置金额
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					if (TXHData.MD_Port_Data[Port].PortData.Device_Type == Display_664)
					{
						if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >= 0x900000)
							Tempu64 = 0x900000;
						else
							Tempu64 = TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue;
						MD_Connect_TX_Buff[Port][2] = 0xA5;
						for (i = 0; i < 3; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = (Tempu64 >> ((2 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][6] = C_MDConnectCmdWritePrsetSale;
						MD_Connect_TX_Buff[Port][7] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 6); // 校验
						MD_ConnectTX_Len = 8;
					}
					else
					{
						if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >= 0x90000000)
							Tempu64 = 0x90000000;
						else
							Tempu64 = TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue;
						MD_Connect_TX_Buff[Port][2] = 0xA6;
						for (i = 0; i < 4; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = (Tempu64 >> ((3 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][7] = C_MDConnectCmdWritePrsetSale;
						MD_Connect_TX_Buff[Port][8] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 7); // 校验
						MD_ConnectTX_Len = 9;
					}
				}
				break;
				case C_MDConnectCmdWritePrsetVolume: // 预置油量
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					if (TXHData.MD_Port_Data[Port].PortData.Device_Type == Display_664)
					{
						if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue == 0x900000)
							Tempu64 = 0x900000;
						else
							Tempu64 = TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue;
						MD_Connect_TX_Buff[Port][2] = 0xA5;
						for (i = 0; i < 3; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = (Tempu64 >> ((2 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][6] = C_MDConnectCmdWritePrsetVolume;
						MD_Connect_TX_Buff[Port][7] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 6); // 校验
						MD_ConnectTX_Len = 8;
					}
					else
					{
						if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue == 0x90000000)
							Tempu64 = 0x90000000;
						else
							Tempu64 = TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue;
						MD_Connect_TX_Buff[Port][2] = 0xA6;
						for (i = 0; i < 4; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = (Tempu64 >> ((3 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][7] = C_MDConnectCmdWritePrsetVolume;
						MD_Connect_TX_Buff[Port][8] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 7); // 校验
						MD_ConnectTX_Len = 9;
					}
				}
				break;
				case C_MDConnectCmdStart: // 启动
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = C_MDConnectCmdStart;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				case C_MDConnectCmdStop: // 停机
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = C_MDConnectCmdStop;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				case C_MDConnectPauseFueling: // 暂停
				{
					zhtningzhuangtai = 1;
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = C_MDConnectPauseFueling;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				case C_MDConnectResumeFueling: // 继续
				{
					zhtningzhuangtai = 2;
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = C_MDConnectResumeFueling;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				case C_MDConnectCmdReadPrice: // 读单价
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = C_MDConnectCmdReadPrice;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				case C_MDConnectCmdWritePrice: // xie单价
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					if (TXHData.MD_Port_Data[Port].PortData.Device_Type == Display_664)
					{
						MD_Connect_TX_Buff[Port][2] = 0xA4;
						for (i = 0; i < 2; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price) >> ((1 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][5] = C_MDConnectCmdWritePrice;
						MD_Connect_TX_Buff[Port][6] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 5); // 校验
						MD_ConnectTX_Len = 7;
					}
					else
					{
						MD_Connect_TX_Buff[Port][2] = 0xA5;
						for (i = 0; i < 3; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price) >> ((2 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][6] = C_MDConnectCmdWritePrice;
						MD_Connect_TX_Buff[Port][7] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 6); // 校验
						MD_ConnectTX_Len = 8;
					}
				}
				break;
				case C_MDConnectCmdWritePulseCoefficient: // xie
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头MD_Connect_u64ToBCD(TXHData.PulseCoefficient[GunNum - 1]
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA6;
					for (i = 0; i < 4; i++)
					{
						MD_Connect_TX_Buff[Port][3 + i] = ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].PulseCoefficient) >> ((3 - i) * 8)) & 0xff;
					}
					MD_Connect_TX_Buff[Port][7] = C_MDConnectCmdWritePulseCoefficient;
					MD_Connect_TX_Buff[Port][8] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 7); // 校验
					MD_ConnectTX_Len = 9;
				}
				break;
				case C_MDConnectCmdReadTotal: // 读总累
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = C_MDConnectCmdReadTotal;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				case C_MDConnectCmdWriteTotal: // xie总累
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					if (TXHData.MD_Port_Data[Port].PortData.Device_Type == Display_664)
					{
						MD_Connect_TX_Buff[Port][2] = 0xAc;
						for (i = 0; i < 5; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].CTOTAL.TotalLit) >> ((4 - i) * 8)) & 0xff;
						}
						for (i = 0; i < 5; i++)
						{
							MD_Connect_TX_Buff[Port][8 + i] = ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].CTOTAL.TotalMoney) >> ((4 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][13] = C_MDConnectCmdWriteTotal;
						MD_Connect_TX_Buff[Port][14] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 13); // 校验
						MD_ConnectTX_Len = 15;
					}
					else
					{
						MD_Connect_TX_Buff[Port][2] = 0xAe;
						for (i = 0; i < 6; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].CTOTAL.TotalLit) >> ((5 - i) * 8)) & 0xff;
						}
						for (i = 0; i < 6; i++)
						{
							MD_Connect_TX_Buff[Port][9 + i] = ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].CTOTAL.TotalMoney) >> ((5 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][15] = C_MDConnectCmdWriteTotal;
						MD_Connect_TX_Buff[Port][16] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 15); // 校验
						MD_ConnectTX_Len = 17;
					}
				}
				break;
				case C_MDConnectASKControlPower: // 要控制权
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = C_MDConnectASKControlPower;
					// MD_Connect_TX_Buff[Port][3] = C_MDConnectReturnControlPower;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				case C_MDConnectReturnControlPower: // 还控制权
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = C_MDConnectReturnControlPower;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				case C_MDConnectCmdReadVersion: // 读版本号
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = C_MDConnectCmdReadVersion;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake = 0x01;
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next = C_MDConnectCmdReadState;
				}
				break;
				case C_MDConnectCmdSetBaudRate: // 同步波特率
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA5;
					MD_Connect_TX_Buff[Port][3] = (115200 >> 16) & 0xff;
					MD_Connect_TX_Buff[Port][4] = (115200 >> 8) & 0xff;
					MD_Connect_TX_Buff[Port][5] = 115200 & 0xff;
					MD_Connect_TX_Buff[Port][6] = C_MDConnectCmdSetBaudRate;
					MD_Connect_TX_Buff[Port][7] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 6); // 校验
					MD_ConnectTX_Len = 8;
				}
				break;
				case C_MDConnectCmdSendFrame: // 传送帧
				{
					MD_Connect_TX_Buff[Port][0] = 0xF5;
					MD_Connect_TX_Buff[Port][1] = GunAddr;
					MD_Connect_TX_Buff[Port][2] = 0xff;
					for (i = 0; i < 10; i++)
						MD_Connect_TX_Buff[Port][3 + i] = TXHData.MD_Port_Data[Port].PortData.ROM_UpData_Version[i];
					MD_Connect_TX_Buff[Port][13] = TXHData.MD_Port_Data[Port].PortData.ROM_UpData.FrameTop >> 8;
					MD_Connect_TX_Buff[Port][14] = TXHData.MD_Port_Data[Port].PortData.ROM_UpData.FrameTop;
					MD_Connect_TX_Buff[Port][15] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].FrameNow >> 8;
					MD_Connect_TX_Buff[Port][16] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].FrameNow;
					AT45DBItemRead(CA_DeviceFrame, TXHData.MD_Port_Info[Port].GunInfo[GunNum].FrameNow + Port * 1024);
					for (i = 0; i < 512; i++)
						MD_Connect_TX_Buff[Port][17 + i] = TXHData.Frame[i];
					MD_Connect_TX_Buff[Port][529] = C_MDConnectCmdSendFrame;
					MD_Connect_TX_Buff[Port][530] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 529);
					MD_ConnectTX_Len = 531;
				}
				break;
				}
			}
			break;
			case PosBlueSkyPlus:
			{
				FatherNum = GunNum;																		   // 这离GunNum表示泵号
				GunAddr = MD_Connect_u64ToBCD(TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].Address); // 泵地址
				if (TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].Handshake == TXHData.MD_Port_Info[Port].Handshake_Top)
					TXHData.MD_Port_Info[Port].LoopGunNextFlag = 1;
				TXHData.MBCountCutNum[Port][FatherNum]++;
				//					if(TXHData.MD_Port_Info[Port].GunInfo[GunNum].ROM_UpData_State.Flag.BaudRateSync_Flag == 1)
				//					{
				//						MD_Connect_USART_Configuration(Port,BaudRateSync,USART_WordLength_9b,TXHData.MD_Port_Data[Port].PortData.Parity_Even);
				//						}
				//					else
				//					{
				//					  MD_Connect_USART_Configuration(Port,TXHData.MD_Port_Data[Port].PortData.BaudRate,USART_WordLength_9b,TXHData.MD_Port_Data[Port].PortData.Parity_Even);
				//						}
				TXHData.RNGData = RNG_GetRandomNumber();
				MD_Connect_TX_Buff[Port][0] = 0xFB;	   // 帧头
				MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
				MD_Connect_TX_Buff[Port][4] = TXHData.CTIME.Year;
				MD_Connect_TX_Buff[Port][5] = TXHData.CTIME.Month;
				MD_Connect_TX_Buff[Port][6] = TXHData.CTIME.Day;
				MD_Connect_TX_Buff[Port][7] = TXHData.CTIME.Hour;
				MD_Connect_TX_Buff[Port][8] = TXHData.CTIME.Min;
				MD_Connect_TX_Buff[Port][9] = TXHData.CTIME.Sec;
				for (i = 0; i < 4; i++)
					MD_Connect_TX_Buff[Port][10 + i] = TXHData.RNGData >> (8 * (3 - i));
				MD_Connect_TX_Buff[Port][14] = TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].SonNumber;
				MD_ConnectTX_Len = 15;
				switch (MD_TX_CMD)
				{
				case LTP_DriverCMDReadPassword: //
				{
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = LTP_DriverCMD;
					MD_ConnectTX_Len++;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = MD_TX_CMD;
					MD_ConnectTX_Len++;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].Password_Lever;
					MD_ConnectTX_Len++;
				}
				break;
				case LTP_DriverCMDWritePassword: //
				{
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = LTP_DriverCMD;
					MD_ConnectTX_Len++;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = MD_TX_CMD;
					MD_ConnectTX_Len++;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].Password_Lever;
					MD_ConnectTX_Len++;
					for (i = 0; i < 4; i++)
						MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + i] = TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].Password >> (8 * (3 - i));
					MD_ConnectTX_Len += 4;
				}
				break;
				case LTP_DriverCMDReadVerAndMac: //
				{
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = LTP_DriverCMD;
					MD_ConnectTX_Len++;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = MD_TX_CMD;
					MD_ConnectTX_Len++;
				}
				break;
				case LTP_DriverCMDLock: //
				{
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = LTP_DriverCMD;
					MD_ConnectTX_Len++;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = MD_TX_CMD;
					MD_ConnectTX_Len++;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].LockType;
					MD_ConnectTX_Len++;
					switch (TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].LockType)
					{
					case 0:
					{
					}
					break;
					case 1:
					{
						for (i = 0; i < 3; i++)
							MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + i] = TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].LockTime[i];
						MD_ConnectTX_Len += 3;
					}
					break;
					case 2:
					{
						for (i = 0; i < 6; i++)
							MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + i] = TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].LockValue[i];
						MD_ConnectTX_Len += 6;
					}
					break;
					}
				}
				break;
				case LTP_DriverCMDUnlock: //
				{
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = LTP_DriverCMD;
					MD_ConnectTX_Len++;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = MD_TX_CMD;
					MD_ConnectTX_Len++;
				}
				break;
				case LTP_DriverCMDSendFrame: //
				{
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = LTP_DriverCMD;
					MD_ConnectTX_Len++;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = MD_TX_CMD;
					MD_ConnectTX_Len++;
					for (i = 0; i < 10; i++)
						MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + i] = TXHData.MD_Port_Data[Port].PortData.ROM_UpData_Version[i];
					MD_ConnectTX_Len += 10;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = TXHData.MD_Port_Data[Port].PortData.ROM_UpData.FrameTop >> 8;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = TXHData.MD_Port_Data[Port].PortData.ROM_UpData.FrameTop;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].FrameNow >> 8;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].FrameNow;
					AT45DBItemRead(CA_DeviceFrame, TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].FrameNow + Port * 1024);
					for (i = 0; i < 512; i++)
						MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + i] = TXHData.Frame[i];
					MD_ConnectTX_Len += 512;

					TXHData.MBCountTimer[Port].TimerCountMax = 120; // 周期调整ms
				}
				break;
				default:
				{
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = LTP_GunCMD;
					for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].SonNumber; DeviceNumber++)
					{
						GunNum = TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].SonStart + DeviceNumber; //
						MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = DeviceNumber + 1;
						MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next;
						switch (TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next)
						{
						case LTP_GunCMDReadState:		 //
						case LTP_GunCMDReadStateAndData: //
						case LTP_GunCMDReadTotal:		 //
						case LTP_GunCMDStop:			 //
						case LTP_GunCMDReadEvent:		 //
						case LTP_GunCMDReadError:		 //
						{
							MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = 0;
						}
						break;
						case LTP_GunCMDSuspend: //
						{
							MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = 0;
						}
						break;
						case LTP_GunCMDContinue: //
						{
							MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = 0;
						}
						break;
						case LTP_GunCMDWritePrset: //
						{
							MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = 5;
							MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresteType;
							for (i = 0; i < 4; i++)
								MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >> (8 * (3 - i));
							MD_ConnectTX_Len += 4;
						}
						break;
						case LTP_GunCMDAuthorize: //
						{
							MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = 9;
							MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresteType;
							for (i = 0; i < 4; i++)
								MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >> (8 * (3 - i));
							MD_ConnectTX_Len += 4;
							MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = 0;
							for (i = 0; i < 3; i++)
								MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price >> (8 * (2 - i));
							MD_ConnectTX_Len += 3;
						}
						break;
						case LTP_GunCMDReadParameter: //
						{
							MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].ParameterNumber;
							MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = 0;
						}
						break;
						case LTP_GunCMDWriteParameter: //
						{
							switch (TXHData.MD_Port_Info[Port].GunInfo[GunNum].ParameterNumber)
							{
							case 0x01: // 单价
							{
								MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = 4;
								MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].ParameterNumber;
								for (i = 0; i < 3; i++)
									MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price >> (8 * (2 - i));
								MD_ConnectTX_Len += 3;
							}
							break;
							case 0x02: // 脉当
							{
								MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = 4;
								MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].ParameterNumber;
								for (i = 0; i < 3; i++)
									MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].PulseCoefficient >> (8 * (2 - i));
								MD_ConnectTX_Len += 3;
							}
							break;
							case 0x03: // 提前关阀量
							{
								MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = 3;
								MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].ParameterNumber;
								for (i = 0; i < 2; i++)
									MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].ValveValue >> (8 * (1 - i));
								MD_ConnectTX_Len += 2;
							}
							break;
							case 0x04: // 最小显示值
							{
								MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = 3;
								MD_Connect_TX_Buff[Port][MD_ConnectTX_Len++] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].ParameterNumber;
								for (i = 0; i < 2; i++)
									MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].MinDisplay >> (8 * (1 - i));
								MD_ConnectTX_Len += 2;
							}
							break;
							}
						}
						break;
						}
					}
					if (DeviceNumber == 0)
					{
						if (CoreDebug->DHCSR & 1)
						{					 // check C_DEBUGEN == 1 -> Debugger Connected
							__breakpoint(0); // halt program execution here
						}
					}
				}
				break;
				}
				MD_Connect_TX_Buff[Port][2] = (MD_ConnectTX_Len >> 8) & 0xff;
				MD_Connect_TX_Buff[Port][3] = MD_ConnectTX_Len & 0xff;

				Bluesky_Encrypt(&MD_Connect_TX_Buff[Port][14], MD_ConnectTX_Len - 14, TXHData.RNGData);

				CRCTemp = CRC_Check(&MD_Connect_TX_Buff[Port][0], MD_ConnectTX_Len); // 校验
				MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = (CRCTemp >> 8) & 0xff;
				MD_ConnectTX_Len++;
				MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = CRCTemp & 0xff;
				MD_ConnectTX_Len++;
			}
			break;
			case PosLY:
			{
				GunAddr = TXHData.MD_Port_Data[Port].GunData[GunNum].GunAddr;
				if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake == TXHData.MD_Port_Info[Port].Handshake_Top)
					TXHData.MD_Port_Info[Port].LoopGunNextFlag = 1;
				TXHData.MBCountCutNum[Port][GunNum]++;
				if (GunAddr > 0)
					GunAddr -= 1;
				switch (MD_TX_CMD)
				{
				case LY_MDConnectCmdHandshake: // 握手
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x30;
					MD_Connect_TX_Buff[Port][4] = 0x30;
					MD_Connect_TX_Buff[Port][5] = (TXHData.MD_Port_Info[Port].GunInfo[GunNum].LYHandshakeCRC >> 4) & 0x0f;
					if (MD_Connect_TX_Buff[Port][5] < 0x0A)
						MD_Connect_TX_Buff[Port][5] += 0x30;
					else
						MD_Connect_TX_Buff[Port][5] = MD_Connect_TX_Buff[Port][5] - 0x0A + 0x41;
					MD_Connect_TX_Buff[Port][6] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].LYHandshakeCRC & 0x0f;
					if (MD_Connect_TX_Buff[Port][6] < 0x0A)
						MD_Connect_TX_Buff[Port][6] += 0x30;
					else
						MD_Connect_TX_Buff[Port][6] = MD_Connect_TX_Buff[Port][6] - 0x0A + 0x41;
					MD_Connect_TX_Buff[Port][7] = 0x03;
					MD_Connect_TX_Buff[Port][8] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 7); // 校验
					MD_ConnectTX_Len = 9;
					//							if(TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake == 0x06)
					//							{
					//								TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake = 0x07;
					//								}
					TXHData.MD_Port_Info[Port].LoopGunNextFlag = 0;
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake = 0x08;
				}
				break;
				case LY_MDConnectCmdPoll: // 轮询
				{
					MD_Connect_TX_Buff[Port][0] = 0x04;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x51;
					MD_Connect_TX_Buff[Port][3] = 0x05;
					MD_ConnectTX_Len = 4;
				}
				break;
				case LY_MDConnectCmdReadState: // 读状态
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x31;
					MD_Connect_TX_Buff[Port][4] = 0x35;
					MD_Connect_TX_Buff[Port][5] = 0x03;
					MD_Connect_TX_Buff[Port][6] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 5); // 校验
					MD_ConnectTX_Len = 7;
				}
				break;
				case LY_MDConnectCmdReadTotal: // 读状态
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x32;
					MD_Connect_TX_Buff[Port][4] = 0x30;
					MD_Connect_TX_Buff[Port][5] = 0x03;
					MD_Connect_TX_Buff[Port][6] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 5); // 校验
					MD_ConnectTX_Len = 7;
				}
				break;
				case LY_MDConnectCmdChoiceGun: // 选择枪
				{
					MD_Connect_TX_Buff[Port][0] = 0x04;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x05;
					MD_ConnectTX_Len = 4;
					//							if(TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake == 0x02)
					//							{
					//								TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake = 0x03;
					//								}
				}
				break;
				case LY_MDConnectCmdDisauthorize: // 取消授权
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x31;
					MD_Connect_TX_Buff[Port][4] = 0x32;
					MD_Connect_TX_Buff[Port][5] = 0x03;
					MD_Connect_TX_Buff[Port][6] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 5); // 校验
					MD_ConnectTX_Len = 7;
					TXHData.MD_Port_Data[Port].GunData[GunNum].GunState.Flag.AuthorizeState = 0;
				}
				break;
				case LY_MDConnectCmdAuthorize: // 授权
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x31;
					MD_Connect_TX_Buff[Port][4] = 0x30;
					if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >= 0x900000)
						MD_Connect_TX_Buff[Port][5] = 0x30;
					else
					{
						MD_Connect_TX_Buff[Port][5] = 0x32;
					}
					if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresteType == Preset_Volume)
						MD_Connect_TX_Buff[Port][6] = 0x31;
					else if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresteType == Preset_Sale)
						MD_Connect_TX_Buff[Port][6] = 0x32;
					for (i = 0; i < 6; i++)
						MD_Connect_TX_Buff[Port][7 + i] = 0x30 + ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >> (5 - i) * 4) & 0x0f);
					MD_Connect_TX_Buff[Port][13] = 0x32;
					for (i = 0; i < 4; i++)
						MD_Connect_TX_Buff[Port][14 + i] = 0x30 + ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price >> (3 - i) * 4) & 0x0f);
					MD_Connect_TX_Buff[Port][18] = 0x03;
					MD_Connect_TX_Buff[Port][19] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 18); // 校验
					MD_ConnectTX_Len = 20;
				}
				break;
				case LY_MDConnectCmdWritePrice: // 写单价
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x32;
					MD_Connect_TX_Buff[Port][4] = 0x31;
					MD_Connect_TX_Buff[Port][5] = 0x32;

					MD_Connect_TX_Buff[Port][6] = 0x32;
					for (i = 0; i < 4; i++)
						MD_Connect_TX_Buff[Port][7 + i] = 0x30 + ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price >> (3 - i) * 4) & 0x0f);
					for (i = 0; i < 25; i++)
						MD_Connect_TX_Buff[Port][11 + i] = 0x30;
					MD_Connect_TX_Buff[Port][36] = 0x03;
					MD_Connect_TX_Buff[Port][37] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 36); // 校验
					MD_ConnectTX_Len = 38;
				}
				break;
				case LY_MDConnectCmdACK0: // 1030
				{
					MD_Connect_TX_Buff[Port][0] = 0x10;
					MD_Connect_TX_Buff[Port][1] = 0x30;
					MD_ConnectTX_Len = 2;
				}
				break;
				case LY_MDConnectCmdACK1: // 1031
				{
					MD_Connect_TX_Buff[Port][0] = 0x10;
					MD_Connect_TX_Buff[Port][1] = 0x31;
					MD_ConnectTX_Len = 2;
				}
				break;
				}
			}
			break;
			case PosJP:
			{
				GunAddr = TXHData.MD_Port_Data[Port].GunData[GunNum].GunAddr;
				if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake == TXHData.MD_Port_Info[Port].Handshake_Top)
					TXHData.MD_Port_Info[Port].LoopGunNextFlag = 1;
				TXHData.MBCountCutNum[Port][GunNum]++;
				if (GunAddr > 0)
					GunAddr -= 1;
				switch (MD_TX_CMD)
				{
				case LY_MDConnectCmdPoll: // 轮询
				{
					MD_Connect_TX_Buff[Port][0] = 0x04;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x51;
					MD_Connect_TX_Buff[Port][3] = 0x05;
					MD_ConnectTX_Len = 4;
				}
				break;
				case LY_MDConnectCmdReadState: // 读状态
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x31;
					MD_Connect_TX_Buff[Port][4] = 0x35;
					MD_Connect_TX_Buff[Port][5] = 0x03;
					MD_Connect_TX_Buff[Port][6] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 5); // 校验
					MD_ConnectTX_Len = 7;
				}
				break;
				case LY_MDConnectCmdReadTotal: // 读
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x32;
					MD_Connect_TX_Buff[Port][4] = 0x30;
					MD_Connect_TX_Buff[Port][5] = 0x03;
					MD_Connect_TX_Buff[Port][6] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 5); // 校验
					MD_ConnectTX_Len = 7;
				}
				break;
				case LY_MDConnectCmdChoiceGun: // 选择枪
				{
					MD_Connect_TX_Buff[Port][0] = 0x04;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x05;
					MD_ConnectTX_Len = 4;
				}
				break;
				case LY_MDConnectCmdDisauthorize: // 取消授权
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x31;
					MD_Connect_TX_Buff[Port][4] = 0x32;
					MD_Connect_TX_Buff[Port][5] = 0x03;
					MD_Connect_TX_Buff[Port][6] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 5); // 校验
					TXHData.MD_Port_Data[Port].GunData[GunNum].GunState.Flag.AuthorizeState = 0;
					MD_ConnectTX_Len = 7;
				}
				break;
				case LY_MDConnectCmdAuthorize: // 授权
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x31;
					MD_Connect_TX_Buff[Port][4] = 0x41;
					if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue == 0x90000000)
						MD_Connect_TX_Buff[Port][5] = 0x30;
					else
					{
						MD_Connect_TX_Buff[Port][5] = 0x32;
					}
					if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresteType == Preset_Volume)
						MD_Connect_TX_Buff[Port][6] = 0x31;
					else if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresteType == Preset_Sale)
						MD_Connect_TX_Buff[Port][6] = 0x32;
					for (i = 0; i < 8; i++)
						MD_Connect_TX_Buff[Port][7 + i] = 0x30 + ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >> (7 - i) * 4) & 0x0f);

					MD_Connect_TX_Buff[Port][15] = 0x32;
					for (i = 0; i < 6; i++)
						MD_Connect_TX_Buff[Port][16 + i] = 0x30 + ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price >> (5 - i) * 4) & 0x0f);
					MD_Connect_TX_Buff[Port][22] = 0x30;
					for (i = 0; i < 6; i++)
						MD_Connect_TX_Buff[Port][23 + i] = 0x30;
					MD_Connect_TX_Buff[Port][29] = 0x30;
					for (i = 0; i < 6; i++)
						MD_Connect_TX_Buff[Port][30 + i] = 0x30;
					MD_Connect_TX_Buff[Port][36] = 0x30;
					for (i = 0; i < 6; i++)
						MD_Connect_TX_Buff[Port][37 + i] = 0x30;
					MD_Connect_TX_Buff[Port][43] = 0x30;
					for (i = 0; i < 6; i++)
						MD_Connect_TX_Buff[Port][44 + i] = 0x30;
					MD_Connect_TX_Buff[Port][50] = 0x30;
					for (i = 0; i < 6; i++)
						MD_Connect_TX_Buff[Port][51 + i] = 0x30;

					MD_Connect_TX_Buff[Port][57] = 0x03;
					MD_Connect_TX_Buff[Port][58] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 57); // 校验
					MD_ConnectTX_Len = 59;
				}
				break;
				case LY_MDConnectCmdWritePrice: // 写单价
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x32;
					MD_Connect_TX_Buff[Port][4] = 0x31;
					MD_Connect_TX_Buff[Port][5] = 0x33;

					MD_Connect_TX_Buff[Port][6] = 0x32;
					for (i = 0; i < 6; i++)
						MD_Connect_TX_Buff[Port][7 + i] = 0x30 + ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price >> (5 - i) * 4) & 0x0f);
					for (i = 0; i < 25; i++)
						MD_Connect_TX_Buff[Port][13 + i] = 0x30;
					MD_Connect_TX_Buff[Port][38] = 0x03;
					MD_Connect_TX_Buff[Port][39] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 38); // 校验
					MD_ConnectTX_Len = 40;
				}
				break;
				case LY_MDConnectCmdACK0: // 1030
				{
					MD_Connect_TX_Buff[Port][0] = 0x10;
					MD_Connect_TX_Buff[Port][1] = 0x30;
					MD_ConnectTX_Len = 2;
				}
				break;
				case LY_MDConnectCmdACK1: // 1031
				{
					MD_Connect_TX_Buff[Port][0] = 0x10;
					MD_Connect_TX_Buff[Port][1] = 0x31;
					MD_ConnectTX_Len = 2;
				}
				break;
				}
			}
			break;
			case PosDart:
			{
				GunAddr = TXHData.MD_Port_Data[Port].GunData[GunNum].GunAddr;
				if (TXHData.MD_Port_Info[Port].GunInfo[i].Handshake == TXHData.MD_Port_Info[Port].Handshake_Top)
					TXHData.MD_Port_Info[Port].LoopGunNextFlag = 1;
				TXHData.MBCountCutNum[Port][GunNum]++;
				for (i = 0; i < TXHData.MD_Port_Data[Port].PortData.DeviceNumber; i++)
					if (GunAddr == TXHData.MD_Port_Data[Port].GunData[i].GunAddr)
						break;
				// SunNum = GunNum - TXHData.MD_Port_Data[Port].GunData[i].GunNummber + 1;//确认同一地址的第几条枪

				if (GunAddr > 0)
					GunAddr -= 1;

				if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].DartSeq < 0x0f) // 序列号自动增加
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].DartSeq++;
				else
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].DartSeq = 0;
				switch (MD_TX_CMD)
				{
				case DART_MDConnectCmdPoll: // 轮询
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr + 0x50; // 帧头
					MD_Connect_TX_Buff[Port][1] = 0x20;			  // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xFA;
					MD_ConnectTX_Len = 3;
				}
				break;
				case DART_MDConnectCmdReadState: // 读状态
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr + 0x50;											 // 帧头
					MD_Connect_TX_Buff[Port][1] = 0x30 | TXHData.MD_Port_Info[Port].GunInfo[GunNum].DartSeq; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x01;
					MD_Connect_TX_Buff[Port][3] = 0x01;
					MD_Connect_TX_Buff[Port][4] = 0x00;
					Tempu64 = DartCRC16(&MD_Connect_TX_Buff[Port][0], 5);
					MD_Connect_TX_Buff[Port][5] = Tempu64 & 0xff;
					MD_Connect_TX_Buff[Port][6] = (Tempu64 >> 8) & 0xff;
					MD_Connect_TX_Buff[Port][7] = 0x03;
					MD_Connect_TX_Buff[Port][8] = 0xFA; // 校验
					MD_ConnectTX_Len = 9;
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next = DART_MDConnectCmdPoll;
				}
				break;
				case DART_MDConnectCmdReadVTotal: // 读50 33 65 01 14 DE C8 03 FA
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr + 0x50;											 // 帧头
					MD_Connect_TX_Buff[Port][1] = 0x30 | TXHData.MD_Port_Info[Port].GunInfo[GunNum].DartSeq; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x65;
					MD_Connect_TX_Buff[Port][3] = 0x01;
					MD_Connect_TX_Buff[Port][4] = 0x00;
					Tempu64 = DartCRC16(&MD_Connect_TX_Buff[Port][0], 5);
					MD_Connect_TX_Buff[Port][5] = Tempu64 & 0xff;
					MD_Connect_TX_Buff[Port][6] = (Tempu64 >> 8) & 0xff;
					MD_Connect_TX_Buff[Port][7] = 0x03;
					MD_Connect_TX_Buff[Port][8] = 0xFA; // 校验
					MD_ConnectTX_Len = 9;
				}
				break;
				case DART_MDConnectCmdReadPTotal: // 读
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr + 0x50;											 // 帧头
					MD_Connect_TX_Buff[Port][1] = 0x30 | TXHData.MD_Port_Info[Port].GunInfo[GunNum].DartSeq; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x65;
					MD_Connect_TX_Buff[Port][3] = 0x01;
					MD_Connect_TX_Buff[Port][4] = 0x10;
					Tempu64 = DartCRC16(&MD_Connect_TX_Buff[Port][0], 5);
					MD_Connect_TX_Buff[Port][5] = Tempu64 & 0xff;
					MD_Connect_TX_Buff[Port][6] = (Tempu64 >> 8) & 0xff;
					MD_Connect_TX_Buff[Port][7] = 0x03;
					MD_Connect_TX_Buff[Port][8] = 0xFA; // 校验
					MD_ConnectTX_Len = 9;
				}
				break;
				case DART_MDConnectCmdReStart: // 重新握手50 3F 01 01 05 03 04 00 09 00 01 48 A3 03 FA
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr + 0x50;											 // 帧头
					MD_Connect_TX_Buff[Port][1] = 0x30 | TXHData.MD_Port_Info[Port].GunInfo[GunNum].DartSeq; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x01;
					MD_Connect_TX_Buff[Port][3] = 0x01;
					MD_Connect_TX_Buff[Port][4] = 0x05;
					Tempu64 = DartCRC16(&MD_Connect_TX_Buff[Port][0], 5);
					MD_Connect_TX_Buff[Port][5] = Tempu64 & 0xff;
					MD_Connect_TX_Buff[Port][6] = (Tempu64 >> 8) & 0xff;
					MD_Connect_TX_Buff[Port][7] = 0x03;
					MD_Connect_TX_Buff[Port][8] = 0xFA; // 校验
					MD_ConnectTX_Len = 9;
				}
				break;
				case DART_MDConnectCmdACK: // 1030
				{
					if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].LYGunNeedCMD != DART_MDConnectCmdPoll)
					{
						TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next = TXHData.MD_Port_Info[Port].GunInfo[GunNum].LYGunNeedCMD;
						TXHData.MD_Port_Info[Port].GunInfo[GunNum].LYGunNeedCMD = DART_MDConnectCmdPoll;
					}
					MD_Connect_TX_Buff[Port][0] = GunAddr + 0x50;											 // 帧头
					MD_Connect_TX_Buff[Port][1] = 0xC0 | TXHData.MD_Port_Info[Port].GunInfo[GunNum].DartSeq; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xFA;
					MD_ConnectTX_Len = 3;
				}
				break;
				}
			}
			break;
			case PosYWY:
			{
				TXHData.MD_Port_Info[Port].LoopGunNextFlag = 1;
				TXHData.MBCountCutNum[Port][GunNum]++;
				switch (TXHData.MD_Port_Data[Port].PortData.Device_Type)
				{
				case YWY_Bluesky:
				{
					switch (MD_TX_CMD)
					{
					case YWY_MDConnectCmdReadData: // 读数据
					{
						for (i = 0; i < 7; i++)
							MD_Connect_TX_Buff[Port][i] = Data_201[i];
						MD_ConnectTX_Len = 7;
					}
					break;
					case YWY_MDConnectCmdWriteApacity: // 下载罐容表
					{
						for (i = 0; i < 7; i++)
							MD_Connect_TX_Buff[Port][i] = Data_20E[i];
						MD_ConnectTX_Len = 7;
					}
					break;
					}
				}
				break;
				case YWY_Probe_KY:
				{
					GunAddr = GunNum + 1;
					// TXHData.MBCountCutNum[Port][i] ++;
					MD_Connect_TX_Buff[Port][0] = GunAddr;
					MD_Connect_TX_Buff[Port][1] = 0x03;
					MD_Connect_TX_Buff[Port][2] = 0x00;
					MD_Connect_TX_Buff[Port][3] = 0x02;
					MD_Connect_TX_Buff[Port][4] = 0x00;
					MD_Connect_TX_Buff[Port][5] = 0x09;
					Tempu64 = CRC_Check(&MD_Connect_TX_Buff[Port][0], 6);
					MD_Connect_TX_Buff[Port][7] = Tempu64 >> 8;
					MD_Connect_TX_Buff[Port][6] = Tempu64;
					MD_ConnectTX_Len = 8;
				}
				break;
				case YWY_Pressure:
				{
					GunAddr = GunNum + 1;
					// TXHData.MBCountCutNum[0][i] ++;
					MD_Connect_TX_Buff[Port][0] = GunAddr;
					MD_Connect_TX_Buff[Port][1] = 0x03;
					MD_Connect_TX_Buff[Port][2] = 0x00;
					MD_Connect_TX_Buff[Port][3] = 0x00;
					MD_Connect_TX_Buff[Port][4] = 0x00;
					MD_Connect_TX_Buff[Port][5] = 0x02;
					Tempu64 = CRC_Check(&MD_Connect_TX_Buff[Port][0], 6);
					MD_Connect_TX_Buff[Port][7] = Tempu64 >> 8;
					MD_Connect_TX_Buff[Port][6] = Tempu64;
					MD_ConnectTX_Len = 8;
				}
				break;
				}
			}
			break;
			case PosRFID:
			{
				GunAddr = TXHData.MD_Port_Data[Port].GunData[GunNum].GunAddr;
				if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake == TXHData.MD_Port_Info[Port].Handshake_Top)
					TXHData.MD_Port_Info[Port].LoopGunNextFlag = 1;
				TXHData.MBCountCutNum[Port][GunNum]++;
				//					if(TXHData.MD_Port_Info[Port].GunInfo[GunNum].SonDevice.SonNumber > 0)//这个设备支持多枪协议
				//					{
				//						for(i = 0;i < TXHData.MD_Port_Info[Port].GunInfo[GunNum].SonDevice.SonNumber;i ++)
				//						  if(TXHData.MD_Port_Info[Port].GunInfo[GunNum+i].Handshake != TXHData.MD_Port_Info[Port].Handshake_Top)
				//								break;
				//						if(i == TXHData.MD_Port_Info[Port].GunInfo[GunNum].SonDevice.SonNumber && MD_TX_CMD != RFID_MDConnectCmdROMownload)//所有枪都握手完成,并且不是在线升级指令,使用多枪指令
				//						  MD_TX_CMD = RFID_MDConnectCmdAllData;
				//					  }
				switch (MD_TX_CMD)
				{
					//						case RFID_MDConnectCmdAllData://读所有枪状态
					//						{
					//							if(TXHData.MD_Port_Info[Port].GunInfo[GunNum].SonDevice.SonNumber > 0)//这个设备支持多枪协议
					//							{
					//								if(GunAddr == TXHData.MD_Port_Info[Port].GunInfo[GunNum].SonDevice.SonAddress[0] ||
					//									 GunAddr == TXHData.MD_Port_Info[Port].GunInfo[GunNum].SonDevice.SonAddress[1] ||
					//								   GunAddr == TXHData.MD_Port_Info[Port].GunInfo[GunNum].SonDevice.SonAddress[2] ||
					//								   GunAddr == TXHData.MD_Port_Info[Port].GunInfo[GunNum].SonDevice.SonAddress[3])//第一个地址，跳过剩下的地址
					//								{
					//									TXHData.MD_Port_Info[Port].pGunNow += TXHData.MD_Port_Info[Port].GunInfo[GunNum].SonDevice.SonNumber-1 ;
					//									}
					//								}
					//							MD_Connect_TX_Buff[Port][0] = 0xF5;//
					//							MD_Connect_TX_Buff[Port][1] = GunAddr;
					//							MD_Connect_TX_Buff[Port][2] = 0;
					//							MD_Connect_TX_Buff[Port][3] = 0;
					//							MD_Connect_TX_Buff[Port][4] = RFID_MDConnectCmdAllData;
					//							MD_ConnectTX_Len = 5;//缓存数据位置
					//							for(DeviceNumber = 0;DeviceNumber < TXHData.MD_Port_Info[Port].GunInfo[GunNum].SonDevice.SonNumber;DeviceNumber ++)
					//							{
					//								switch(TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].MB_CMD_Next)  // 根据命令字节进行不同的操作
					//								{
					//									case RFID_MDConnectCmdReadData:  //轮询
					//									{
					//										MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = TXHData.MD_Port_Data[Port].GunData[GunNum + DeviceNumber].GunAddr;
					//										MD_ConnectTX_Len ++;
					//										MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].MB_CMD_Next;
					//										MD_ConnectTX_Len ++;
					//									}break;
					//									case RFID_MDConnectCmdWriteCardInfo://写授权信息 RFID_MDConnectCmdWriteFullingInfo
					//									{
					//										MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = TXHData.MD_Port_Data[Port].GunData[GunNum + DeviceNumber].GunAddr;
					//										MD_ConnectTX_Len ++;
					//										MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].MB_CMD_Next;
					//										MD_ConnectTX_Len ++;
					//										MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].RFIDState;
					//										MD_ConnectTX_Len ++;
					//										if(TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].RFIDState == 0x01)
					//										{
					//											for(i = 0;i < 15;i ++)
					//												MD_Connect_TX_Buff[Port][MD_ConnectTX_Len+i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].RFIDUserName[i];
					//											MD_ConnectTX_Len += 15;
					//											for(i = 0;i < 10;i ++)
					//												MD_Connect_TX_Buff[Port][MD_ConnectTX_Len+i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].CarLicensePlate[i];
					//											MD_ConnectTX_Len += 10;
					//											MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].BalanceDecimal;
					//											MD_ConnectTX_Len += 1;
					//											for(i = 0;i < 5;i ++)
					//												MD_Connect_TX_Buff[Port][MD_ConnectTX_Len+i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].Balance[i];
					//											MD_ConnectTX_Len += 5;
					//											}
					//										else if(TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].RFIDState == 0x20)
					//										{
					//											for(i = 0;i < 4;i ++)
					//												MD_Connect_TX_Buff[Port][MD_ConnectTX_Len+i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].Balance[i];
					//											MD_ConnectTX_Len += 4;
					//											}
					//										}break;
					//									case RFID_MDConnectCmdWriteFullingInfo://写实时信息
					//									{
					//										MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = TXHData.MD_Port_Data[Port].GunData[GunNum + DeviceNumber].GunAddr;
					//										MD_ConnectTX_Len ++;
					//										MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].MB_CMD_Next;
					//										MD_ConnectTX_Len ++;
					//										MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].RFIDState;
					//										MD_ConnectTX_Len ++;
					//										MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].BalanceDecimal;
					//										MD_ConnectTX_Len ++;
					//										for(i = 0;i < 5;i ++)
					//											MD_Connect_TX_Buff[Port][MD_ConnectTX_Len+i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum + DeviceNumber].Balance[i];
					//										MD_ConnectTX_Len += 5;
					//										}break;
					//									}
					//								}
					//							MD_Connect_TX_Buff[Port][2] = MD_ConnectTX_Len >> 8;
					//							MD_Connect_TX_Buff[Port][3] = MD_ConnectTX_Len;
					//							Tempu64 = CRC_Check(&MD_Connect_TX_Buff[Port][0],MD_ConnectTX_Len);
					//							MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = Tempu64 >> 8;
					//							MD_ConnectTX_Len ++;
					//							MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = Tempu64;
					//							MD_ConnectTX_Len ++;
					//							}break;
				case RFID_MDConnectCmdReadData: // 读状态
				{
					MD_Connect_TX_Buff[Port][0] = 0xF5;
					MD_Connect_TX_Buff[Port][1] = GunAddr;
					MD_Connect_TX_Buff[Port][2] = 0x00;
					MD_Connect_TX_Buff[Port][3] = 0x05;
					MD_Connect_TX_Buff[Port][4] = RFID_MDConnectCmdReadData;
					Tempu64 = CRC_Check(&MD_Connect_TX_Buff[Port][0], 5);
					MD_Connect_TX_Buff[Port][5] = Tempu64 >> 8;
					MD_Connect_TX_Buff[Port][6] = Tempu64;
					MD_ConnectTX_Len = 7;
				}
				break;
				case RFID_MDConnectCmdLossACK: //
				case RFID_MDConnectCmdFindACK: //
				{
					MD_Connect_TX_Buff[Port][0] = 0xF5;
					MD_Connect_TX_Buff[Port][1] = GunAddr;
					MD_Connect_TX_Buff[Port][2] = 0x00;
					MD_Connect_TX_Buff[Port][3] = 0x05;
					MD_Connect_TX_Buff[Port][4] = MD_TX_CMD;
					Tempu64 = CRC_Check(&MD_Connect_TX_Buff[Port][0], 5);
					MD_Connect_TX_Buff[Port][5] = Tempu64 >> 8;
					MD_Connect_TX_Buff[Port][6] = Tempu64;
					MD_ConnectTX_Len = 7;
				}
				break;
				case RFID_MDConnectCmdWriteCardInfo: // 写授权信息 RFID_MDConnectCmdWriteFullingInfo
				{
					MD_Connect_TX_Buff[Port][0] = 0xF5;
					MD_Connect_TX_Buff[Port][1] = GunAddr;
					MD_Connect_TX_Buff[Port][2] = 0x00;

					MD_Connect_TX_Buff[Port][4] = RFID_MDConnectCmdWriteCardInfo;
					MD_Connect_TX_Buff[Port][5] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].RFIDState;
					if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].RFIDState == 0x01)
					{
						MD_ConnectTX_Len = 37;
						for (i = 0; i < 15; i++)
							MD_Connect_TX_Buff[Port][6 + i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].RFIDUserName[i];
						for (i = 0; i < 10; i++)
							MD_Connect_TX_Buff[Port][21 + i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].CarLicensePlate[i];
						MD_Connect_TX_Buff[Port][31] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].BalanceDecimal;
						for (i = 0; i < 5; i++)
							MD_Connect_TX_Buff[Port][32 + i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].Balance[i];
					}
					else if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].RFIDState == 0x20)
					{
						MD_ConnectTX_Len = 10;
						for (i = 0; i < 4; i++)
							MD_Connect_TX_Buff[Port][6 + i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].Balance[i];
					}
					else
					{
						MD_ConnectTX_Len = 6;
					}
					MD_Connect_TX_Buff[Port][3] = MD_ConnectTX_Len;
					Tempu64 = CRC_Check(&MD_Connect_TX_Buff[Port][0], MD_ConnectTX_Len);
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = Tempu64 >> 8;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + 1] = Tempu64;
					MD_ConnectTX_Len = MD_ConnectTX_Len + 2;
				}
				break;
				case RFID_MDConnectCmdWriteFullingInfo: // 写实时信息
				{
					MD_Connect_TX_Buff[Port][0] = 0xF5;
					MD_Connect_TX_Buff[Port][1] = GunAddr;
					MD_Connect_TX_Buff[Port][2] = 0x00;

					MD_Connect_TX_Buff[Port][4] = RFID_MDConnectCmdWriteFullingInfo;
					MD_Connect_TX_Buff[Port][5] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].RFIDState;
					MD_ConnectTX_Len = 12;
					MD_Connect_TX_Buff[Port][6] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].BalanceDecimal;
					for (i = 0; i < 5; i++)
						MD_Connect_TX_Buff[Port][7 + i] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].Balance[i];
					MD_Connect_TX_Buff[Port][3] = MD_ConnectTX_Len;
					Tempu64 = CRC_Check(&MD_Connect_TX_Buff[Port][0], MD_ConnectTX_Len);
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = Tempu64 >> 8;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + 1] = Tempu64;
					MD_ConnectTX_Len = MD_ConnectTX_Len + 2;
				}
				break;
				case RFID_MDConnectCmdWriteBindingInfo: // 下发绑定信息
				{
					MD_ConnectTX_Len = 6;
					MD_Connect_TX_Buff[Port][0] = 0xF5;
					MD_Connect_TX_Buff[Port][1] = GunAddr;
					MD_Connect_TX_Buff[Port][2] = 0x00;
					MD_Connect_TX_Buff[Port][3] = MD_ConnectTX_Len;
					MD_Connect_TX_Buff[Port][4] = RFID_MDConnectCmdWriteBindingInfo;
					MD_Connect_TX_Buff[Port][5] = TXHData.MD_Port_Data[Port].GunData[GunNum].RFIDBinding;

					Tempu64 = CRC_Check(&MD_Connect_TX_Buff[Port][0], MD_ConnectTX_Len);
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = Tempu64 >> 8;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + 1] = Tempu64;
					MD_ConnectTX_Len = MD_ConnectTX_Len + 2;
				}
				break;
				case RFID_MDConnectCmdReadVersion: // 读版本
				{
					MD_Connect_TX_Buff[Port][0] = 0xF5;
					MD_Connect_TX_Buff[Port][1] = GunAddr;
					MD_Connect_TX_Buff[Port][2] = 0x00;
					MD_Connect_TX_Buff[Port][3] = 0x05;
					MD_Connect_TX_Buff[Port][4] = RFID_MDConnectCmdReadVersion;
					Tempu64 = CRC_Check(&MD_Connect_TX_Buff[Port][0], 5);
					MD_Connect_TX_Buff[Port][5] = Tempu64 >> 8;
					MD_Connect_TX_Buff[Port][6] = Tempu64;
					MD_ConnectTX_Len = 7;
				}
				break;
				case RFID_MDConnectCmdROMownload: // 固件下发
				{
					MD_ConnectTX_Len = 531;
					MD_Connect_TX_Buff[Port][0] = 0xF5;
					MD_Connect_TX_Buff[Port][1] = GunAddr;
					MD_Connect_TX_Buff[Port][2] = MD_ConnectTX_Len >> 8;
					MD_Connect_TX_Buff[Port][3] = MD_ConnectTX_Len & 0xff;
					MD_Connect_TX_Buff[Port][4] = RFID_MDConnectCmdROMownload;
					for (i = 0; i < 10; i++)
						MD_Connect_TX_Buff[Port][5 + i] = TXHData.MD_Port_Data[Port].PortData.ROM_UpData_Version[i];
					MD_Connect_TX_Buff[Port][15] = TXHData.MD_Port_Data[Port].PortData.ROM_UpData.FrameTop >> 8;
					MD_Connect_TX_Buff[Port][16] = TXHData.MD_Port_Data[Port].PortData.ROM_UpData.FrameTop;
					MD_Connect_TX_Buff[Port][17] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].FrameNow >> 8;
					MD_Connect_TX_Buff[Port][18] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].FrameNow;
					AT45DBItemRead(CA_DeviceFrame, TXHData.MD_Port_Info[Port].GunInfo[GunNum].FrameNow + Port * 1024);
					for (i = 0; i < 512; i++)
						MD_Connect_TX_Buff[Port][19 + i] = TXHData.Frame[i];
					Tempu64 = CRC_Check(&MD_Connect_TX_Buff[Port][0], MD_ConnectTX_Len);
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len] = Tempu64 >> 8;
					MD_Connect_TX_Buff[Port][MD_ConnectTX_Len + 1] = Tempu64;
					MD_ConnectTX_Len = MD_ConnectTX_Len + 2;
				}
				break;
				}
			}
			break;
			case PosYGao:
			{
				GunAddr = (TXHData.MD_Port_Data[Port].GunData[GunNum].GunAddr);
				if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake == TXHData.MD_Port_Info[Port].Handshake_Top)
					TXHData.MD_Port_Info[Port].LoopGunNextFlag = 1;
				TXHData.MBCountCutNum[Port][GunNum]++;
				switch (MD_TX_CMD)
				{
				case YG_MDConnectCmdReadFuelVolumeState: // 读状态+数据
				{
					MD_Connect_TX_Buff[Port][0] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][1] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][2] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][3] = MD_TX_CMD;
					MD_Connect_TX_Buff[Port][4] = GunAddr;										 // 枪号
					MD_Connect_TX_Buff[Port][5] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][3], 2); // 校验
					MD_ConnectTX_Len = 6;
				}
				break;
				case YG_MDConnectCmdReadFuelRecord: // 读记录
				{
					MD_Connect_TX_Buff[Port][0] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][1] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][2] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][3] = MD_TX_CMD;
					MD_Connect_TX_Buff[Port][4] = GunAddr;										 // 枪号
					MD_Connect_TX_Buff[Port][5] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][3], 2); // 校验
					MD_ConnectTX_Len = 6;
				}
				break;
				case YG_MDConnectCmdReadFuelRecordConfirm: // 读记录确认信息
				{
					MD_Connect_TX_Buff[Port][0] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][1] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][2] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][3] = MD_TX_CMD;
					MD_Connect_TX_Buff[Port][4] = GunAddr;										 // 枪号
					MD_Connect_TX_Buff[Port][5] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][3], 2); // 校验
					MD_ConnectTX_Len = 6;
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].MB_CMD_Next = YG_MDConnectCmdReadFuelVolumeState;
				}
				break;
				case YG_MDConnectCmdWritePrset: // 预置
				{
					MD_Connect_TX_Buff[Port][0] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][1] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][2] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][3] = MD_TX_CMD;
					MD_Connect_TX_Buff[Port][4] = GunAddr; // 枪号

					if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresteType == Preset_Volume)
					{
						if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >= 0x90000000)
							Tempu64 = 0x900000;
						else
							Tempu64 = TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue;
						for (i = 0; i < 3; i++)
						{
							MD_Connect_TX_Buff[Port][5 + i] = (Tempu64 >> ((2 - i) * 8)) & 0xff;
						}
						Tempu64 = 0;
						for (i = 0; i < 4; i++)
						{
							MD_Connect_TX_Buff[Port][8 + i] = (Tempu64 >> ((3 - i) * 8)) & 0xff;
						}
						for (i = 0; i < 3; i++)
						{
							MD_Connect_TX_Buff[Port][12 + i] = (Tempu64 >> ((2 - i) * 8)) & 0xff;
						}
						Tempu64 = TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price;
						for (i = 0; i < 3; i++)
						{
							MD_Connect_TX_Buff[Port][15 + i] = (Tempu64 >> ((2 - i) * 8)) & 0xff;
						}
						Tempu64 = 100000000 / TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price;
						for (i = 0; i < 4; i++)
						{
							MD_Connect_TX_Buff[Port][18 + i] = (Tempu64 >> ((3 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][22] = 0;
					}
					else if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresteType == Preset_Sale)
					{
						Tempu64 = 0;
						for (i = 0; i < 3; i++)
						{
							MD_Connect_TX_Buff[Port][5 + i] = (Tempu64 >> ((2 - i) * 8)) & 0xff;
						}
						if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >= 0x90000000)
							Tempu64 = 0x900000;
						else
							Tempu64 = TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue;
						for (i = 0; i < 4; i++)
						{
							MD_Connect_TX_Buff[Port][8 + i] = (Tempu64 >> ((3 - i) * 8)) & 0xff;
						}
						for (i = 0; i < 3; i++)
						{
							MD_Connect_TX_Buff[Port][12 + i] = (Tempu64 >> ((2 - i) * 8)) & 0xff;
						}
						Tempu64 = TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price;
						for (i = 0; i < 3; i++)
						{
							MD_Connect_TX_Buff[Port][15 + i] = (Tempu64 >> ((2 - i) * 8)) & 0xff;
						}
						Tempu64 = 100000000 / TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price;
						for (i = 0; i < 4; i++)
						{
							MD_Connect_TX_Buff[Port][18 + i] = (Tempu64 >> ((3 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][22] = 1;
					}
					Tempu64 = TXHData.MD_Port_Data[Port].GunData[GunNum].OrderNumber + 1;
					for (i = 0; i < 2; i++)
					{
						MD_Connect_TX_Buff[Port][23 + i] = (Tempu64 >> ((1 - i) * 8)) & 0xff;
					}
					MD_Connect_TX_Buff[Port][25] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][3], 22); // 校验
					MD_ConnectTX_Len = 26;
				}
				break;
				case YG_MDConnectCmdStart: // 启动
				{
					MD_Connect_TX_Buff[Port][0] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][1] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][2] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][3] = MD_TX_CMD;
					MD_Connect_TX_Buff[Port][4] = GunAddr;										 // 枪号
					MD_Connect_TX_Buff[Port][5] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][3], 2); // 校验
					MD_ConnectTX_Len = 6;
				}
				break;
				case YG_MDConnectCmdStop: // 停机
				{
					MD_Connect_TX_Buff[Port][0] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][1] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][2] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][3] = MD_TX_CMD;
					MD_Connect_TX_Buff[Port][4] = GunAddr;										 // 枪号
					MD_Connect_TX_Buff[Port][5] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][3], 2); // 校验
					MD_ConnectTX_Len = 6;
				}
				break;
				case YG_MDConnectCmdWritePrice: // xie单价
				{
					MD_Connect_TX_Buff[Port][0] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][1] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][2] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][3] = MD_TX_CMD;
					MD_Connect_TX_Buff[Port][4] = GunAddr; // 枪号
					Tempu64 = TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price;
					for (i = 0; i < 3; i++)
					{
						MD_Connect_TX_Buff[Port][5 + i] = (Tempu64 >> ((2 - i) * 8)) & 0xff;
					}
					Tempu64 = 100000000 / MD_Connect_BCDTou64(TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price);
					Tempu64 = MD_Connect_u64ToBCD(Tempu64);
					for (i = 0; i < 4; i++)
					{
						MD_Connect_TX_Buff[Port][8 + i] = (Tempu64 >> ((3 - i) * 8)) & 0xff;
					}
					MD_Connect_TX_Buff[Port][12] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][3], 9); // 校验
					MD_ConnectTX_Len = 13;
				}
				break;
				case YG_MDConnectCmdReadTotal: // 读总累
				{
					MD_Connect_TX_Buff[Port][0] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][1] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][2] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][3] = MD_TX_CMD;
					MD_Connect_TX_Buff[Port][4] = GunAddr;										 // 枪号
					MD_Connect_TX_Buff[Port][5] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][3], 2); // 校验
					MD_ConnectTX_Len = 6;
				}
				break;
				case YG_MDConnectControlMode: // 要控制权
				{
					MD_Connect_TX_Buff[Port][0] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][1] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][2] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][3] = MD_TX_CMD;
					MD_Connect_TX_Buff[Port][4] = GunAddr;										 // 枪号
					MD_Connect_TX_Buff[Port][5] = 0x55;											 // 联机模式
					MD_Connect_TX_Buff[Port][6] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][3], 3); // 校验
					MD_ConnectTX_Len = 7;
				}
				break;
				case YG_MDConnectCmdLock: // 锁定
				{
					MD_Connect_TX_Buff[Port][0] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][1] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][2] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][3] = MD_TX_CMD;
					MD_Connect_TX_Buff[Port][4] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][5] = 0xAA;	   // 联机模式
					for (i = 0; i < 3; i++)
					{
						MD_Connect_TX_Buff[Port][6 + i] = 0x00;
					}
					MD_Connect_TX_Buff[Port][9] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][3], 6); // 校验
					MD_ConnectTX_Len = 10;
				}
				break;
				case YG_MDConnectCmdUnLock: // 解锁
				{
					MD_Connect_TX_Buff[Port][0] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][1] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][2] = 0xFA; // 帧头
					MD_Connect_TX_Buff[Port][3] = MD_TX_CMD;
					MD_Connect_TX_Buff[Port][4] = GunAddr;										 // 枪号
					MD_Connect_TX_Buff[Port][5] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][3], 2); // 校验
					MD_ConnectTX_Len = 6;
				}
				break;
				}
			}
			break;
			case PosHongYang:
			{
				GunAddr = TXHData.MD_Port_Data[Port].GunData[GunNum].GunAddr;
				if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake == TXHData.MD_Port_Info[Port].Handshake_Top)
					TXHData.MD_Port_Info[Port].LoopGunNextFlag = 1;
				TXHData.MBCountCutNum[Port][GunNum]++;
				switch (Port)
				{
				case 0:
					MD_Connect_TX1_DMAAddrSet((uint32_t)&HY_SendBuff);
					break;
				case 1:
					MD_Connect_TX2_DMAAddrSet((uint32_t)&HY_SendBuff);
					break;
				case 2:
					MD_Connect_TX3_DMAAddrSet((uint32_t)&HY_SendBuff);
					break;
				case 3:
					MD_Connect_TX4_DMAAddrSet((uint32_t)&HY_SendBuff);
					break;
				}
				switch (MD_TX_CMD)
				{
				case HY_MDConnectCmdReadFuelData: // 读数据
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][1] = 0x03;
					MD_Connect_TX_Buff[Port][2] = HY_MDConnectCmdReadFuelData;
					MD_Connect_TX_Buff[Port][3] = InteiHEXCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 4;

					if (GunAddr <= 64)
						HY_SendBuff[0] = GunAddr | 0x100;
					else
						HY_SendBuff[0] = GunAddr;
					for (i = 1; i < MD_ConnectTX_Len; i++)
						HY_SendBuff[i] = MD_Connect_TX_Buff[Port][i];
				}
				break;
				case HY_MDConnectCmdWritePrsetSale: // 预置金额
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = HY_MDConnectCmdWritePrsetSale;
					if (TXHData.MD_Port_Data[Port].PortData.Device_Type == Display_664)
					{
						if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >= 0x900000)
							Tempu64 = 0x900000;
						else
							Tempu64 = MD_Connect_BCDTou64(TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue);
						MD_Connect_TX_Buff[Port][1] = 0x06;
						for (i = 0; i < 3; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = (Tempu64 >> ((2 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][6] = CheckSum8(&MD_Connect_TX_Buff[Port][0], 6); // 校验
						MD_ConnectTX_Len = 7;
					}
					else
					{
						if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >= 0x90000000)
							Tempu64 = 0x90000000;
						else
							Tempu64 = MD_Connect_BCDTou64(TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue);
						MD_Connect_TX_Buff[Port][1] = 0x07;
						for (i = 0; i < 4; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = (Tempu64 >> ((3 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][7] = InteiHEXCheck(&MD_Connect_TX_Buff[Port][0], 7); // 校验
						MD_ConnectTX_Len = 8;
					}
					if (GunAddr <= 64)
						HY_SendBuff[0] = GunAddr | 0x100;
					else
						HY_SendBuff[0] = GunAddr;
					for (i = 1; i < MD_ConnectTX_Len; i++)
						HY_SendBuff[i] = MD_Connect_TX_Buff[Port][i];
				}
				break;
				case HY_MDConnectCmdWritePrsetVolume: // 预置油量
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = HY_MDConnectCmdWritePrsetVolume;
					if (TXHData.MD_Port_Data[Port].PortData.Device_Type == Display_664)
					{
						if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue == 0x900000)
							Tempu64 = 0x900000;
						else
							Tempu64 = MD_Connect_BCDTou64(TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue);
						MD_Connect_TX_Buff[Port][1] = 0x06;
						for (i = 0; i < 3; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = (Tempu64 >> ((2 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][6] = CheckSum8(&MD_Connect_TX_Buff[Port][0], 6); // 校验
						MD_ConnectTX_Len = 7;
					}
					else
					{
						if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue == 0x90000000)
							Tempu64 = 0x90000000;
						else
							Tempu64 = MD_Connect_BCDTou64(TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue);
						MD_Connect_TX_Buff[Port][1] = 0x07;
						for (i = 0; i < 4; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = (Tempu64 >> ((3 - i) * 8)) & 0xff;
						}

						MD_Connect_TX_Buff[Port][7] = InteiHEXCheck(&MD_Connect_TX_Buff[Port][0], 7); // 校验
						MD_ConnectTX_Len = 8;
					}
					if (GunAddr <= 64)
						HY_SendBuff[0] = GunAddr | 0x100;
					else
						HY_SendBuff[0] = GunAddr;
					for (i = 1; i < MD_ConnectTX_Len; i++)
						HY_SendBuff[i] = MD_Connect_TX_Buff[Port][i];
				}
				break;
				case HY_MDConnectCmdStart: // 启动
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][1] = 0x03;
					MD_Connect_TX_Buff[Port][2] = HY_MDConnectCmdStart;
					MD_Connect_TX_Buff[Port][3] = InteiHEXCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 4;
					if (GunAddr <= 64)
						HY_SendBuff[0] = GunAddr | 0x100;
					else
						HY_SendBuff[0] = GunAddr;
					for (i = 1; i < MD_ConnectTX_Len; i++)
						HY_SendBuff[i] = MD_Connect_TX_Buff[Port][i];
					TXHData.MD_Port_Data[Port].GunData[GunNum].GunState.Flag.AuthorizeState = 1;
					FMItemWrite(CF_MD_Port_Data, Port);
				}
				break;
				case HY_MDConnectCmdStop: // 停机
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][1] = 0x03;
					MD_Connect_TX_Buff[Port][2] = HY_MDConnectCmdStop;
					MD_Connect_TX_Buff[Port][3] = InteiHEXCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 4;
					if (GunAddr <= 64)
						HY_SendBuff[0] = GunAddr | 0x100;
					else
						HY_SendBuff[0] = GunAddr;
					for (i = 1; i < MD_ConnectTX_Len; i++)
						HY_SendBuff[i] = MD_Connect_TX_Buff[Port][i];
				}
				break;
				case HY_MDConnectCmdReadPrice: // 读单价
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][1] = 0x03;
					MD_Connect_TX_Buff[Port][2] = HY_MDConnectCmdReadPrice;
					MD_Connect_TX_Buff[Port][3] = InteiHEXCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 4;
					if (GunAddr <= 64)
						HY_SendBuff[0] = GunAddr | 0x100;
					else
						HY_SendBuff[0] = GunAddr;
					for (i = 1; i < MD_ConnectTX_Len; i++)
						HY_SendBuff[i] = MD_Connect_TX_Buff[Port][i];
				}
				break;
				case HY_MDConnectCmdWritePrice: // xie单价
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = HY_MDConnectCmdWritePrice;
					MD_Connect_TX_Buff[Port][1] = 0x07;
					Tempu64 = MD_Connect_BCDTou64(TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price);
					for (i = 0; i < 4; i++)
					{
						MD_Connect_TX_Buff[Port][3 + i] = ((Tempu64) >> ((3 - i) * 8)) & 0xff;
					}
					MD_Connect_TX_Buff[Port][7] = InteiHEXCheck(&MD_Connect_TX_Buff[Port][0], 7); // 校验
					MD_ConnectTX_Len = 8;
					if (GunAddr <= 64)
						HY_SendBuff[0] = GunAddr | 0x100;
					else
						HY_SendBuff[0] = GunAddr;
					for (i = 1; i < MD_ConnectTX_Len; i++)
						HY_SendBuff[i] = MD_Connect_TX_Buff[Port][i];
				}
				break;
				case HY_MDConnectCmdReadTotal: // 读总累
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][1] = 0x03;
					MD_Connect_TX_Buff[Port][2] = HY_MDConnectCmdReadTotal;
					MD_Connect_TX_Buff[Port][3] = InteiHEXCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 4;
					if (GunAddr <= 64)
						HY_SendBuff[0] = GunAddr | 0x100;
					else
						HY_SendBuff[0] = GunAddr;
					for (i = 1; i < MD_ConnectTX_Len; i++)
						HY_SendBuff[i] = MD_Connect_TX_Buff[Port][i];
				}
				break;
				case HY_MDConnectASKControlPower: // 要控制权
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][1] = 0x03;
					MD_Connect_TX_Buff[Port][2] = HY_MDConnectASKControlPower;
					MD_Connect_TX_Buff[Port][3] = InteiHEXCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 4;
					if (GunAddr <= 64)
						HY_SendBuff[0] = GunAddr | 0x100;
					else
						HY_SendBuff[0] = GunAddr;
					for (i = 1; i < MD_ConnectTX_Len; i++)
						HY_SendBuff[i] = MD_Connect_TX_Buff[Port][i];
				}
				break;
				case HY_MDConnectReturnControlPower: // 还控制权
				{
					MD_Connect_TX_Buff[Port][0] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][1] = 0x03;
					MD_Connect_TX_Buff[Port][2] = HY_MDConnectReturnControlPower;
					MD_Connect_TX_Buff[Port][3] = InteiHEXCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 4;
					if (GunAddr <= 64)
						HY_SendBuff[0] = GunAddr | 0x100;
					else
						HY_SendBuff[0] = GunAddr;
					for (i = 1; i < MD_ConnectTX_Len; i++)
						HY_SendBuff[i] = MD_Connect_TX_Buff[Port][i];
				}
				break;
				}
			}
			break;
			case PosLanFeng:
			{
				GunAddr = MD_Connect_u64ToBCD(TXHData.MD_Port_Data[Port].GunData[GunNum].GunAddr);
				if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake == TXHData.MD_Port_Info[Port].Handshake_Top)
					TXHData.MD_Port_Info[Port].LoopGunNextFlag = 1;
				TXHData.MBCountCutNum[Port][GunNum]++;
				if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].ROM_UpData_State.Flag.BaudRateSync_Flag == 1)
				{
					MD_Connect_USART_Configuration(Port, BaudRateSync, USART_WordLength_9b, TXHData.MD_Port_Data[Port].PortData.Parity_Even);
				}
				else
				{
					MD_Connect_USART_Configuration(Port, TXHData.MD_Port_Data[Port].PortData.BaudRate, USART_WordLength_9b, TXHData.MD_Port_Data[Port].PortData.Parity_Even);
				}
				switch (MD_TX_CMD)
				{
				case LF_MDConnectCmdReadState: // 读状态
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = LF_MDConnectCmdReadState;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				case LF_MDConnectCmdWritePrset: // 预置金额
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					if (TXHData.MD_Port_Data[Port].PortData.Device_Type == Display_664)
					{
						if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >= 0x900000)
							Tempu64 = 0x900000;
						else
							Tempu64 = TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue;
						MD_Connect_TX_Buff[Port][2] = 0xA5;
						for (i = 0; i < 3; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = (Tempu64 >> ((2 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][6] = C_MDConnectCmdWritePrsetSale;
						MD_Connect_TX_Buff[Port][7] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 6); // 校验
						MD_ConnectTX_Len = 8;
					}
					else
					{
						if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >= 0x90000000)
							Tempu64 = 0x90000000;
						else
							Tempu64 = TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue;
						MD_Connect_TX_Buff[Port][2] = 0xA6;
						for (i = 0; i < 4; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = (Tempu64 >> ((3 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][7] = LF_MDConnectCmdWritePrset;
						MD_Connect_TX_Buff[Port][8] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 7); // 校验
						MD_ConnectTX_Len = 9;
					}
				}
				break;
				case LF_MDConnectCmdStop: // 停机
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = LF_MDConnectCmdStop;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				case LF_MDConnectCmdWritePrice: // xie单价
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					if (TXHData.MD_Port_Data[Port].PortData.Device_Type == Display_664)
					{
						MD_Connect_TX_Buff[Port][2] = 0xA4;
						for (i = 0; i < 2; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price) >> ((1 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][5] = C_MDConnectCmdWritePrice;
						MD_Connect_TX_Buff[Port][6] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 5); // 校验
						MD_ConnectTX_Len = 7;
					}
					else
					{
						MD_Connect_TX_Buff[Port][2] = 0xA5;
						for (i = 0; i < 3; i++)
						{
							MD_Connect_TX_Buff[Port][3 + i] = ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].Price) >> ((2 - i) * 8)) & 0xff;
						}
						MD_Connect_TX_Buff[Port][6] = LF_MDConnectCmdWritePrice;
						MD_Connect_TX_Buff[Port][7] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 6); // 校验
						MD_ConnectTX_Len = 8;
					}
				}
				break;
				case LF_MDConnectCmdReadTotal: // 读总累
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = LF_MDConnectCmdReadTotal;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				case LF_MDConnectASKControlPower: // 要控制权
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = LF_MDConnectASKControlPower;
					// MD_Connect_TX_Buff[Port][3] = C_MDConnectReturnControlPower;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				case LF_MDConnectReturnControlPower: // 还控制权
				{
					MD_Connect_TX_Buff[Port][0] = 0xf5;	   // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0xA2;
					MD_Connect_TX_Buff[Port][3] = LF_MDConnectReturnControlPower;
					MD_Connect_TX_Buff[Port][4] = MD_Connect_TXDataCheck(&MD_Connect_TX_Buff[Port][0], 3); // 校验
					MD_ConnectTX_Len = 5;
				}
				break;
				}
			}
			break;
			case PosSSLan: //
			{
				FatherNum = GunNum;																												  // 这离GunNum表示泵号
				GunNum = TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].SonStart + TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].SonNow; //
				GunAddr = TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].Address;															  // 泵地址
				if (TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].Handshake == TXHData.MD_Port_Info[Port].Handshake_Top)
					TXHData.MD_Port_Info[Port].LoopGunNextFlag = 1;
				TXHData.MBCountCutNum[Port][FatherNum]++;
				if (GunAddr > 0)
					GunAddr -= 1;
				switch (MD_TX_CMD)
				{
				case LY_MDConnectCmdHandshake: // 握手
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x30;
					MD_Connect_TX_Buff[Port][4] = 0x30;
					MD_Connect_TX_Buff[Port][5] = (TXHData.MD_Port_Info[Port].GunInfo[GunNum].LYHandshakeCRC >> 4) & 0x0f;
					if (MD_Connect_TX_Buff[Port][5] < 0x0A)
						MD_Connect_TX_Buff[Port][5] += 0x30;
					else
						MD_Connect_TX_Buff[Port][5] = MD_Connect_TX_Buff[Port][5] - 0x0A + 0x41;
					MD_Connect_TX_Buff[Port][6] = TXHData.MD_Port_Info[Port].GunInfo[GunNum].LYHandshakeCRC & 0x0f;
					if (MD_Connect_TX_Buff[Port][6] < 0x0A)
						MD_Connect_TX_Buff[Port][6] += 0x30;
					else
						MD_Connect_TX_Buff[Port][6] = MD_Connect_TX_Buff[Port][6] - 0x0A + 0x41;
					MD_Connect_TX_Buff[Port][7] = 0x03;
					MD_Connect_TX_Buff[Port][8] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 7); // 校验
					MD_ConnectTX_Len = 9;
					//							if(TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake == 0x06)
					//							{
					//								TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake = 0x07;
					//								}
					TXHData.MD_Port_Info[Port].LoopGunNextFlag = 0;
					TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake = 0x08;
				}
				break;
				case LY_MDConnectCmdPoll: // 轮询
				{
					MD_Connect_TX_Buff[Port][0] = 0x04;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x51;
					MD_Connect_TX_Buff[Port][3] = 0x05;
					MD_ConnectTX_Len = 4;
				}
				break;
				case LY_MDConnectCmdReadState: // 读状态
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x31;
					MD_Connect_TX_Buff[Port][4] = 0x35;
					MD_Connect_TX_Buff[Port][5] = 0x03;
					MD_Connect_TX_Buff[Port][6] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 5); // 校验
					MD_ConnectTX_Len = 7;
				}
				break;
				case LY_MDConnectCmdReadTotal: // 读状态
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x32;
					MD_Connect_TX_Buff[Port][4] = 0x30;
					MD_Connect_TX_Buff[Port][5] = 0x03;
					MD_Connect_TX_Buff[Port][6] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 5); // 校验
					MD_ConnectTX_Len = 7;
				}
				break;
				case LY_MDConnectCmdChoiceGun: // 选择枪
				{
					MD_Connect_TX_Buff[Port][0] = 0x04;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x05;
					MD_ConnectTX_Len = 4;
					//							if(TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake == 0x02)
					//							{
					//								TXHData.MD_Port_Info[Port].GunInfo[GunNum].Handshake = 0x03;
					//								}
				}
				break;
				case LY_MDConnectCmdDisauthorize: // 取消授权
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x31;
					MD_Connect_TX_Buff[Port][4] = 0x32;
					MD_Connect_TX_Buff[Port][5] = 0x03;
					MD_Connect_TX_Buff[Port][6] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 5); // 校验
					MD_ConnectTX_Len = 7;
					TXHData.MD_Port_Data[Port].GunData[GunNum].GunState.Flag.AuthorizeState = 0;
				}
				break;
				case LY_MDConnectCmdAuthorize: // 授权
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x31;
					MD_Connect_TX_Buff[Port][4] = 0x31;
					if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >= 0x900000)
						MD_Connect_TX_Buff[Port][5] = 0x30;
					else
					{
						MD_Connect_TX_Buff[Port][5] = 0x32;
					}
					if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresteType == Preset_Volume)
						MD_Connect_TX_Buff[Port][6] = 0x31;
					else if (TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresteType == Preset_Sale)
						MD_Connect_TX_Buff[Port][6] = 0x32;
					for (i = 0; i < 6; i++)
						MD_Connect_TX_Buff[Port][7 + i] = 0x30 + ((TXHData.MD_Port_Info[Port].GunInfo[GunNum].PresetValue >> (5 - i) * 4) & 0x0f);
					for (i = 0; i < 30; i++)
						MD_Connect_TX_Buff[Port][13 + i] = 0x30;
					for (j = 0; j < 6; j++)
					{
						if ((TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].SonNow == j) && TXHData.MD_Port_Info[Port].GunInfo[TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].SonStart + j].Price != 0)
							MD_Connect_TX_Buff[Port][13 + j * 5] = 0x32;
						else
							MD_Connect_TX_Buff[Port][13 + j * 5] = 0x30;
						for (i = 0; i < 4; i++)
							MD_Connect_TX_Buff[Port][14 + i + j * 5] = 0x30 + ((TXHData.MD_Port_Info[Port].GunInfo[TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].SonStart + j].Price >> (3 - i) * 4) & 0x0f);
					}
					MD_Connect_TX_Buff[Port][13 + 30] = 0x03;
					MD_Connect_TX_Buff[Port][14 + 30] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 13 + 30); // 校验
					MD_ConnectTX_Len = 15 + 30;
				}
				break;
				case LY_MDConnectCmdWritePrice: // 写单价
				{
					MD_Connect_TX_Buff[Port][0] = 0x02;			  // 帧头
					MD_Connect_TX_Buff[Port][1] = GunAddr + 0x40; // 枪号
					MD_Connect_TX_Buff[Port][2] = 0x41;
					MD_Connect_TX_Buff[Port][3] = 0x32;
					MD_Connect_TX_Buff[Port][4] = 0x31;
					MD_Connect_TX_Buff[Port][5] = 0x32;
					for (i = 0; i < 30; i++)
						MD_Connect_TX_Buff[Port][6 + i] = 0x30;
					for (j = 0; j < 6; j++)
					{
						if ((TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].SonNow == j) && TXHData.MD_Port_Info[Port].GunInfo[TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].SonStart + j].Price != 0)
							MD_Connect_TX_Buff[Port][6 + j * 5] = 0x32;
						else
							MD_Connect_TX_Buff[Port][6 + j * 5] = 0x30;
						for (i = 0; i < 4; i++)
							MD_Connect_TX_Buff[Port][7 + i + j * 5] = 0x30 + ((TXHData.MD_Port_Info[Port].GunInfo[TXHData.MD_Port_Info[Port].FatherDevice[FatherNum].SonStart + j].Price >> (3 - i) * 4) & 0x0f);
					}
					MD_Connect_TX_Buff[Port][36] = 0x03;
					MD_Connect_TX_Buff[Port][37] = BCC_CheckSum(&MD_Connect_TX_Buff[Port][1], 36); // 校验
					MD_ConnectTX_Len = 38;
				}
				break;
				case LY_MDConnectCmdACK0: // 1030
				{
					MD_Connect_TX_Buff[Port][0] = 0x10;
					MD_Connect_TX_Buff[Port][1] = 0x30;
					MD_ConnectTX_Len = 2;
				}
				break;
				case LY_MDConnectCmdACK1: // 1031
				{
					MD_Connect_TX_Buff[Port][0] = 0x10;
					MD_Connect_TX_Buff[Port][1] = 0x31;
					MD_ConnectTX_Len = 2;
				}
				break;
				}
			}
			break;

			case PosPLC:
			{
				TXHData.MD_Port_Info[Port].LoopGunNextFlag = 1;
				TXHData.MBCountCutNum[Port][GunNum]++;
				switch (MD_TX_CMD)
				{
				case PLC_MDConnectCmdReadData: // 轮询
				{
					MD_Connect_TX_Buff[Port][0] = 0x03;
					MD_Connect_TX_Buff[Port][1] = 0x03;
					MD_Connect_TX_Buff[Port][2] = 0x00;
					MD_Connect_TX_Buff[Port][3] = 0x00;
					MD_Connect_TX_Buff[Port][4] = 0x00;
					MD_Connect_TX_Buff[Port][5] = 26;
					Tempu64 = CRC_Check(&MD_Connect_TX_Buff[Port][0], 6);
					MD_Connect_TX_Buff[Port][7] = Tempu64 >> 8;
					MD_Connect_TX_Buff[Port][6] = Tempu64;
					MD_ConnectTX_Len = 8;
					// TXHData.MD_Port_Info[Port].GunInfo[0].MB_CMD_Next = PLC_MDConnectCmdReadErro;
				}
				break;
				case PLC_MDConnectCmdReadErro: // 读状态
				{
					MD_Connect_TX_Buff[Port][0] = 0x03;
					MD_Connect_TX_Buff[Port][1] = 0x03;
					MD_Connect_TX_Buff[Port][2] = 0x00;
					MD_Connect_TX_Buff[Port][3] = 30;
					MD_Connect_TX_Buff[Port][4] = 0;
					MD_Connect_TX_Buff[Port][5] = 3;
					Tempu64 = CRC_Check(&MD_Connect_TX_Buff[Port][0], 6);
					MD_Connect_TX_Buff[Port][7] = Tempu64 >> 8;
					MD_Connect_TX_Buff[Port][6] = Tempu64;
					MD_ConnectTX_Len = 8;
					// TXHData.MD_Port_Info[Port].GunInfo[0].MB_CMD_Next = PLC_MDConnectCmdReadData;
				}
				break;
				}
			}
			break;
			case PosPrice1_4:
			{
				TXHData.MD_Port_Info[Port].LoopGunNextFlag = 1;
				TXHData.MBCountCutNum[Port][GunNum]++;
				switch (MD_TX_CMD)
				{
				case Price_MDConnectCmdWriteParameter: // 写参数
				{
					MD_Connect_TX_Buff[Port][0] = 0xFE;
					MD_Connect_TX_Buff[Port][1] = 0xFF;
					MD_Connect_TX_Buff[Port][2] = 0x04;
					MD_Connect_TX_Buff[Port][3] = 0x01;
					MD_Connect_TX_Buff[Port][4] = 0x03;
					Tempu64 = Price_DataCheck(&MD_Connect_TX_Buff[Port][2], MD_Connect_TX_Buff[Port][2] - 1);
					MD_Connect_TX_Buff[Port][5] = Tempu64;
					MD_Connect_TX_Buff[Port][6] = 0xEF;
					MD_ConnectTX_Len = 7;
				}
				break;
				case Price_MDConnectCmdReadParameter: // 读参数
				{
					MD_Connect_TX_Buff[Port][0] = 0xFE;
					MD_Connect_TX_Buff[Port][1] = 0xFF;
					MD_Connect_TX_Buff[Port][2] = 0x04;
					MD_Connect_TX_Buff[Port][3] = 0x01;
					MD_Connect_TX_Buff[Port][4] = 0x02;
					Tempu64 = Price_DataCheck(&MD_Connect_TX_Buff[Port][2], MD_Connect_TX_Buff[Port][2] - 1);
					MD_Connect_TX_Buff[Port][5] = Tempu64;
					MD_Connect_TX_Buff[Port][6] = 0xEF;
					MD_ConnectTX_Len = 7;
				}
				break;
				case Price_MDConnectCmdWriteDecimal: // 写小数位MD_Port_Info_Type
				{
					MD_Connect_TX_Buff[Port][0] = 0xFE;
					MD_Connect_TX_Buff[Port][1] = 0xFF;
					MD_Connect_TX_Buff[Port][2] = 16;
					MD_Connect_TX_Buff[Port][3] = 0x01;
					MD_Connect_TX_Buff[Port][4] = 0x04;
					for (j = 0; j < TXHData.MD_Port_Info[Port].PriceTagData.PriceNumber; j++)
					{
						MD_Connect_TX_Buff[Port][5 + j] = TXHData.MD_Port_Info[Port].PriceTagData.Length - TXHData.MD_Port_Info[Port].PriceTagData.Decimal[j];
					}
					for (j = TXHData.MD_Port_Info[Port].PriceTagData.PriceNumber; j < 17; j++)
						MD_Connect_TX_Buff[Port][5 + j] = 0;
					Tempu64 = Price_DataCheck(&MD_Connect_TX_Buff[Port][2], MD_Connect_TX_Buff[Port][2] - 1);
					MD_Connect_TX_Buff[Port][17] = Tempu64;
					MD_Connect_TX_Buff[Port][18] = 0xEF;
					MD_ConnectTX_Len = 19;
				}
				break;
				case Price_MDConnectCmdWritePrice: // 写单价
				{
					MD_Connect_TX_Buff[Port][0] = 0xFE;
					MD_Connect_TX_Buff[Port][1] = 0xFF;
					MD_Connect_TX_Buff[Port][2] = 40;
					MD_Connect_TX_Buff[Port][3] = 0x01;
					MD_Connect_TX_Buff[Port][4] = 0x01;
					for (i = 5; i < 40; i++)
						MD_Connect_TX_Buff[Port][i] = 0;
					for (i = 0; i < TXHData.MD_Port_Info[Port].PriceTagData.PriceNumber; i++)
					{
						for (j = 0; j < 3; j++)
						{
							if (TXHData.MD_Port_Info[Port].PriceTagData.Length / 2 > j)
								MD_Connect_TX_Buff[Port][5 + j + (i * 3)] = TXHData.MD_Port_Info[Port].PriceTagData.Price[i] >> ((TXHData.MD_Port_Info[Port].PriceTagData.Length / 2 - 1 - j) * 8);
							else
								MD_Connect_TX_Buff[Port][5 + j + (i * 3)] = 0;
						}
					}
					Tempu64 = Price_DataCheck(&MD_Connect_TX_Buff[Port][2], MD_Connect_TX_Buff[Port][2] - 1);
					MD_Connect_TX_Buff[Port][41] = Tempu64;
					MD_Connect_TX_Buff[Port][42] = 0xEF;
					MD_ConnectTX_Len = 43;
				}
				break;
				case Price_MDConnectCmdReadPrice: // 读单价
				{
					MD_Connect_TX_Buff[Port][0] = 0xFE;
					MD_Connect_TX_Buff[Port][1] = 0xFF;
					MD_Connect_TX_Buff[Port][2] = 0x04;
					MD_Connect_TX_Buff[Port][3] = 0x01;
					MD_Connect_TX_Buff[Port][4] = 0x03;
					Tempu64 = Price_DataCheck(&MD_Connect_TX_Buff[Port][2], MD_Connect_TX_Buff[Port][2] - 1);
					MD_Connect_TX_Buff[Port][5] = Tempu64;
					MD_Connect_TX_Buff[Port][6] = 0xEF;
					MD_ConnectTX_Len = 7;
				}
				break;
				}
			}
			break;
			}
			switch (Port)
			{
			case 0:
			{
				if (MD_ConnectTX_Len)
				{
					MD_Connect_RS485_Tx1EN;
					MD_Connect_TX1_DMALenSet(MD_ConnectTX_Len);
					MD_Connect_TX1_DMAStart();
				}
			}
			break;
			case 1:
			{
				if (MD_ConnectTX_Len)
				{
					MD_Connect_RS485_Tx2EN;
					MD_Connect_TX2_DMALenSet(MD_ConnectTX_Len);
					MD_Connect_TX2_DMAStart();
				}
			}
			break;
			case 2:
			{
				if (MD_ConnectTX_Len)
				{
					MD_Connect_RS485_Tx3EN;
					MD_Connect_TX3_DMALenSet(MD_ConnectTX_Len);
					MD_Connect_TX3_DMAStart();
				}
			}
			break;
			case 3:
			{
				if (MD_ConnectTX_Len)
				{
					MD_Connect_RS485_Tx4EN;
					MD_Connect_TX4_DMALenSet(MD_ConnectTX_Len);
					MD_Connect_TX4_DMAStart();
				}
			}
			break;
			}
			if (TXHData.UDisk_Flag)
				Log_Task(&MD_Connect_TX_Buff[Port][0], MD_ConnectTX_Len, Port, Info_Issue);
		}
		else
		{
			TXHData.MBCountCutNum[Port][GunNum]++;
		}
	}
	else if (TXHData.MDConnectState[Port].Flag.WorkMode == 0) // 指令模式
	{
		switch (TXHData.MDConnectState[Port].Flag.SetModeCMDNext)
		{
		case WIFI_ATRec:
		{
			TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
			for (i = 0; i < strlen(MD_ATRec); i++)
				MD_Connect_TX_Buff[Port][i] = MD_ATRec[i];
			MD_ConnectTX_Len = (i); // 设置发送DMA长度
			TXHData.MBCountTimer[Port].TimerCountMax = 1000;
		}
		break;
		case WIFI_WMODE:
		{
			TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
			for (i = 0; i < strlen(MD_WMODE); i++)
				MD_Connect_TX_Buff[Port][i] = MD_WMODE[i];
			MD_ConnectTX_Len = (i); // 设置发送DMA长度
		}
		break;
		case WIFI_WifiRST:
		{
			for (i = 0; i < strlen(MD_WifiRST); i++)
				MD_Connect_TX_Buff[Port][i] = MD_WifiRST[i];
			MD_ConnectTX_Len = (i); // 设置发送DMA长度

			TXHData.MBCountTimer[Port].TimerCountMax = 1000 * 10;
		}
		break;
		case WIFI_WifiWSSSID:
		{
			TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
			for (i = 0; i < strlen(MD_WifiWSSSID); i++)
				MD_Connect_TX_Buff[Port][i] = MD_WifiWSSSID[i];
			MD_Connect_TX_Buff[Port][11] = 0x31 + Port;
			MD_Connect_TX_Buff[Port][22] = 0x31 + Port * 3;
			if (Port == 3)
			{
				MD_Connect_TX_Buff[Port][22] = 0x31;
				MD_Connect_TX_Buff[Port][23] = 0x30;
				MD_Connect_TX_Buff[Port][24] = 0x0D;
				MD_Connect_TX_Buff[Port][25] = 0x0A;
				i++;
			}
			MD_ConnectTX_Len = (i); // 设置发送DMA长度

			TXHData.MBCountTimer[Port].TimerCountMax = 1000 * 10;
		}
		break;
		case WIFI_WifiRSSI:
		{
			for (i = 0; i < strlen(MD_WifiRSSI); i++)
				MD_Connect_TX_Buff[Port][i] = MD_WifiRSSI[i];
			MD_ConnectTX_Len = (i); // 设置发送DMA长度

			TXHData.MDConnectState[Port].Flag.SetModeCMDNext = WIFI_WifiSOCKET;
			TXHData.MBCountTimer[Port].TimerCountMax = 1000 * 2;
		}
		break;
		case WIFI_WifiSOCKET:
		{
			{
				for (i = 0; i < strlen(MD_WifiSOCKET); i++)
					MD_Connect_TX_Buff[Port][i] = MD_WifiSOCKET[i];
				MD_ConnectTX_Len = (i); // 设置发送DMA长度
			}
			TXHData.MBCountTimer[Port].TimerCountMax = 1000 * 10;
		}
		break;
		}
		switch (Port)
		{
		case 0:
		{
			if (MD_ConnectTX_Len)
			{
				MD_Connect_RS485_Tx1EN;
				MD_Connect_TX1_DMALenSet(MD_ConnectTX_Len);
				MD_Connect_TX1_DMAStart();
			}
		}
		break;
		case 1:
		{
			if (MD_ConnectTX_Len)
			{
				MD_Connect_RS485_Tx2EN;
				MD_Connect_TX2_DMALenSet(MD_ConnectTX_Len);
				MD_Connect_TX2_DMAStart();
			}
		}
		break;
		case 2:
		{
			if (MD_ConnectTX_Len)
			{
				MD_Connect_RS485_Tx3EN;
				MD_Connect_TX3_DMALenSet(MD_ConnectTX_Len);
				MD_Connect_TX3_DMAStart();
			}
		}
		break;
		case 3:
		{
			if (MD_ConnectTX_Len)
			{
				MD_Connect_RS485_Tx4EN;
				MD_Connect_TX4_DMALenSet(MD_ConnectTX_Len);
				MD_Connect_TX4_DMAStart();
			}
		}
		break;
		}
	}
}
/*F*****************************************************************************
 * NAME:    KeyBoardTask
 * PURMDE: KeyBoard键盘通讯处理任务
 * PARAMS: 无
 * return:	无
 *******************************************************************************/
volatile u8 KBAddr_Init[4] = {0, 0, 0, 0};
volatile u32 MD_RX_RNGData[4] = {0, 0, 0, 0};
void MD_ConnectRXTask(void)
{
	volatile u16 i = 0, j = 0, Port = 0, Temp = 0, DeviceNumber = 0, DeviceType = 0, DeviceDataLen = 0, DeviceNoDataLen = 0, DevicePortLen = 0;
	volatile u64 TempBCD = 0, Tempu64 = 0;
	volatile u8 MD_ConnectRX_Port = 0, POSType = 0, RXBuild_Port = 0, WhiteList_Num = 0;
	volatile u16 MD_ConnectRX_Len = 0;							 // 长度
	volatile u8 MD_ConnectRX_pGun = 0;							 // 地址枪号
	volatile u8 MD_ConnectRX_pGun_Father = 0;					 // 多枪协议父设备号
	volatile u8 MD_ConnectRX_pGun_SonDeviceBusy = 0;			 // 多强协议中用来标识有子设备在提枪或者加油中
	volatile u16 MD_ConnectRX_CMD = 0, MD_ConnectRX_CMDType = 0; // 命令
	volatile GunState_TypeDef GunState;
	u8 MD_ConnectRX_Check = 0; // 校验变量
	u8 Buff[50];
	u8 Temp8 = 0;
	u8 Encrypt_Flag1 = 0;
	u8 Encrypt_Flag2 = 0;
	u32 Temp32 = 0;
	u16 Temp16 = 0;
	volatile u16 Offset = 0;
	volatile u32 CRC_temp = 0;
	volatile float TempF = 0;
	volatile u8 Tank_Num;
	u8 Data_201[7] = "i20100";
	u8 Data_20E[7] = "i20E00";

	while (TXHData.MBCountRXIDLETimer[0].Flag + TXHData.MBCountRXIDLETimer[1].Flag + TXHData.MBCountRXIDLETimer[2].Flag + TXHData.MBCountRXIDLETimer[3].Flag)
	{
		if (TXHData.MBCountRXIDLETimer[0].Flag)
		{
			TXHData.MBCountRXIDLETimer[0].Flag = 0;
			if (TXHData.MD_Rec_NummberB[0] == 1000 - DMA1_Stream5->NDTR)
			{
				TXHData.MD_Rec_Nummber[0] = 1000 - DMA1_Stream5->NDTR;
				MD_Connect_RX1_DMAStop(); // 关闭DMA接收
				DMA_ClearFlag(DMA1_Stream5, DMA_IT_TCIF5);
				MD_ConnectRX1Task_Flag = 1;		// 使能Gas接收任务
				MD_Connect_RX1_DMALenSet(1000); // 重置接受长度
				MD_Connect_RX1_DMAStart();		// 打开DMA接收
			}
		}
		if (TXHData.MBCountRXIDLETimer[1].Flag)
		{
			TXHData.MBCountRXIDLETimer[1].Flag = 0;
			if (TXHData.MD_Rec_NummberB[1] == 1000 - DMA1_Stream2->NDTR)
			{
				TXHData.MD_Rec_Nummber[1] = 1000 - DMA1_Stream2->NDTR;
				MD_Connect_RX2_DMAStop(); // 关闭DMA接收
				DMA_ClearFlag(DMA1_Stream2, DMA_IT_TCIF2);
				MD_ConnectRX2Task_Flag = 1;		// 使能Gas接收任务
				MD_Connect_RX2_DMALenSet(1000); // 重置接受长度
				MD_Connect_RX2_DMAStart();		// 打开DMA接收
			}
		}
		if (TXHData.MBCountRXIDLETimer[2].Flag)
		{
			TXHData.MBCountRXIDLETimer[2].Flag = 0;
			if (TXHData.MD_Rec_NummberB[2] == 1000 - DMA1_Stream0->NDTR)
			{
				TXHData.MD_Rec_Nummber[2] = 1000 - DMA1_Stream0->NDTR;
				MD_Connect_RX3_DMAStop(); // 关闭DMA接收
				DMA_ClearFlag(DMA1_Stream0, DMA_IT_TCIF0);
				MD_ConnectRX3Task_Flag = 1;		// 使能Gas接收任务
				MD_Connect_RX3_DMALenSet(1000); // 重置接受长度
				MD_Connect_RX3_DMAStart();		// 打开DMA接收
			}
		}
		if (TXHData.MBCountRXIDLETimer[3].Flag)
		{
			TXHData.MBCountRXIDLETimer[3].Flag = 0;
			if (TXHData.MD_Rec_NummberB[3] == 1000 - DMA1_Stream1->NDTR)
			{
				TXHData.MD_Rec_Nummber[3] = 1000 - DMA1_Stream1->NDTR;
				MD_Connect_RX4_DMAStop(); // 关闭DMA接收
				DMA_ClearFlag(DMA1_Stream1, DMA_IT_TCIF1);
				MD_ConnectRX4Task_Flag = 1;		// 使能Gas接收任务
				MD_Connect_RX4_DMALenSet(1000); // 重置接受长度
				MD_Connect_RX4_DMAStart();		// 打开DMA接收
			}
		}
	}
	while (MD_ConnectRX1Task_Flag + MD_ConnectRX2Task_Flag + MD_ConnectRX3Task_Flag + MD_ConnectRX4Task_Flag)
	{
		if (MD_ConnectRX1Task_Flag)
		{
			MD_ConnectRX1Task_Flag = 0;
			MD_ConnectRX_Port = 0;
		}
		else if (MD_ConnectRX2Task_Flag)
		{
			MD_ConnectRX2Task_Flag = 0;
			MD_ConnectRX_Port = 1;
		}
		else if (MD_ConnectRX3Task_Flag)
		{
			MD_ConnectRX3Task_Flag = 0;
			MD_ConnectRX_Port = 2;
		}
		else if (MD_ConnectRX4Task_Flag)
		{
			MD_ConnectRX4Task_Flag = 0;
			MD_ConnectRX_Port = 3;
		}
		if (MD_Connect_RX_Buff[MD_ConnectRX_Port][0] == 0xC1 && MD_Connect_RX_Buff[MD_ConnectRX_Port][2] == 0x08) // LORA设置回复
		{
			TXHData.MD_LORA_Slave_Flag = 1;
			switch (MD_ConnectRX_Port)
			{
			case 0:
				MD_Connect_LORA_IdleMode1;
				break;
			case 1:
				MD_Connect_LORA_IdleMode2;
				break;
			case 2:
				MD_Connect_LORA_IdleMode3;
				break;
			case 3:
				MD_Connect_LORA_IdleMode4;
				break;
			}
			BEEP_OFF;
		}
		else if (TXHData.MDConnectState[MD_ConnectRX_Port].Flag.WorkMode == 1) // 数据模式
		{
			if (TXHData.UDisk_Flag)
				Log_Task(&MD_Connect_RX_Buff[MD_ConnectRX_Port][0], TXHData.MD_Rec_Nummber[MD_ConnectRX_Port], MD_ConnectRX_Port, Info_Receive);
			POSType = TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.POSType;
			switch (POSType)
			{
			case PosBlueSky:
			{
				MD_ConnectRX_pGun = MD_Connect_BCDTou64(MD_Connect_RX_Buff[MD_ConnectRX_Port][1]); // 提取指令抢号
				for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.DeviceNumber; DeviceNumber++)
					if (MD_ConnectRX_pGun == TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunAddr)
					{
						MD_ConnectRX_pGun = DeviceNumber;
						break;
					}
				if ((MD_Connect_RX_Buff[MD_ConnectRX_Port][2] & 0xf0) == 0xa0)
					MD_ConnectRX_Len = MD_Connect_RX_Buff[MD_ConnectRX_Port][2] & 0x0f; // 提取长度码
				else
					MD_ConnectRX_Len = MD_Connect_RX_Buff[MD_ConnectRX_Port][2];
				if (MD_ConnectRX_Len == 0)
					MD_ConnectRX_Len = 16;
				MD_ConnectRX_CMD = MD_Connect_RX_Buff[MD_ConnectRX_Port][MD_ConnectRX_Len + 1]; // 提取命令码
				Temp = MD_Connect_TXDataCheck(&MD_Connect_RX_Buff[MD_ConnectRX_Port][0], MD_ConnectRX_Len + 1);
				if (Temp == MD_Connect_RX_Buff[MD_ConnectRX_Port][MD_ConnectRX_Len + 2] && MD_Connect_RX_Buff[MD_ConnectRX_Port][1] > 0) // 判断校验位
				{
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].RSSI = MD_Connect_RX_Buff[MD_ConnectRX_Port][MD_ConnectRX_Len + 3];
					TXHData.MBCountCutNum[MD_ConnectRX_Port][MD_ConnectRX_pGun] = 0;
					if (TXHData.POS_MonitorModel == 1) // 监管模式
					{
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
						switch (MD_ConnectRX_CMD)
						{
						case C_MDConnectCmdReadState: // 读状态
						{
							if (MD_ConnectRX_Len < 3)
								MD_ConnectRX_CMD = 0;
							break;
						};
						break;
						case C_MDConnectCmdReadFuelState: // 读数据
						{
							if (MD_ConnectRX_Len < 3)
								MD_ConnectRX_CMD = 0;
							break;
						};
						break;
						case C_MDConnectCmdReadPrice: // 读单价
						{
							if (MD_ConnectRX_Len < 3)
								MD_ConnectRX_CMD = 0;
							break;
						};
						break;
						case C_MDConnectCmdReadTotal: // 读总累
						{
							if (MD_ConnectRX_Len < 3)
								MD_ConnectRX_CMD = 0;
							break;
						};
						break;
						default:
							MD_ConnectRX_CMD = 0;
							break;
						}
					}
					switch (MD_ConnectRX_CMD)
					{
					case C_MDConnectCmdReadState: // 读状态
					{
						TXHData.LTGunState.State = MD_Connect_RX_Buff[MD_ConnectRX_Port][3];
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake < TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 1 - TXHData.LTGunState.Flag.GunUp;
							//									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = TXHData.LTGunState.Flag.StartFlag;
							if (TXHData.LTGunState.Flag.StartFlag == 0 && TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState == 1)
							{
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 1;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.Start_Flag = 1;
								FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
							}
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x02;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadPrice;
						}
						else if (TXHData.LTGunState.Flag.TitleFlag == 0) // 如果控制权丢失，从新获取控制权
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectASKControlPower;
						}
						else
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 1 - TXHData.LTGunState.Flag.GunUp;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = TXHData.LTGunState.Flag.StartFlag;
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag != TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.Start_Flag)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.Start_Flag = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag;
								if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 1)
								{
									// TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadFuelState;
									// TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
									if (TXHData.POS_Info.Link_Flag == 0 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number)
									{
										TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].RFIDState = 0x11;
										TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].MB_CMD_Next = RFID_MDConnectCmdWriteFullingInfo;
									}
								}
								else
								{
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.ON_OFF = 1;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadFuelState;
									// TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 1;
									if (TXHData.POS_Info.Link_Flag == 0 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number)
									{
										TXHData.MD_Port_Data[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].GunState.Flag.UpdateDisplay = 0;
										TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].RFIDState = 0;
										TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].MB_CMD_Next = RFID_MDConnectCmdWriteFullingInfo;
									}
								}
								FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
							}
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag != TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.GunUP_Flag)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.GunUP_Flag = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag;
								if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag == 0) // 挂枪
								{
									if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState == 1 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag == 0 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.ON_OFF == 0 && TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 0)
									{
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.ON_OFF = 1;
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadFuelState;
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 1;
									}
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 0;
								}
								else // 提枪
								{
									if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag == 0)
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 1;
									else
									{
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 0;
										TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 0;
									}
									if (TXHData.POS_Info.Link_Flag == 0 || TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunControlState == Control_BoxAuto) // 离线了,判断一下是不是需要离线授权
									{
										if (TXHData.OfflineAuthorize == 1 && (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)) // 离线授权
										{
											if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call == 1 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number == 0)
											{
												TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunCapture = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdStart;
												TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0x00;
												TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = NowAuthorizeType_Offline_NoCard;
												FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
												for (i = 0; i < 6; i++)
													TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardNumber[i] = 0;
												for (i = 0; i < 15; i++)
													TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CarLicensePlate[i] = 0;
											}
											else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call == 1)
											{
												// if(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number  == TXHData.MD_Port_Data[Port].GunData[DeviceNumber].GunNummber)//查找对应的RFID设备号
												{
													if (TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].RFIDState == 3) // 标签验证通过
													{
														TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].RFIDState = 0;
														TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunCapture = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
														TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdStart;
														TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0x00;
														TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = NowAuthorizeType_Offline_Card;
														FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
													}
												}
											}
										}
									}
								}
								FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
							}
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 1 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next == C_MDConnectCmdReadState)
							{
								//									if(TXHData.POSCutTimer.Flag == 1)
								//										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdStop;
								//									else
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadFuelState;
							}
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD == C_MDConnectCmdWritePrice && TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 0 && TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState == 0)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectASKControlPower;
							}
						}
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.Flag == 1)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.Flag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadPrice;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						}
						else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.ON_OFF == 0 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag == 1)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadPrice;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						}
						if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online == 1 && TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag == 0 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag == 0 && TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords == 0)
						{
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].ROM_UpData_State.Flag.Update_Flag && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].ROM_UpData_State.Flag.Update_Flag == 0)
							{
								if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].GunVersion.VersionFindFlag)
								{
									for (i = 0; i < 6; i++) // 判断是不是同一个系列
										if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].GunVersion.Version[i] != TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.ROM_UpData_Version[i])
											break;
									if (i == 6)
									{
										for (i = 6; i < 10; i++) // 判断版本号是不是相同
											if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].GunVersion.Version[i] != TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.ROM_UpData_Version[i])
												break;
										if (i != 10)
										{
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].ROM_UpData_State.Flag.Update_Flag = 1;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdSetBaudRate;
										}
									}
								}
							}
						}
					}
					break;
					case C_MDConnectCmdReadFuelState: // 读数据
					{
						if (TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.Device_Type == Display_664)
						{
							if (MD_ConnectRX_Len != 8)
								break;
							for (i = 0; i < 6; i++)
							{
								if ((MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i] & 0x0f) > 0x09)
									break;
								if ((MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i] & 0xf0) > 0x90)
									break;
							}
							if (i < 6)
								break;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.OilCNT = ((MD_Connect_RX_Buff[MD_ConnectRX_Port][3] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][4] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][5]);
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.MoneyCNT = ((MD_Connect_RX_Buff[MD_ConnectRX_Port][6] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][7] << 8) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][8]));
						}
						else
						{
							if (MD_ConnectRX_Len != 10)
								break;
							for (i = 0; i < 8; i++)
							{
								if ((MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i] & 0x0f) > 0x09)
									break;
								if ((MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i] & 0xf0) > 0x90)
									break;
							}
							if (i < 8)
								break;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.OilCNT = ((MD_Connect_RX_Buff[MD_ConnectRX_Port][3] << 24) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][4] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] << 8) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][6]));
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.MoneyCNT = ((MD_Connect_RX_Buff[MD_ConnectRX_Port][7] << 24) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][8] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][9] << 8) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][10]));
						}
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake < TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x04;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadTotal;
						}
						else if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 1 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next == C_MDConnectCmdReadFuelState)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadState;
						}
						else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.Flag == 1)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.Flag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadPrice;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						}
					}
					break;
					case C_MDConnectCmdStart: //
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadState;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
						if (MD_Connect_RX_Buff[MD_ConnectRX_Port][3] == 0x59)
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 1;
						else
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
						FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
					}
					break;
					case C_MDConnectCmdStop: //
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadState;
					}
					break;
					case C_MDConnectPauseFueling: //
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadState;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
					}
					break;
					case C_MDConnectResumeFueling: //
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadState;
					}
					break;
					case C_MDConnectCmdWritePrsetSale: // 预置金额
					{
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End == 1)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadState;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
						}
						else
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdStart;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						}
					}
					break;
					case C_MDConnectCmdWritePrsetVolume: // 预置油量
					{
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End == 1)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadState;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
						}
						else
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdStart;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						}
					}
					break;
					case C_MDConnectCmdReadPrice: // 读单价
					{
						if (TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.Device_Type == Display_664)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price = ((MD_Connect_RX_Buff[MD_ConnectRX_Port][3] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][4]);
						}
						else
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price = ((MD_Connect_RX_Buff[MD_ConnectRX_Port][3] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][4] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][5]);
						}
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake < TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x03;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadFuelState;
						}
						else
						{
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End == 1)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End = 0;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadFuelState;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
							}
							else
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadTotal;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
							}
						}
					}
					break;
					case C_MDConnectCmdWritePrice: // xie单价
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadState;
					}
					break;
					case C_MDConnectCmdReadTotal: // 读总累
					{
						if (TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.Device_Type == Display_664)
						{
							if (MD_ConnectRX_Len != 12)
								break;
							for (i = 0; i < 10; i++)
							{
								if ((MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i] & 0x0f) > 0x09)
									break;
								if ((MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i] & 0xf0) > 0x90)
									break;
							}
							if (i < 10)
								break;
							Tempu64 = 0;
							for (i = 0; i < 5; i++)
							{
								Tempu64 <<= 8;
								Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i];
							}
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalLit = Tempu64;
							Tempu64 = 0;
							for (i = 0; i < 5; i++)
							{
								Tempu64 <<= 8;
								Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][8 + i];
							}
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalMoney = Tempu64;
						}
						else
						{
							if (MD_ConnectRX_Len != 14)
								break;
							for (i = 0; i < 12; i++)
							{
								if ((MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i] & 0x0f) > 0x09)
									break;
								if ((MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i] & 0xf0) > 0x90)
									break;
							}
							if (i < 12)
								break;
							Tempu64 = 0;
							for (i = 0; i < 6; i++)
							{
								Tempu64 <<= 8;
								Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i];
							}
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalLit = Tempu64;
							Tempu64 = 0;
							for (i = 0; i < 6; i++)
							{
								Tempu64 <<= 8;
								Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][9 + i];
							}
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalMoney = Tempu64;
						}

						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							Tempu64 = MD_ConnectRX_Port * 16 + MD_ConnectRX_pGun;																  // 计算打印存储位置
							if (TXHData.POS_Info.Link_Flag == 0																					  // 离线了,判断一下是不是需要离线记录
								|| (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunControlState == Control_BoxAuto)		  // 自主授权模式，判断一下是不是需要离线记录
								|| TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType > NowAuthorizeType_Online) // 离线启动的，判断一下是不是需要离线记录
							{
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = 0;
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL;
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData;
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].RTIME = TXHData.CTIME;
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price;
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0;
								for (i = 0; i < 6; i++)
									TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CardNum[i] = TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].CardNumber[i + 4]; // 卡号信息有10字节，这里只取后6
								for (i = 0; i < 10; i++)
									TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].CardNumber[i] = 0;
								AT45DBItemWrite(CA_PREXDATA, TXHData.PREXDATA_WaitUpNummber / 5);
								FMItemWrite(CF_PREXDATA_TTC, 0);
								if (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)
									TXHData.PREXDATA_WaitUpNummber++;
								FMItemWrite(CF_PREXDATA_WaitUpNummber, 0);
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;

								TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].OrderNumber;
								for (i = 0; i < 6; i++)
									TXHData.PrintLastRecord[Tempu64].CardNum[i] = TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CardNum[i];
							}
							else
							{
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords = 1;
								TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
								for (i = 0; i < 6; i++)
									TXHData.PrintLastRecord[Tempu64].CardNum[i] = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardNumber[i];
							}
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
							FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);

							TXHData.PrintLastRecord[Tempu64].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL;
							TXHData.PrintLastRecord[Tempu64].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData;
							TXHData.PrintLastRecord[Tempu64].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
							TXHData.PrintLastRecord[Tempu64].RTIME = TXHData.CTIME;
							TXHData.PrintLastRecord[Tempu64].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price;

							FMItemWrite(CF_PrintLastRecord, Tempu64);
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 0;
						}
						else
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadState;
					}
					break;
					case C_MDConnectCmdWriteTotal: // xie
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadState;
					}
					break;
					case C_MDConnectCmdWritePulseCoefficient: // xie
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadState;
					}
					break;
					case C_MDConnectASKControlPower: // 要控制权
					{
						TXHData.POSLOCK_Impower = 1;
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake < TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x01;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadVersion;
						}
						else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD == C_MDConnectCmdWritePrice)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdWritePrice;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = 0;
						}
						else
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadState;
					}
					break;
					case C_MDConnectReturnControlPower: // 还控制权
					{
						TXHData.POSLOCK_Impower = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadState;
						//							if(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == 0x00)
						//							{
						//								TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						//								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x01;
						//								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdReadState;
						//								}
						//							else if(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD == C_MDConnectCmdWritePrice)
						//							{
						//								TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						//							  TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdWritePrice;
						//								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = 0;
						//							  }
					}
					break;
					case C_MDConnectCmdReadVersion: // 读版本号
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].GunVersion.VersionFindFlag = 1;
						for (i = 0; i < 10; i++)
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].GunVersion.Version[i] = MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 3];
					}
					break;
					case C_MDConnectCmdSetBaudRate: // 同步波特率
					{
						if (((MD_Connect_RX_Buff[MD_ConnectRX_Port][3] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][4] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][5]) == BaudRateSync)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FrameNow = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = C_MDConnectCmdSendFrame;
							MD_Connect_USART_Configuration(MD_ConnectRX_Port, BaudRateSync, USART_WordLength_9b, TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.Parity_Even);
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].ROM_UpData_State.Flag.BaudRateSync_Flag = 1;
						}
					}
					break;
					case C_MDConnectCmdSendFrame: // 传送帧
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FrameNow = (MD_Connect_RX_Buff[MD_ConnectRX_Port][3] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][4];
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FrameNow >= TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.ROM_UpData.FrameTop)
						{
							TXHData.MBCountCutNum[MD_ConnectRX_Port][MD_ConnectRX_pGun] = 6; // 更新完了，断开从新握手
						}
					}
					break;
					}
				}
			}
			break;
			case PosLY: // TXHData.LoopGunNextFlag
			{
				if (MD_Connect_RX_Buff[MD_ConnectRX_Port][0] == 0x04)
					MD_ConnectRX_CMD = 0x04;
				else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][0] == 0x15)
					MD_ConnectRX_CMD = 0x15;
				if (((MD_Connect_RX_Buff[MD_ConnectRX_Port][0] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][1]) == 0x1030)
					MD_ConnectRX_CMD = LY_MDConnectCmdACK0;
				else if (((MD_Connect_RX_Buff[MD_ConnectRX_Port][0] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][1]) == 0x1031)
					MD_ConnectRX_CMD = LY_MDConnectCmdACK1;
				else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][0] == 0x02)
				{
					// BCC_CheckSum(&MD_Connect_RX_Buff[MD_ConnectRX_Port][1] , 5);//校验
					MD_ConnectRX_CMD = (MD_Connect_RX_Buff[MD_ConnectRX_Port][3] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][4];
				}
				MD_ConnectRX_pGun = TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunNow;
				TXHData.MBCountCutNum[MD_ConnectRX_Port][MD_ConnectRX_pGun] = 0;
				if (TXHData.POS_MonitorModel == 1) // 监管模式
				{
					TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
				}
				switch (MD_ConnectRX_CMD)
				{
				case LY_MDConnectCmdACK0: //
				{
					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x05)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x06;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdHandshake;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x0a)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x0b;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdReadTotal;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x0f)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x10;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdReadState;
					}
					else
					{
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next == LY_MDConnectCmdWritePrice)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
						}
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD != LY_MDConnectCmdPoll)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdPoll;
						}
					}
				}
				break;
				case LY_MDConnectCmdACK1: //
				{
					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x08)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x08;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x0b)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x0c;
					}
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next == LY_MDConnectCmdAuthorize)
					{
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 1;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 0;
						FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
					}
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdPoll;
				}
				break;
				case 0x3030: // 握手1
				{
					for (i = 0; i < 6; i++)
						Buff[i] = MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i];
					TempBCD = do_crc(Buff, 6);
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYHandshakeCRC = ((TempBCD >> 8) + TempBCD) % 256;
					//							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYHandshakeCRC = Tempu64 >> 4;

					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x04;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdACK1;
				}
				break;
				case 0x04: //
				{
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake < 0x04) // 等待握手
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdPoll;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake++;
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == 0x04) // 如果三次没有收到握手，跳过
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x0a;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
						}
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == 0x04) // 收到握手，开始验证
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x05;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x08)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x09;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdACK1;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x09)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x0a;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x0d)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x0e;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdPoll;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x0e)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x0f;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x10)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x11;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdPoll;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdPoll;
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
						if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState == 1)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 0)
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords = 1;
							FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
						}
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
					{
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD != LY_MDConnectCmdPoll)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD != LY_MDConnectCmdReadState)
								TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						}
						else
						{
							if(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.Flag == 1)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.Flag = 0;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdReadTotal;
							}
							else
							{
                                TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdPoll;
							    TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
							}
						}
					}
				}
				break;
				case 0x15: // 失败
				{
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdPoll;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdPoll;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
				}
				break;
				case 0x3630: // 握手2
				{
					// if(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x08)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x09;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdACK1;
					}
				}
				break;
				case 0x3632: // 报错信息
				{
					// if(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x08)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdACK1;
					}
				}
				break;
				case 0x3631: // 状态
				{
					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdACK1;
					// if(TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.State != TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.State)
					{
						if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 0x30 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunState == 0x31)
							{
								// if(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake  == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
								{
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 0;
									FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
								}
							}
							else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunState == 0x33)
							{
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 1;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.ON_OFF = 1;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.TimerCountMax = 1000 * 5;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdReadTotal;
							}
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 0;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 0;
						}
						else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 0x31 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag == 0)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 1;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 1;
							}
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 0;
							if (TXHData.POS_Info.Link_Flag == 0 || TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunControlState == Control_BoxAuto) // 离线了,判断一下是不是需要离线授权
							{
								if (TXHData.OfflineAuthorize == 1 && (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)) // 离线授权
								{
									if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call == 1 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number == 0)
									{
										TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = NowAuthorizeType_Offline_NoCard;
										TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0x00;
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].PresetValue = 0x90000000;
										TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunCapture = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
										if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
										{
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].PresteType = Preset_Sale;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdAuthorize;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
										}
									}
									else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call == 1)
									{
										// if(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number  == TXHData.MD_Port_Data[Port].GunData[DeviceNumber].GunNummber)//查找对应的RFID设备号
										{
											if (TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].RFIDState == 3) // 标签验证通过
											{
												TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = NowAuthorizeType_Offline_Card;
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].PresetValue = 0x90000000;
												TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunCapture = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
												if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
												{
													TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].PresteType = Preset_Sale;
													TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdAuthorize;
													TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
												}
												TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0x00;
											}
										}
									}
								}
							}
						}
						else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 0x33)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 1;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 1;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 0)
							{
								FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
							}
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdReadState;
						}
						else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 0x34)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 1;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.ON_OFF = 1;//加个定时器，用来判断是否完成交易记录的生成
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.TimerCountMax = 1000*5;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdReadTotal;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
						}
						Tempu64 = 0;
						for (i = 0; i < 6; i++)
						{
							Tempu64 = Tempu64 << 4;
							Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 6] - 0x30;
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.OilCNT = Tempu64;
						Tempu64 = 0;
						for (i = 0; i < 4; i++)
						{
							Tempu64 = Tempu64 << 4;
							Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 13] - 0x30;
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price = Tempu64;
						Tempu64 = 0;
						for (i = 0; i < 6; i++)
						{
							Tempu64 = Tempu64 << 4;
							Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 17] - 0x30;
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.MoneyCNT = Tempu64;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunState = MD_Connect_RX_Buff[MD_ConnectRX_Port][5];
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.State = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.State;
					}
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake < TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top && (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake > 0x0f)) // 等待主动读数据，防止为握手之前设备主动发数据造成状态识别戳我
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdACK1;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdPoll;
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
						if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 0x30)
							{
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 0;
							}
						if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState == 1 || TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 1)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 0;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords = 1;
							Tempu64 = MD_ConnectRX_Port * 16 + MD_ConnectRX_pGun;

							TXHData.PrintLastRecord[Tempu64].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL;
							TXHData.PrintLastRecord[Tempu64].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData;
							TXHData.PrintLastRecord[Tempu64].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
							TXHData.PrintLastRecord[Tempu64].RTIME = TXHData.CTIME;
							TXHData.PrintLastRecord[Tempu64].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price;
							TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
							FMItemWrite(CF_PrintLastRecord, Tempu64);
							FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
						}
					}
				}
				break;
				case 0x3635: // 累计
				{
					Tempu64 = 0;
					for (i = 0; i < 10; i++)
					{
						Tempu64 = Tempu64 << 4;
						Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 11] - 0x30;
					}
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalLit = Tempu64;
					Tempu64 = 0;
					for (i = 0; i < 10; i++)
					{
						Tempu64 = Tempu64 << 4;
						Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 21] - 0x30;
					}
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalMoney = Tempu64;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
					{
						Tempu64 = MD_ConnectRX_Port * 16 + MD_ConnectRX_pGun;
						if (TXHData.POS_Info.Link_Flag == 0																					  // 离线了,判断一下是不是需要离线记录
							|| (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunControlState == Control_BoxAuto)		  // 自主授权模式，判断一下是不是需要离线记录
							|| TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType > NowAuthorizeType_Online) // 离线启动的，判断一下是不是需要离线记录
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = 0;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].RTIME = TXHData.CTIME;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0;
							for (i = 0; i < 6; i++)
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CardNum[i] = TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].CardNumber[i + 4]; // 卡号信息有10字节，这里只取后6
							for (i = 0; i < 10; i++)
								TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].CardNumber[i] = 0;
							AT45DBItemWrite(CA_PREXDATA, TXHData.PREXDATA_WaitUpNummber / 5);
							FMItemWrite(CF_PREXDATA_TTC, 0);
							if (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)
								TXHData.PREXDATA_WaitUpNummber++;
							FMItemWrite(CF_PREXDATA_WaitUpNummber, 0);
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords = 0;
							TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].OrderNumber;
							for (i = 0; i < 6; i++)
								TXHData.PrintLastRecord[Tempu64].CardNum[i] = TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CardNum[i];
						}
						else
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords = 1;
							TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
							for (i = 0; i < 6; i++)
								TXHData.PrintLastRecord[Tempu64].CardNum[i] = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardNumber[i];
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.ON_OFF = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.TimerCount = 0;
						FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);

						TXHData.PrintLastRecord[Tempu64].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL;
						TXHData.PrintLastRecord[Tempu64].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData;
						TXHData.PrintLastRecord[Tempu64].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
						TXHData.PrintLastRecord[Tempu64].RTIME = TXHData.CTIME;
						TXHData.PrintLastRecord[Tempu64].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price;
						TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
						FMItemWrite(CF_PrintLastRecord, Tempu64);
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x0c)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x0d;
					}
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdACK1;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdReadState;
				}
				break;
				}
			}
			break;
			case PosJP:
			{
				if (MD_Connect_RX_Buff[MD_ConnectRX_Port][0] == 0x04)
					MD_ConnectRX_CMD = 0x04;
				else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][0] == 0x15)
					MD_ConnectRX_CMD = 0x15;
				if (((MD_Connect_RX_Buff[MD_ConnectRX_Port][0] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][1]) == 0x1030)
					MD_ConnectRX_CMD = LY_MDConnectCmdACK0;
				else if (((MD_Connect_RX_Buff[MD_ConnectRX_Port][0] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][1]) == 0x1031)
					MD_ConnectRX_CMD = LY_MDConnectCmdACK1;
				else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][0] == 0x02)
				{
					MD_ConnectRX_CMD = (MD_Connect_RX_Buff[MD_ConnectRX_Port][3] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][4];
				}
				MD_ConnectRX_pGun = TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunNow;
				TXHData.MBCountCutNum[MD_ConnectRX_Port][MD_ConnectRX_pGun] = 0;
				if (TXHData.POS_MonitorModel == 1) // 监管模式
				{
					TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
				}
				switch (MD_ConnectRX_CMD)
				{
				case 0x3630: // 握手
				{
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == 0x00)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x01;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdACK1;
					}
				}
				break;
				case LY_MDConnectCmdACK0: //
				{
					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x02)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x03;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdReadTotal;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x05)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x06;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdReadState;
					}
					else
					{
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next == LY_MDConnectCmdWritePrice)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
						}
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD != LY_MDConnectCmdPoll)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdPoll;
						}
					}
				}
				break;
				case LY_MDConnectCmdACK1: //
				{
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next == LY_MDConnectCmdAuthorize)
					{
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 1;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 0;
						FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
					}
					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdPoll;
				}
				break;
				case 0x04: //
				{
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x01)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x02;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x04)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x05;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x06)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdPoll;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
					{
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD != LY_MDConnectCmdPoll)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD != LY_MDConnectCmdReadState)
								TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						}
						else
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdPoll;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
						}
					}
				}
				break;
				case 0x15: // 失败
				{
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdPoll;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdPoll;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
				}
				break;
				case 0x3641: // 状态
				{
					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdACK1;
					// if(TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.State != TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.State)
					{
						if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 0x30 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 0;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 0;
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunState == 0x31)
							{
								// if(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake  == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
								{
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 0;
									FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
								}
							}
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag == 1)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdReadTotal;
							}
						}
						else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 0x31 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag == 0)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 1;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 1;
							}
							//									else
							//									{
							//										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 0;
							//										TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 0;
							//										}

							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 0;
							if (TXHData.POS_Info.Link_Flag == 0 || TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunControlState == Control_BoxAuto) // 离线了,判断一下是不是需要离线授权
							{
								if (TXHData.OfflineAuthorize == 1 && (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)) // 离线授权
								{
									if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call == 1 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number == 0)
									{
										TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = NowAuthorizeType_Offline_NoCard;
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].PresetValue = 0x90000000;
										TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunCapture = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
										if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
										{
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].PresteType = Preset_Sale;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdAuthorize;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
										}
										TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0x00;
									}
									else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call == 1)
									{
										// if(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number  == TXHData.MD_Port_Data[Port].GunData[DeviceNumber].GunNummber)//查找对应的RFID设备号
										{
											if (TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].RFIDState == 3) // 标签验证通过
											{
												TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = NowAuthorizeType_Offline_Card;
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].PresetValue = 0x90000000;
												TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunCapture = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
												if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
												{
													TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].PresteType = Preset_Sale;
													TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdAuthorize;
													TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
												}
												TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0x00;
											}
										}
									}
								}
							}
						}
						else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 0x33)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 1;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 1;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 0)
							{
								FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
							}
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdReadState;
						}
						else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 0x34)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 1;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdReadTotal;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
						}

						//								else
						//								{
						//									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 0;
						//									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 0;
						//									}
						Tempu64 = 0;
						for (i = 0; i < 8; i++)
						{
							Tempu64 = Tempu64 << 4;
							Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 6] - 0x30;
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.OilCNT = Tempu64;
						Tempu64 = 0;
						for (i = 0; i < 6; i++)
						{
							Tempu64 = Tempu64 << 4;
							Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 15] - 0x30;
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price = Tempu64;
						Tempu64 = 0;
						for (i = 0; i < 8; i++)
						{
							Tempu64 = Tempu64 << 4;
							Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 21] - 0x30;
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.MoneyCNT = Tempu64;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunState = MD_Connect_RX_Buff[MD_ConnectRX_Port][5];
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.State = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.State;
					}
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake < TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdACK1;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdPoll;
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
						if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState == 1)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 0)
							{
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords = 1;
								Tempu64 = MD_ConnectRX_Port * 16 + MD_ConnectRX_pGun;

								TXHData.PrintLastRecord[Tempu64].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL;
								TXHData.PrintLastRecord[Tempu64].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData;
								TXHData.PrintLastRecord[Tempu64].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
								TXHData.PrintLastRecord[Tempu64].RTIME = TXHData.CTIME;
								TXHData.PrintLastRecord[Tempu64].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price;
								TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
								FMItemWrite(CF_PrintLastRecord, Tempu64);
							}
							FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
						}
					}
				}
				break;
				case 0x3642: // 累计
				{
					Tempu64 = 0;
					for (i = 0; i < 12; i++)
					{
						Tempu64 = Tempu64 << 4;
						Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 11] - 0x30;
					}
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalLit = Tempu64;
					Tempu64 = 0;
					for (i = 0; i < 12; i++)
					{
						Tempu64 = Tempu64 << 4;
						Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 23] - 0x30;
					}
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalMoney = Tempu64;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x03)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x04;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
					{
						Tempu64 = MD_ConnectRX_Port * 16 + MD_ConnectRX_pGun;																  // 计算打印存储位置
						if (TXHData.POS_Info.Link_Flag == 0																					  // 离线了,判断一下是不是需要离线记录
							|| (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunControlState == Control_BoxAuto)		  // 自主授权模式，判断一下是不是需要离线记录
							|| TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType > NowAuthorizeType_Online) // 离线启动的，判断一下是不是需要离线记录
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = 0;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].RTIME = TXHData.CTIME;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0;
							for (i = 0; i < 6; i++)
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CardNum[i] = TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].CardNumber[i + 4]; // 卡号信息有10字节，这里只取后6
							for (i = 0; i < 10; i++)
								TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].CardNumber[i] = 0;
							AT45DBItemWrite(CA_PREXDATA, TXHData.PREXDATA_WaitUpNummber / 5);
							FMItemWrite(CF_PREXDATA_TTC, 0);
							if (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)
								TXHData.PREXDATA_WaitUpNummber++;
							FMItemWrite(CF_PREXDATA_WaitUpNummber, 0);
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords = 0;
							TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].OrderNumber;
							for (i = 0; i < 6; i++)
								TXHData.PrintLastRecord[Tempu64].CardNum[i] = TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CardNum[i];
						}
						else
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords = 1;
							TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
							for (i = 0; i < 6; i++)
								TXHData.PrintLastRecord[Tempu64].CardNum[i] = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardNumber[i];
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 0;
						FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);

						TXHData.PrintLastRecord[Tempu64].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL;
						TXHData.PrintLastRecord[Tempu64].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData;
						TXHData.PrintLastRecord[Tempu64].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
						TXHData.PrintLastRecord[Tempu64].RTIME = TXHData.CTIME;
						TXHData.PrintLastRecord[Tempu64].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price;
						TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
						FMItemWrite(CF_PrintLastRecord, Tempu64);
					}
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 0;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LY_MDConnectCmdACK1;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = LY_MDConnectCmdReadState;
				}
				break;
				}
			}
			break;
			case PosDart:
			{
				TXHData.MBCountCutNum[MD_ConnectRX_Port][MD_ConnectRX_pGun] = 0;
				if (MD_Connect_RX_Buff[MD_ConnectRX_Port][1] == 0x70 && MD_Connect_RX_Buff[MD_ConnectRX_Port][2] == 0xFA)
					MD_ConnectRX_CMD = DART_MDConnectCmdPoll;
				else if (((MD_Connect_RX_Buff[MD_ConnectRX_Port][1] & 0xF0) == 0xC0) && (MD_Connect_RX_Buff[MD_ConnectRX_Port][2] == 0xFA))
				{
					MD_ConnectRX_CMD = DART_MDConnectCmdACK;
				}
				else if (((MD_Connect_RX_Buff[MD_ConnectRX_Port][0] & 0xF0) == 0x50) && ((MD_Connect_RX_Buff[MD_ConnectRX_Port][1] & 0xF0) == 0x30))
				{
					MD_ConnectRX_CMD = MD_Connect_RX_Buff[MD_ConnectRX_Port][2];
				}

				MD_ConnectRX_pGun = TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunNow;
				TXHData.MBCountCutNum[MD_ConnectRX_Port][MD_ConnectRX_pGun] = 0;
				if (TXHData.POS_MonitorModel == 1) // 监管模式
				{
					TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
				}
				switch (MD_ConnectRX_CMD)
				{
				case DART_MDConnectCmdPoll: // 轮询
				{
				}
				break;
				case DART_MDConnectCmdACK: //
				{
				}
				break;
				case 0x01: // CD1
				{
					switch (MD_Connect_RX_Buff[MD_ConnectRX_Port][4])
					{
					case 0x01: // 重新握手
					{
					}
					break;
					case 0x02: // 已授权
					{
					}
					break;
					case 0x03: // 实时数据
					{
					}
					break;
					case 0x05: // 复位
					{
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == 0)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 1;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = DART_MDConnectCmdACK;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = DART_MDConnectCmdReadState;
						}
					}
					break;
					}
				}
				break;
				case 0x03:
				{
					TXHData.DartGunState.State = MD_Connect_RX_Buff[MD_ConnectRX_Port][7];
					TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = TXHData.DartGunState.Flag.State;
				}
				break;
				case 0x65: // CD101
				{
					if ((MD_Connect_RX_Buff[MD_ConnectRX_Port][4] & 0xf0) == 0)
						MD_ConnectRX_CMD = DART_MDConnectCmdReadVTotal;
					else
						MD_ConnectRX_CMD = DART_MDConnectCmdReadPTotal;
					// MD_ConnectRX_pGun_Sun = MD_Connect_RX_Buff[MD_ConnectRX_Port][4] & 0x0f;
					for (i = 0; i < TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.DeviceNumber; i++)
						if ((MD_Connect_RX_Buff[MD_ConnectRX_Port][0] - 0x50) == TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[i].GunAddr)
							break;
					// MD_ConnectRX_pGun = i + MD_ConnectRX_pGun_Sun;
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == 1)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 2;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = DART_MDConnectCmdReadPTotal;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == 1)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 2;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = DART_MDConnectCmdReadPTotal;
					}
				}
				break;
				}
			}
			break;
			case PosYWY:
			{
				switch (TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.Device_Type)
				{
				case YWY_Bluesky:
				{
					TempBCD = CheckSum(&MD_Connect_RX_Buff[MD_ConnectRX_Port][1], TXHData.MD_Rec_Nummber[MD_ConnectRX_Port] - 6);
					Tempu64 = StrToInt(&MD_Connect_RX_Buff[MD_ConnectRX_Port][TXHData.MD_Rec_Nummber[MD_ConnectRX_Port] - 5], 4);
					if (Tempu64 == TempBCD)
					{
						TXHData.MBCountCutNum[MD_ConnectRX_Port][0] = 0;
						MD_ConnectRX_CMD = MD_Connect_RX_Buff[MD_ConnectRX_Port][4];
						switch (MD_ConnectRX_CMD)
						{
						case YWY_MDConnectCmdReadData:
						{
							TXHData.TankNumTop = Tempu64 = (TXHData.MD_Rec_Nummber[MD_ConnectRX_Port] - 24) / 65;
							for (i = 0; i < Tempu64; i++)
							{
								if(MD_Connect_RX_Buff[MD_ConnectRX_Port][23 + i * 65] == 0)
								  TXHData.TankState[MD_ConnectRX_Port][i].State = MD_Connect_RX_Buff[MD_ConnectRX_Port][20 + i * 65];
						
								TempF = StrToFloat(&MD_Connect_RX_Buff[MD_ConnectRX_Port][26 + i * 65], 8);
								if(MD_Connect_RX_Buff[MD_ConnectRX_Port][26 + i * 65] != 0x3F)
								  TXHData.TankData[MD_ConnectRX_Port][i].Data.OV = TempF;
								else
									TXHData.TankData[MD_ConnectRX_Port][i].Data.OV = 0;
								TempF = StrToFloat(&MD_Connect_RX_Buff[MD_ConnectRX_Port][50 + i * 65], 8);
								if(MD_Connect_RX_Buff[MD_ConnectRX_Port][50 + i * 65] != 0x3F)
								  TXHData.TankData[MD_ConnectRX_Port][i].Data.OH = TempF;
								else
								  TXHData.TankData[MD_ConnectRX_Port][i].Data.OH = 0;
								TempF = StrToFloat(&MD_Connect_RX_Buff[MD_ConnectRX_Port][58 + i * 65], 8);
								if(MD_Connect_RX_Buff[MD_ConnectRX_Port][58 + i * 65] != 0x3F)
								  TXHData.TankData[MD_ConnectRX_Port][i].Data.WH = TempF;
								else
								  TXHData.TankData[MD_ConnectRX_Port][i].Data.WH = 0;
								TempF = StrToFloat(&MD_Connect_RX_Buff[MD_ConnectRX_Port][66 + i * 65], 8);
								if(MD_Connect_RX_Buff[MD_ConnectRX_Port][66 + i * 65] != 0x3F)
								  TXHData.TankData[MD_ConnectRX_Port][i].Data.TH = TempF;
								else
								  TXHData.TankData[MD_ConnectRX_Port][i].Data.TH = 0;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[i].GunState.Flag.Online = 1;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].RSSI = MD_Connect_RX_Buff[MD_ConnectRX_Port][TXHData.MD_Rec_Nummber[MD_ConnectRX_Port] - 1];
							}
						}
						break;
						case YWY_MDConnectCmdWriteApacity:
						{
						}
						break;
						}
					}
				}
				break;
				case YWY_Probe_KY:
				{
					Tempu64 = (MD_Connect_RX_Buff[MD_ConnectRX_Port][22] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][21];
					TempBCD = CRC_Check(&MD_Connect_RX_Buff[MD_ConnectRX_Port][0], 21);
					if (Tempu64 == TempBCD)
					{
						MD_ConnectRX_pGun = MD_Connect_RX_Buff[MD_ConnectRX_Port][0] - 1;
						TXHData.MBCountCutNum[MD_ConnectRX_Port][MD_ConnectRX_pGun] = 0;
						TXHData.TankState[MD_ConnectRX_Port][MD_ConnectRX_pGun].State = 0;
						TXHData.TankData[MD_ConnectRX_Port][MD_ConnectRX_pGun].Data.OV = 0;
						TXHData.TankData[MD_ConnectRX_Port][MD_ConnectRX_pGun].Data.OH = (float)((MD_Connect_RX_Buff[MD_ConnectRX_Port][3] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][4]) + (float)((MD_Connect_RX_Buff[MD_ConnectRX_Port][5] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][6]) / 65535;
						TXHData.TankData[MD_ConnectRX_Port][MD_ConnectRX_pGun].Data.WH = (float)((MD_Connect_RX_Buff[MD_ConnectRX_Port][7] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][8]) + (float)((MD_Connect_RX_Buff[MD_ConnectRX_Port][9] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][10]) / 65535;
						;
						if ((MD_Connect_RX_Buff[MD_ConnectRX_Port][11] & 0x80) == 0)
							TXHData.TankData[MD_ConnectRX_Port][MD_ConnectRX_pGun].Data.TH = (float)((MD_Connect_RX_Buff[MD_ConnectRX_Port][11] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][12]) / 16;
						else
							TXHData.TankData[MD_ConnectRX_Port][MD_ConnectRX_pGun].Data.TH = 0.0 - ((float)((0 - ((MD_Connect_RX_Buff[MD_ConnectRX_Port][11] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][12])) & 0xffff) / 16.0);
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;

						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].RSSI = MD_Connect_RX_Buff[MD_ConnectRX_Port][23];
						TXHData.TankNumTop = TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.DeviceNumber;
					}
				}
				break;
				case YWY_Pressure:
				{
					Tempu64 = (MD_Connect_RX_Buff[MD_ConnectRX_Port][8] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][7];
					TempBCD = CRC_Check(&MD_Connect_RX_Buff[MD_ConnectRX_Port][0], 7);
					if (Tempu64 == TempBCD)
					{
						MD_ConnectRX_pGun = MD_Connect_RX_Buff[MD_ConnectRX_Port][0] - 1;
						TXHData.MBCountCutNum[MD_ConnectRX_Port][0] = 0;
						TXHData.TankState[MD_ConnectRX_Port][MD_ConnectRX_pGun].State = 0;
						TXHData.TankData[MD_ConnectRX_Port][MD_ConnectRX_pGun].Data.OV = (float)((MD_Connect_RX_Buff[MD_ConnectRX_Port][3] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][4]) / (pow(10, MD_Connect_RX_Buff[MD_ConnectRX_Port][6]));
						TXHData.TankData[MD_ConnectRX_Port][MD_ConnectRX_pGun].Data.OH = 0;
						TXHData.TankData[MD_ConnectRX_Port][MD_ConnectRX_pGun].Data.WH = 0;
						TXHData.TankData[MD_ConnectRX_Port][MD_ConnectRX_pGun].Data.TH = 0;
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].RSSI = MD_Connect_RX_Buff[MD_ConnectRX_Port][9];
						TXHData.TankNumTop = TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.DeviceNumber;
					}
				}
				break;
				}
			}
			break;
			case PosRFID:
			{
				MD_ConnectRX_Len = (MD_Connect_RX_Buff[MD_ConnectRX_Port][2] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][3];
				Tempu64 = (MD_Connect_RX_Buff[MD_ConnectRX_Port][MD_ConnectRX_Len] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][MD_ConnectRX_Len + 1];
				TempBCD = CRC_Check(&MD_Connect_RX_Buff[MD_ConnectRX_Port][0], MD_ConnectRX_Len);
				if (Tempu64 == TempBCD)
				{
					MD_ConnectRX_pGun = MD_Connect_RX_Buff[MD_ConnectRX_Port][1]; // 提取指令地址号
					for (i = 0; i < TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.DeviceNumber; i++)
						if (MD_ConnectRX_pGun == TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[i].GunAddr)
						{
							MD_ConnectRX_pGun = i; // 提取指令抢号
							break;
						}
					TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
					MD_ConnectRX_CMD = MD_Connect_RX_Buff[MD_ConnectRX_Port][4];
					TXHData.MBCountCutNum[MD_ConnectRX_Port][MD_ConnectRX_pGun] = 0;
					switch (MD_ConnectRX_CMD)
					{
					case RFID_MDConnectCmdAllData: // 读所有状态
					{
						Offset = 6;
						for (DeviceNumber = 0; DeviceNumber < MD_Connect_RX_Buff[MD_ConnectRX_Port][5]; DeviceNumber++)
						{
							Offset++;
							MD_ConnectRX_CMD = MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset];
							Offset++;
							switch (MD_ConnectRX_CMD)
							{
							case RFID_MDConnectCmdReadData: // 读状态
							{
								MD_ConnectRX_Len = MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset];
								Offset++;
								if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun + DeviceNumber].ROM_UpData_State.Flag.Update_Flag && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].ROM_UpData_State.Flag.Update_Flag == 0)
								{
									if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].GunVersion.VersionFindFlag)
									{
										for (i = 0; i < 4; i++) // 判断是不是同一个系列
											if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].GunVersion.Version[i] != TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.ROM_UpData_Version[i])
												break;
										if (i == 4)
										{
											for (i = 4; i < 10; i++) // 判断版本号是不是相同
												if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].GunVersion.Version[i] != TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.ROM_UpData_Version[i])
													break;
											if (i != 10)
											{
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].ROM_UpData_State.Flag.Update_Flag = 1;
											}
										}
									}
								}
								if (MD_ConnectRX_Len == 15)
								{
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun + DeviceNumber].GunState.Flag.UpdateDisplay = 1;
									for (i = 0; i < 10; i++)
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].CardNumber[i] = MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset + i];
									Offset += 10;
									for (i = 0; i < 2; i++)
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].CardPSWD[i] = MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset + i];
									Offset += 2;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].Mileage = (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset + 1] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset + 2];
									Offset += 3;
									if (TXHData.POS_Info.Link_Flag == 0) // 离线
									{
										for (i = 0; i < 10; i++)
											if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].CardNumber[i] != 0)
												break;
										if (i == 10)
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].RFIDState = 0x40;
										else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].RFIDState == 0)
										{
											for (WhiteList_Num = 0; WhiteList_Num < TXHData.WhiteList.WhiteListTop; WhiteList_Num++) // 查找白名单
											{
												for (Temp = 0; Temp < 6; Temp++)
													if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].CardNumber[Temp + 4] != TXHData.WhiteList.CardNum[WhiteList_Num][Temp])
														break;
												if (Temp == 6) // z在白名单内
												{
													TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].RFIDState = 3;
													TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun + DeviceNumber].GunState.Flag.UpdateDisplay = 0;
													for (i = 0; i < 15; i++)
														TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].RFIDUserName[i] = 0x20;
													for (i = 0; i < 10; i++)
														TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].CarLicensePlate[i] = 0x20;
													TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].BalanceDecimal = 0;
													for (i = 0; i < 5; i++)
														TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].Balance[i] = 0;
													TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].Mileage;
													break;
												}
											}
											if (WhiteList_Num == TXHData.WhiteList.WhiteListTop)
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].RFIDState = 0x40;
										}
									}
									switch (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].RFIDState)
									{
									case 3:
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdWriteCardInfo;
										break;
									case 17:
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdWriteFullingInfo;
										break;
									case 0x40:
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdWriteCardInfo;
										break;
									}
								}
								else
								{
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun + DeviceNumber].GunState.Flag.UpdateDisplay = 0;
									if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].ROM_UpData_State.Flag.Update_Flag)
									{
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].FrameNow = 0;
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdROMownload;
									}
								}
							}
							break;
							case RFID_MDConnectCmdWriteCardInfo: //
							{
								switch (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].RFIDState)
								{
								case 0x40:
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].RFIDState = 0;
									break;
								}
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdReadData;
								// if(TXHData.POS_Info.Link_Flag == 0)//离线
							}
							break;
							case RFID_MDConnectCmdWriteFullingInfo: // 读
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun + DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdReadData;
							}
							break;
							}
						}
					}
					break;
					case RFID_MDConnectCmdReadData: // 读状态
					{
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == 0)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x01;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = RFID_MDConnectCmdReadVersion;
						}
						else
						{
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].ROM_UpData_State.Flag.Update_Flag && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].ROM_UpData_State.Flag.Update_Flag == 0)
							{
								if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].GunVersion.VersionFindFlag)
								{
									for (i = 0; i < 4; i++) // 判断是不是同一个系列
										if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].GunVersion.Version[i] != TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.ROM_UpData_Version[i])
											break;
									if (i == 4)
									{
										for (i = 4; i < 10; i++) // 判断版本号是不是相同
											if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].GunVersion.Version[i] != TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.ROM_UpData_Version[i])
												break;
										if (i != 10)
										{
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].ROM_UpData_State.Flag.Update_Flag = 1;
										}
									}
								}
							}
						}
						if (MD_ConnectRX_Len == 17)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
							for (i = 0; i < 10; i++)
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardNumber[i] = MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 5];
							for (i = 0; i < 2; i++)
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardPSWD[i] = MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 15];
						}
						else if (MD_ConnectRX_Len == 20)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
							for (i = 0; i < 10; i++)
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardNumber[i] = MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 5];
							for (i = 0; i < 2; i++)
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardPSWD[i] = MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 15];
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Mileage = (MD_Connect_RX_Buff[MD_ConnectRX_Port][17] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][18] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][19];
							if (TXHData.POS_Info.Link_Flag == 0) // 离线
							{
								for (i = 0; i < 10; i++)
									if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardNumber[i] != 0)
										break;
								if (i == 10)
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].RFIDState = 0x40;
								else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].RFIDState == 0)
								{
									for (WhiteList_Num = 0; WhiteList_Num < TXHData.WhiteList.WhiteListTop; WhiteList_Num++) // 查找白名单
									{
										for (Temp = 0; Temp < 6; Temp++)
											if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardNumber[Temp + 4] != TXHData.WhiteList.CardNum[WhiteList_Num][Temp])
												break;
										if (Temp == 6) // z在白名单内
										{
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].RFIDState = 3;
											TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 0;
											for (i = 0; i < 15; i++)
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].RFIDUserName[i] = 0x20;
											for (i = 0; i < 10; i++)
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CarLicensePlate[i] = 0x20;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].BalanceDecimal = 0;
											for (i = 0; i < 5; i++)
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Balance[i] = 0;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Mileage;
											break;
										}
									}
									if (WhiteList_Num == TXHData.WhiteList.WhiteListTop)
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].RFIDState = 0x40;
								}
							}
							switch (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].RFIDState)
							{
							case 3:
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = RFID_MDConnectCmdWriteCardInfo;
								break;
							case 17:
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = RFID_MDConnectCmdWriteFullingInfo;
								break;
							case 0x40:
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = RFID_MDConnectCmdWriteCardInfo;
								break;
							}
						}
						else if (MD_ConnectRX_Len == 6) // 有状态返回
						{
							if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 1) // 标签消失
							{
								zhtningzhuangtai = 3;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = RFID_MDConnectCmdLossACK;
								if (TXHData.MD_Port_Data[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].GunState.Flag.Start_Flag)
								{
									switch (TXHData.MD_Port_Data[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].PortData.POSType)
									{
									case PosBlueSky:
										TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].MB_CMD_Next = C_MDConnectPauseFueling;
										break;
									case PosBlueSkyPlus:
										TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].MB_CMD_Next = LTP_GunCMDSuspend;
										break;
									}
									TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].pGunCapture = TXHData.MD_Port_Data[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].GunNummber;
								}
							}
							else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 2) // 标签恢复
							{
								zhtningzhuangtai = 4;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = RFID_MDConnectCmdFindACK;
								if (TXHData.MD_Port_Data[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].GunState.Flag.Start_Flag)
								{
									switch (TXHData.MD_Port_Data[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].PortData.POSType)
									{
									case PosBlueSky:
										TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].MB_CMD_Next = C_MDConnectResumeFueling;
										break;
									case PosBlueSkyPlus:
										TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].MB_CMD_Next = LTP_GunCMDContinue;
										break;
									}
									TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].pGunCapture = TXHData.MD_Port_Data[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].GunNummber;
								}
							}
						}
						else
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 0;
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].ROM_UpData_State.Flag.Update_Flag)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FrameNow = 0;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = RFID_MDConnectCmdROMownload;
							}
						}
					}
					break;
					case RFID_MDConnectCmdFindACK: //
					case RFID_MDConnectCmdLossACK: //
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = RFID_MDConnectCmdReadData;
					}
					break;
					case RFID_MDConnectCmdWriteCardInfo: //
					{
						switch (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].RFIDState)
						{
						case 0x40:
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].RFIDState = 0;
							break;
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = RFID_MDConnectCmdReadData;
						// if(TXHData.POS_Info.Link_Flag == 0)//离线
					}
					break;
					case RFID_MDConnectCmdWriteFullingInfo: // 读
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = RFID_MDConnectCmdReadData;
					}
					break;
					case RFID_MDConnectCmdWriteBindingInfo: //
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x03;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = RFID_MDConnectCmdReadData;
					}
					break;
					case RFID_MDConnectCmdReadVersion: // 读版本号
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x02;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = RFID_MDConnectCmdWriteBindingInfo;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].GunVersion.VersionFindFlag = 1;
						for (i = 0; i < 10; i++)
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].GunVersion.Version[i] = MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 5];
						if (MD_ConnectRX_Len == 21)
						{
							//									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].SonDevice.SonNumber = MD_Connect_RX_Buff[MD_ConnectRX_Port][15];
							//									for(i = 0;i < 4;i ++)
							//										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].SonDevice.SonAddress[i] = MD_Connect_RX_Buff[MD_ConnectRX_Port][16+i];
						}
					}
					break;
					case RFID_MDConnectCmdROMownload: //
					{
						// TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = RFID_MDConnectCmdReadData;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FrameNow = (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][6];
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FrameNow >= TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.ROM_UpData.FrameTop)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = RFID_MDConnectCmdReadData;
							// TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].ROM_UpData_State.Flag.Update_Flag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].ROM_UpData_State.Flag.Update_Flag = 0;
							// FMItemWrite(CF_MD_Port_Data,MD_ConnectRX_Port);
						}
					}
					break;
					}
				}
			}
			break;
			case PosYGao:
			{
				MD_ConnectRX_pGun = MD_Connect_RX_Buff[MD_ConnectRX_Port][4]; // 提取指令抢号
				for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.DeviceNumber; DeviceNumber++)
				{
					if (MD_ConnectRX_pGun == TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunAddr)
					{
						MD_ConnectRX_pGun = DeviceNumber;
						break;
					}
				}
				MD_ConnectRX_CMD = MD_Connect_RX_Buff[MD_ConnectRX_Port][3]; // 提取命令码
				switch (MD_ConnectRX_CMD)
				{
				case YG_MDConnectCmdWritePrset:
					MD_ConnectRX_Len = 7;
					break;
				case YG_MDConnectCmdWritePrice:
					MD_ConnectRX_Len = 7;
					break;
				case YG_MDConnectCmdStop:
					MD_ConnectRX_Len = 6;
					break;
				case YG_MDConnectCmdStart:
					MD_ConnectRX_Len = 6;
					break;
				case YG_MDConnectControlMode:
					MD_ConnectRX_Len = 6;
					break;
				case YG_MDConnectCmdReadTotal:
					MD_ConnectRX_Len = 18;
					break;
				case YG_MDConnectCmdRemovePrset:
					MD_ConnectRX_Len = 7;
					break;
				case YG_MDConnectCmdReadVersion:
					MD_ConnectRX_Len = 9;
					break;
				case YG_MDConnectCmdUnLock:
					MD_ConnectRX_Len = 6;
					break;
				case YG_MDConnectCmdLock:
					MD_ConnectRX_Len = 6;
					break;
				case YG_MDConnectCmdReadFuelVolumeState:
					MD_ConnectRX_Len = 11;
					break;
				case YG_MDConnectCmdReadFuelSaleState:
					MD_ConnectRX_Len = 11;
					break;
				case YG_MDConnectCmdReadFuelRecord:
					MD_ConnectRX_Len = 42;
					break;
				}
				Temp = BCC_CheckSum(&MD_Connect_RX_Buff[MD_ConnectRX_Port][3], MD_ConnectRX_Len - 4);
				if (Temp == MD_Connect_RX_Buff[MD_ConnectRX_Port][MD_ConnectRX_Len - 1] && MD_Connect_RX_Buff[MD_ConnectRX_Port][1] > 0) // 判断校验位
				{
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].RSSI = MD_Connect_RX_Buff[MD_ConnectRX_Port][MD_ConnectRX_Len];
					TXHData.MBCountCutNum[MD_ConnectRX_Port][MD_ConnectRX_pGun] = 0;
					if (TXHData.POS_MonitorModel == 1) // 监管模式
					{
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
					}
					switch (MD_ConnectRX_CMD)
					{
					case YG_MDConnectCmdReadFuelVolumeState: // 读状态
					case YG_MDConnectCmdReadFuelSaleState:	 // 读数据
					{
						if (MD_ConnectRX_CMD == YG_MDConnectCmdReadFuelVolumeState)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.OilCNT = ((MD_Connect_RX_Buff[MD_ConnectRX_Port][5] << 24) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][6] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][7] << 8) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][8]));
							Tempu64 = MD_Connect_BCDTou64(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.OilCNT);
							TempBCD = pow(10, TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.GunDec.Dec.OilCNT + TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.GunDec.Dec.Price - TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.GunDec.Dec.MoneyCNT); // 换算小数位
							Tempu64 = (Tempu64 * MD_Connect_BCDTou64(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price) + TempBCD / 2) / TempBCD;																					  // 计算包含四舍五入
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.MoneyCNT = MD_Connect_u64ToBCD(Tempu64);
						}
						else if (MD_ConnectRX_CMD == YG_MDConnectCmdReadFuelSaleState)
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.MoneyCNT = ((MD_Connect_RX_Buff[MD_ConnectRX_Port][5] << 24) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][6] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][7] << 8) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][8]));
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].YGGunState.State = MD_Connect_RX_Buff[MD_ConnectRX_Port][9];
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].YGGunState.Flag.GunUp;
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].YGGunState.Flag.State == 0x01 || TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].YGGunState.Flag.State == 0x03)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 1;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
						}
						else
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 0;
						if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag != TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.Start_Flag)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.Start_Flag = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag;
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 0) // 加油结束
							{
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 1;
							}
							FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
						}
						if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag != TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.GunUP_Flag)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.GunUP_Flag = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag;
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag == 0) // 挂枪
							{
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 0;
							}
							else // 提枪
							{
								if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag == 0)
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 1;
								else
								{
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 0;
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 0;
								}
								if (TXHData.POS_Info.Link_Flag == 0 || TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunControlState == Control_BoxAuto) // 离线了,判断一下是不是需要离线授权
								{
									if (TXHData.OfflineAuthorize == 1 && (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)) // 离线授权
									{
										if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call == 1 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number == 0)
										{
											TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = NowAuthorizeType_Offline_NoCard;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunCapture = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdStart;
											TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0x00;
											FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
											for (i = 0; i < 20; i++)
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardNumber[i] = 0;
											for (i = 0; i < 10; i++)
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CarLicensePlate[i] = 0;
										}
									}
									else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call == 1)
									{
										// if(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number  == TXHData.MD_Port_Data[Port].GunData[DeviceNumber].GunNummber)//查找对应的RFID设备号
										{
											if (TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].RFIDState == 3) // 标签验证通过
											{
												TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = NowAuthorizeType_Offline_Card;
												TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunCapture = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
												if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
												{
													TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdStart;
												}
												TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0x00;
											}
										}
									}
								}
							}
						}

						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x01)
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x02;
						else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 0x02)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x03;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdReadTotal;
						}
						else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].YGGunState.Flag.UpdateRecords == 1)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdReadFuelRecord;
							}
						}
					}
					break;
					case YG_MDConnectCmdStart: // 启动
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdReadFuelVolumeState;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 1;
					}
					break;
					case YG_MDConnectCmdStop: // 停机
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdReadFuelVolumeState;
					}
					break;
					case YG_MDConnectCmdWritePrset: // 预置金额
					{
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End == 1)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdReadFuelVolumeState;
						}
						else
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdStart;
						}
					}
					break;
					case YG_MDConnectCmdWritePrice: // xie单价
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdReadFuelVolumeState;
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
					}
					break;
					case YG_MDConnectCmdReadFuelRecord: // 读记录
					{
						Tempu64 = 0;
						for (i = 0; i < 3; i++)
						{
							Tempu64 <<= 8;
							Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][5 + i];
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.MoneyCNT = MD_Connect_u64ToBCD(Tempu64);
						Tempu64 = 0;
						for (i = 0; i < 3; i++)
						{
							Tempu64 <<= 8;
							Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][8 + i];
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.OilCNT = MD_Connect_u64ToBCD(Tempu64);
						Tempu64 = 0;
						for (i = 0; i < 3; i++)
						{
							Tempu64 <<= 8;
							Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][19 + i];
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price = Tempu64;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdReadTotal;
					}
					break;
					case YG_MDConnectCmdReadTotal: // 读总累
					{
						Tempu64 = 0;
						for (i = 0; i < 4; i++)
						{
							Tempu64 <<= 8;
							Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][5 + i];
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalMoney = MD_Connect_u64ToBCD(Tempu64);
						Tempu64 = 0;
						for (i = 0; i < 4; i++)
						{
							Tempu64 <<= 8;
							Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][9 + i];
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalLit = MD_Connect_u64ToBCD(Tempu64);

						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].YGGunState.Flag.UpdateRecords == 1)
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdReadFuelRecordConfirm;
							else
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdReadFuelVolumeState;
							Tempu64 = MD_ConnectRX_Port * 16 + MD_ConnectRX_pGun;																  // 计算打印存储位置
							if (TXHData.POS_Info.Link_Flag == 0																					  // 离线了,判断一下是不是需要离线记录
								|| (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunControlState == Control_BoxAuto)		  // 自主授权模式，判断一下是不是需要离线记录
								|| TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType > NowAuthorizeType_Online) // 离线启动的，判断一下是不是需要离线记录
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 0;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = 0;
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL;
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData;
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price;
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].RTIME = TXHData.CTIME;
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0;
								for (i = 0; i < 6; i++)
									TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CardNum[i] = TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].CardNumber[i + 4]; // 卡号信息有10字节，这里只取后6
								for (i = 0; i < 10; i++)
									TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].CardNumber[i] = 0;
								AT45DBItemWrite(CA_PREXDATA, TXHData.PREXDATA_WaitUpNummber / 5);
								FMItemWrite(CF_PREXDATA_TTC, 0);
								if (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)
									TXHData.PREXDATA_WaitUpNummber++;
								FMItemWrite(CF_PREXDATA_WaitUpNummber, 0);
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords = 0;
								TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].OrderNumber;
								for (i = 0; i < 6; i++)
									TXHData.PrintLastRecord[Tempu64].CardNum[i] = TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CardNum[i];
							}
							else
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 0;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords = 1;
								TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
								for (i = 0; i < 6; i++)
									TXHData.PrintLastRecord[Tempu64].CardNum[i] = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardNumber[i];
							}

							FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);

							TXHData.PrintLastRecord[Tempu64].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL;
							TXHData.PrintLastRecord[Tempu64].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData;
							TXHData.PrintLastRecord[Tempu64].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
							TXHData.PrintLastRecord[Tempu64].RTIME = TXHData.CTIME;
							TXHData.PrintLastRecord[Tempu64].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price;
							TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
							FMItemWrite(CF_PrintLastRecord, Tempu64);
						}
						else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake < TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdReadFuelVolumeState;
						}
					}
					break;
					case YG_MDConnectControlMode: // 要控制权
					{
						TXHData.POSLOCK_Impower = 1;
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake < TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x01;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdReadFuelVolumeState;
						}
					}
					break;
					case YG_MDConnectCmdLock: // 锁定
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdReadFuelVolumeState;
					}
					break;
					case YG_MDConnectCmdUnLock: // 解锁
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = YG_MDConnectCmdReadFuelVolumeState;
					}
					break;
					}
				}
			}
			break;

			case PosHongYang:
			{
				MD_ConnectRX_pGun = TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunNow; // 提取指令抢号
				MD_ConnectRX_Len = MD_Connect_RX_Buff[MD_ConnectRX_Port][0];
				MD_ConnectRX_CMD = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next; // 提取命令码,,可能会有时间差，发送命令已经变更，还未发送的时候收到上一次指令，要想办法处理
				Temp = InteiHEXCheck(&MD_Connect_RX_Buff[MD_ConnectRX_Port][0], MD_ConnectRX_Len);
				if (Temp == MD_Connect_RX_Buff[MD_ConnectRX_Port][MD_ConnectRX_Len] && MD_Connect_RX_Buff[MD_ConnectRX_Port][1] > 0) // 判断校验位
				{
					TXHData.MBCountCutNum[MD_ConnectRX_Port][MD_ConnectRX_pGun] = 0;
					switch (MD_ConnectRX_CMD)
					{
					case HY_MDConnectCmdReadFuelData: // 读数据
					{
						if (MD_ConnectRX_Len == 0x0D)
						{
							TXHData.HYState.State = MD_Connect_RX_Buff[MD_ConnectRX_Port][1];
							TXHData.HYSelfTestState.State = MD_Connect_RX_Buff[MD_ConnectRX_Port][11];
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake <= 3) // 多读几次数据，可能刚上电的数据不对
							{
								if (TXHData.HYSelfTestState.State > 0)
								{
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake++;
									if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake >= 4)
									{
										TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 1 - TXHData.HYSelfTestState.Flag.GunUp;
										if (TXHData.HYState.Flag.StartFlag == 0 && TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState == 1)
										{
											TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 1;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.Start_Flag = 1;
											FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
										}
										TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x04;
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdReadPrice;
									}
								}
							}
							else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
							{
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 1 - TXHData.HYSelfTestState.Flag.GunUp;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = TXHData.HYState.Flag.StartFlag;
								if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag != TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.Start_Flag)
								{
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.Start_Flag = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag;
									if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 0)
									{
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.ON_OFF = 1;
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 1;
									}
									FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
								}
								if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag != TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.GunUP_Flag)
								{
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.GunUP_Flag = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag;
									if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag == 0) // 挂枪
									{
										if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState == 1 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag == 0 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.ON_OFF == 0 && TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 0)
										{
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.ON_OFF = 1;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 1;
										}
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 0;
									}
									else // 提枪
									{
										if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag == 0)
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 1;
										else
										{
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 0;
											TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 0;
										}
										if (TXHData.POS_Info.Link_Flag == 0 || TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunControlState == Control_BoxAuto)
										{
											if (TXHData.OfflineAuthorize == 1 && (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)) // 离线授权
											{
												if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call == 1 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number == 0)
												{
													TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = NowAuthorizeType_Offline_NoCard;
													TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunCapture = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
													TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdStart;
													TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0x00;
													FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
													for (i = 0; i < 20; i++)
														TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardNumber[i] = 0;
													for (i = 0; i < 10; i++)
														TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CarLicensePlate[i] = 0;
												}
												else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call == 1)
												{
													// if(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number  == TXHData.MD_Port_Data[Port].GunData[DeviceNumber].GunNummber)//查找对应的RFID设备号
													{
														if (TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].RFIDState == 3) // 标签验证通过
														{
															TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = NowAuthorizeType_Offline_Card;
															TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunCapture = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
															TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdStart;
															TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0x00;
															FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
														}
													}
												}
											}
										}
									}
									FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
								}
								if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD == HY_MDConnectCmdWritePrice && TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 0 && TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState == 0)
								{
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectASKControlPower;
								}
								if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 1)
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdReadFuelData;
								else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.Flag == 1)
								{
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.Flag = 0;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdReadPrice;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
								}
							}
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.Device_Type == Display_664)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.MoneyCNT = MD_Connect_u64ToBCD((MD_Connect_RX_Buff[MD_ConnectRX_Port][2] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][3] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][4]);
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.OilCNT = MD_Connect_u64ToBCD((MD_Connect_RX_Buff[MD_ConnectRX_Port][5] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][6] << 8) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][7]));
							}
							else
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.MoneyCNT = MD_Connect_u64ToBCD((MD_Connect_RX_Buff[MD_ConnectRX_Port][2] << 24) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][3] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][4] << 8) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][5]));
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.OilCNT = MD_Connect_u64ToBCD((MD_Connect_RX_Buff[MD_ConnectRX_Port][6] << 24) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][7] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][8] << 8) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][9]));
							}
						}
					}
					break;
					case HY_MDConnectCmdStart: // 启动
					{
						if (MD_ConnectRX_Len == 3)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdReadFuelData;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
							//										TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 1;
							//										FMItemWrite(CF_MD_Port_Data,MD_ConnectRX_Port);
						}
					}
					break;
					case HY_MDConnectCmdStop: // 停机
					{
						if (MD_ConnectRX_Len == 3)
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdReadFuelData;
					}
					break;
					case HY_MDConnectCmdWritePrsetSale: // 预置金额
					{
						if (MD_ConnectRX_Len == 3)
						{
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End == 1)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End = 0;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdReadFuelData;
							}
							else
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdStart;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
							}
						}
					}
					break;
					case HY_MDConnectCmdWritePrsetVolume: // 预置油量
					{
						if (MD_ConnectRX_Len == 3)
						{
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End == 1)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End = 0;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdReadFuelData;
							}
							else
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdStart;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
							}
						}
					}
					break;
					case HY_MDConnectCmdReadPrice: // 读单价
					{
						if (MD_ConnectRX_Len == 0x08)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price = MD_Connect_u64ToBCD((MD_Connect_RX_Buff[MD_ConnectRX_Port][2] << 24) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][3] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][4] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][5]);
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake < TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x05;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdReadTotal;
							}
							else
							{
								if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End == 1)
								{
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End = 0;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdReadFuelData;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
								}
								else
								{
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdReadTotal;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
								}
							}
						}
					}
					break;
					case HY_MDConnectCmdWritePrice: // xie单价
					{
						if (MD_ConnectRX_Len == 3)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].MB_CMD_Next_End = 1;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdReadPrice;
						}
					}
					break;
					case HY_MDConnectCmdReadTotal: // 读总累
					{
						if (MD_ConnectRX_Len == 0x0F)
						{
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.Device_Type == Display_664)
							{
								Tempu64 = 0;
								for (i = 0; i < 5; i++)
								{
									Tempu64 <<= 8;
									Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][2 + 4 - i];
								}
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalLit = Tempu64;
								Tempu64 = 0;
								for (i = 0; i < 5; i++)
								{
									Tempu64 <<= 8;
									Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][7 + 4 - i];
								}
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalMoney = Tempu64;
							}
							else
							{
								Tempu64 = 0;
								for (i = 0; i < 6; i++)
								{
									Tempu64 <<= 8;
									Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][2 + 5 - i];
								}
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalLit = Tempu64;
								Tempu64 = 0;
								for (i = 0; i < 6; i++)
								{
									Tempu64 <<= 8;
									Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][8 + 5 - i];
								}
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalMoney = Tempu64;
							}

							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
							{
								Tempu64 = MD_ConnectRX_Port * 16 + MD_ConnectRX_pGun;																  // 计算打印存储位置
								if (TXHData.POS_Info.Link_Flag == 0																					  // 离线了,判断一下是不是需要离线记录
									|| (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunControlState == Control_BoxAuto)		  // 自主授权模式，判断一下是不是需要离线记录
									|| TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType > NowAuthorizeType_Online) // 离线启动的，判断一下是不是需要离线记录
								{
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = 0;
									TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL;
									TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData;
									TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
									TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].RTIME = TXHData.CTIME;
									TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price;
									TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0;
									for (i = 0; i < 6; i++)
										TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CardNum[i] = TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].CardNumber[i + 4]; // 卡号信息有10字节，这里只取后6
									for (i = 0; i < 10; i++)
										TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].CardNumber[i] = 0;
									AT45DBItemWrite(CA_PREXDATA, TXHData.PREXDATA_WaitUpNummber / 5);
									FMItemWrite(CF_PREXDATA_TTC, 0);
									if (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)
										TXHData.PREXDATA_WaitUpNummber++;
									FMItemWrite(CF_PREXDATA_WaitUpNummber, 0);
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords = 0;
									TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].OrderNumber;
									for (i = 0; i < 6; i++)
										TXHData.PrintLastRecord[Tempu64].CardNum[i] = TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CardNum[i];
								}
								else
								{
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords = 1;
									TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
									for (i = 0; i < 6; i++)
										TXHData.PrintLastRecord[Tempu64].CardNum[i] = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardNumber[i];
								}
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
								FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);

								TXHData.PrintLastRecord[Tempu64].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL;
								TXHData.PrintLastRecord[Tempu64].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData;
								TXHData.PrintLastRecord[Tempu64].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
								TXHData.PrintLastRecord[Tempu64].RTIME = TXHData.CTIME;
								TXHData.PrintLastRecord[Tempu64].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price;
								TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
								FMItemWrite(CF_PrintLastRecord, Tempu64);
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 0;
							}
							else
							{
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
							}
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdReadFuelData;
						}
					}
					break;
					case HY_MDConnectASKControlPower: // 要控制权
					{
						if (MD_ConnectRX_Len == 3)
						{
							TXHData.POSLOCK_Impower = 1;
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake < TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x01;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdReadFuelData;
							}
							else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD == HY_MDConnectCmdWritePrice)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdWritePrice;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYGunNeedCMD = 0;
							}
						}
					}
					break;
					case HY_MDConnectReturnControlPower: // 还控制权
					{
						if (MD_ConnectRX_Len == 3)
						{
							TXHData.POSLOCK_Impower = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = HY_MDConnectCmdReadFuelData;
						}
					}
					break;
					}
				}
			}
			break;

			case PosSSLan: // TXHData.LoopGunNextFlag
			{
				if (MD_Connect_RX_Buff[MD_ConnectRX_Port][0] == 0x04)
					MD_ConnectRX_CMD = 0x04;
				else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][0] == 0x15)
					MD_ConnectRX_CMD = 0x15;
				if (((MD_Connect_RX_Buff[MD_ConnectRX_Port][0] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][1]) == 0x1030)
					MD_ConnectRX_CMD = LY_MDConnectCmdACK0;
				else if (((MD_Connect_RX_Buff[MD_ConnectRX_Port][0] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][1]) == 0x1031)
					MD_ConnectRX_CMD = LY_MDConnectCmdACK1;
				else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][0] == 0x02)
				{
					// BCC_CheckSum(&MD_Connect_RX_Buff[MD_ConnectRX_Port][1] , 5);//校验
					MD_ConnectRX_CMD = (MD_Connect_RX_Buff[MD_ConnectRX_Port][3] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][4];
				}
				MD_ConnectRX_pGun_Father = TXHData.MD_Port_Info[MD_ConnectRX_Port].PumpNow;																															 // 表示
				MD_ConnectRX_pGun = TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNow; // 设备位置
				TXHData.MBCountCutNum[MD_ConnectRX_Port][MD_ConnectRX_pGun_Father] = 0;
				for (i = 0; i < TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNumber; i++) // 同一父设备下的子设备，握手状态同步
				{
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + i].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake;
				}
				switch (MD_ConnectRX_CMD)
				{
				case LY_MDConnectCmdACK0: //
				{
					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake <= 0x05)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = 0x06;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdHandshake;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake <= 0x0a)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = 0x0b;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdReadTotal;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake <= 0x0f)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = 0x10;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdReadState;
					}
					else
					{
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next == LY_MDConnectCmdWritePrice)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNow].GunState.Flag.UpdateDisplay = 1;
						}
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Need != LY_MDConnectCmdPoll)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Need;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Need = LY_MDConnectCmdPoll;
						}
					}
				}
				break;
				case LY_MDConnectCmdACK1: //
				{
					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake <= 0x08)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = 0x08;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake <= 0x0b)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = 0x0c;
					}
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next == LY_MDConnectCmdAuthorize)
					{
						TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 1;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 0;
						FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
					}
					TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdPoll;
				}
				break;
				case 0x3030: // 握手1
				{
					for (i = 0; i < 6; i++)
						Buff[i] = MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i];
					TempBCD = do_crc(Buff, 6);
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun_Father].LYHandshakeCRC = ((TempBCD >> 8) + TempBCD) % 256;
					//							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LYHandshakeCRC = Tempu64 >> 4;

					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun_Father].Handshake = 0x04;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdACK1;
				}
				break;
				case 0x04: //
				{
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake < 0x04) // 等待握手
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdPoll;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake++;
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake == 0x04) // 如果三次没有收到握手，跳过
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = 0x0a;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
						}
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake == 0x04) // 收到握手，开始验证
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = 0x05;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake <= 0x08)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = 0x09;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdACK1;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake <= 0x09)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = 0x0a;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake <= 0x0d)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = 0x0e;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdPoll;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake <= 0x0e)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = 0x0f;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake <= 0x10)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = 0x11;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdPoll;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Need = LY_MDConnectCmdPoll;
						for (i = 0; i < TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNumber; i++)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + i].GunState.Flag.Online = 1;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + i].GunState.Flag.UpdateDisplay = 1;
						}
						if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState == 1)
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 0)
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords = 1;
							FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
						}
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
					{
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Need != LY_MDConnectCmdPoll)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Need != LY_MDConnectCmdReadState)
								TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						}
						else
						{
							if(TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].LTDelayTimer.Flag == 1)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].LTDelayTimer.Flag = 0;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Need = LY_MDConnectCmdReadTotal;
							}
							else
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdPoll;
							    TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
							}
						}
					}
				}
				break;
				case 0x15: // 失败
				{
					TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Need = LY_MDConnectCmdPoll;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdPoll;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
				}
				break;
				case 0x3630: // 握手2
				{
					// if(TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake <= 0x08)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = 0x09;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdACK1;
					}
				}
				break;
				case 0x3632: // 报错信息
				{
					// if(TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake <= 0x08)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdACK1;
					}
				}
				break;
				case 0x3631: // 状态
				{
					if (MD_Connect_RX_Buff[MD_ConnectRX_Port][23] >= 0x31)
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNow = MD_Connect_RX_Buff[MD_ConnectRX_Port][23] - 0x31;
					else
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNow = 0;
					DeviceNumber = TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNow; // 根据当前子设备所在的付设备中的位置，推算设备号
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNow < TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNumber)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdACK1;
						// if(TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.State != TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.State)
						{
							if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 0x30 && TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
							{
								if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].LYGunState == 0x31)
								{
									// if(TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake  == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
									{
										TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.AuthorizeState = 0;
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].Call = 0;
										FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
									}
								}
								else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].LYGunState == 0x33)
								{
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.AuthorizeState = 0;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].WaitPREXDATA_flag = 1;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Need = LY_MDConnectCmdReadTotal;
								}
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.GunUP_Flag = 0;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.Start_Flag = 0;
							}
							else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 0x31 && TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
							{
								if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].WaitPREXDATA_flag == 0)
								{
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].Call = 1;
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.GunUP_Flag = 1;
								}
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.Start_Flag = 0;
								if (TXHData.POS_Info.Link_Flag == 0 || TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunControlState == Control_BoxAuto) // 离线了,判断一下是不是需要离线授权
								{
									if (TXHData.OfflineAuthorize == 1 && (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)) // 离线授权
									{
										if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].Call == 1 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].AssociatedDevices.Number == 0)
										{
											TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].NowAuthorizeType = NowAuthorizeType_Offline_NoCard;
											TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].OrderNumber = 0x00;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunCapture = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].FatherNum;
											if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
											{
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].PresteType = Preset_Sale;
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].PresetValue = 0x90000000;
												TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Need = LY_MDConnectCmdAuthorize;
												TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
											}
										}
										else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].Call == 1)
										{
											// if(TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number  == TXHData.MD_Port_Data[Port].GunData[DeviceNumber].GunNummber)//查找对应的RFID设备号
											{
												if (TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].AssociatedDevices.location].RFIDState == 3) // 标签验证通过
												{
													TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].NowAuthorizeType = NowAuthorizeType_Offline_Card;
													TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunCapture = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FatherNum;
													if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
													{
														TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].PresteType = Preset_Sale;
														TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].PresetValue = 0x90000000;
														TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Need = LY_MDConnectCmdAuthorize;
														TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
													}
													TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].OrderNumber = 0x00;
												}
											}
										}
									}
								}
							}
							else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 0x33)
							{
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.GunUP_Flag = 1;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.AuthorizeState = 0;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.Start_Flag = 1;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
								for (i = 0; i < TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNumber; i++)
								{
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + i].GunState.Flag.Online = 1;
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + i].GunState.Flag.UpdateDisplay = 1;
								}
								if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.Start_Flag == 0)
								{
									FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
								}
								TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Need = LY_MDConnectCmdReadState;
							}
							else if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 0x34 && TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
							{
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.AuthorizeState = 0;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.Start_Flag = 0;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].WaitPREXDATA_flag = 1;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Need = LY_MDConnectCmdReadTotal;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].LTDelayTimer.ON_OFF = 1;//加个定时器，用来判断是否完成交易记录的生成
								TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].LTDelayTimer.TimerCountMax = 1000*5;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
								for (i = 0; i < TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNumber; i++)
								{
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + i].GunState.Flag.Online = 1;
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + i].GunState.Flag.UpdateDisplay = 1;
								}
							}
							Tempu64 = 0;
							for (i = 0; i < 6; i++)
							{
								Tempu64 = Tempu64 << 4;
								Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 6] - 0x30;
							}
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].FData.OilCNT = Tempu64;
							Tempu64 = 0;
							for (i = 0; i < 4; i++)
							{
								Tempu64 = Tempu64 << 4;
								Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 13] - 0x30;
							}
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].Price = Tempu64;
							Tempu64 = 0;
							for (i = 0; i < 6; i++)
							{
								Tempu64 = Tempu64 << 4;
								Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 17] - 0x30;
							}
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].FData.MoneyCNT = Tempu64;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].LYGunState = MD_Connect_RX_Buff[MD_ConnectRX_Port][5];
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].fuelState_B.State = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.State;
						}
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake < TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdACK1;
							//									TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
							//									TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
							//									TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdPoll;
							for (i = 0; i < TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNumber; i++)
							{
								if (i != TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNow)
								{
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + i].GunState.State = 0;
								}
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + i].GunState.Flag.Online = 1;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + i].GunState.Flag.UpdateDisplay = 1;
							}
							if (MD_Connect_RX_Buff[MD_ConnectRX_Port][5] == 0x30)
							{
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.GunUP_Flag = 0;
							}
							if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.AuthorizeState == 1 || TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.Start_Flag == 1)
							{
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.AuthorizeState = 0;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.Start_Flag = 0;
								TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.UpdateRecords = 1;
								Tempu64 = MD_ConnectRX_Port * 16 + MD_ConnectRX_pGun;

								TXHData.PrintLastRecord[Tempu64].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].CTOTAL;
								TXHData.PrintLastRecord[Tempu64].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].FData;
								TXHData.PrintLastRecord[Tempu64].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunNummber;
								TXHData.PrintLastRecord[Tempu64].RTIME = TXHData.CTIME;
								TXHData.PrintLastRecord[Tempu64].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].Price;
								TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].OrderNumber;
								FMItemWrite(CF_PrintLastRecord, Tempu64);
								FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
							}
						}
					}
				}
				break;
				case 0x3635: // 累计
				{
					for (Temp8 = 0; Temp8 < TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNumber; Temp8++)
					{
						Tempu64 = 0;
						for (i = 0; i < 10; i++)
						{
							Tempu64 = Tempu64 << 4;
							Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 11 + Temp8 * 20] - 0x30;
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + Temp8].CTOTAL.TotalLit = Tempu64;
						Tempu64 = 0;
						for (i = 0; i < 10; i++)
						{
							Tempu64 = Tempu64 << 4;
							Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][i + 21 + Temp8 * 20] - 0x30;
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + Temp8].CTOTAL.TotalMoney = Tempu64;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
					}
					
					if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top || TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].WaitPREXDATA_flag == 1)
					{
						//TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
						DeviceNumber = TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNow + TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart; // 根据当前子设备所在的付设备中的位置，推算设备号
						Tempu64 = MD_ConnectRX_Port * 16 + MD_ConnectRX_pGun;
						if (TXHData.POS_Info.Link_Flag == 0																				 // 离线了,判断一下是不是需要离线记录
							|| (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunControlState == Control_BoxAuto)		 // 自主授权模式，判断一下是不是需要离线记录
							|| TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].NowAuthorizeType > NowAuthorizeType_Online) // 离线启动的，判断一下是不是需要离线记录
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].NowAuthorizeType = 0;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].CTOTAL;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].FData;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].Price;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].RTIME = TXHData.CTIME;
							TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].OrderNumber;
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].OrderNumber = 0;
							for (i = 0; i < 6; i++)
								TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CardNum[i] = TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].AssociatedDevices.location].CardNumber[i + 4]; // 卡号信息有10字节，这里只取后6
							for (i = 0; i < 10; i++)
								TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].AssociatedDevices.location].CardNumber[i] = 0;
							AT45DBItemWrite(CA_PREXDATA, TXHData.PREXDATA_WaitUpNummber / 5);
							FMItemWrite(CF_PREXDATA_TTC, 0);
							if (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)
								TXHData.PREXDATA_WaitUpNummber++;
							FMItemWrite(CF_PREXDATA_WaitUpNummber, 0);
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.UpdateRecords = 0;
							TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].OrderNumber;
							for (i = 0; i < 6; i++)
								TXHData.PrintLastRecord[Tempu64].CardNum[i] = TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CardNum[i];
						}
						else
						{
							TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunState.Flag.UpdateRecords = 1;
							TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].OrderNumber;
							for (i = 0; i < 6; i++)
								TXHData.PrintLastRecord[Tempu64].CardNum[i] = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].CardNumber[i];
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].WaitPREXDATA_flag = 0;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].LTDelayTimer.ON_OFF = 0;//加个定时器，用来判断是否完成交易记录的生成
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].LTDelayTimer.TimerCount = 0;
						FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);

						TXHData.PrintLastRecord[Tempu64].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].CTOTAL;
						TXHData.PrintLastRecord[Tempu64].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].FData;
						TXHData.PrintLastRecord[Tempu64].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].GunNummber;
						TXHData.PrintLastRecord[Tempu64].RTIME = TXHData.CTIME;
						TXHData.PrintLastRecord[Tempu64].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[DeviceNumber].Price;
						TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[DeviceNumber].OrderNumber;
						FMItemWrite(CF_PrintLastRecord, Tempu64);
					}
					else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake <= 0x0c)
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Handshake = 0x0d;
					}
					TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LY_MDConnectCmdACK1;
					TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Need = LY_MDConnectCmdReadState;
				}
				break;
				}
			}
			break;

			case PosBlueSkyPlus: // TXHData.LoopGunNextFlag
			{
				MD_ConnectRX_pGun = MD_Connect_BCDTou64(MD_Connect_RX_Buff[MD_ConnectRX_Port][1]); // 提取指令抢号
				for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDeviceTop; DeviceNumber++)
					if (MD_ConnectRX_pGun == MD_Connect_u64ToBCD(TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[DeviceNumber].Address))
					{
						MD_ConnectRX_pGun_Father = DeviceNumber;
						break;
					}
				MD_ConnectRX_Len = (MD_Connect_RX_Buff[MD_ConnectRX_Port][2] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][3];
				Temp16 = CRC_Check(&MD_Connect_RX_Buff[MD_ConnectRX_Port][0], MD_ConnectRX_Len);
				if (Temp16 == ((MD_Connect_RX_Buff[MD_ConnectRX_Port][MD_ConnectRX_Len] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][MD_ConnectRX_Len + 1]))
				{
					TXHData.RNGData = (MD_Connect_RX_Buff[MD_ConnectRX_Port][10] << 24) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][11] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][12] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][13];
					Bluesky_Decrypt(&MD_Connect_RX_Buff[MD_ConnectRX_Port][14], MD_ConnectRX_Len - 14, TXHData.RNGData);

					TXHData.MBCountTimer[MD_ConnectRX_Port].TimerCount = TXHData.MBCountTimer[MD_ConnectRX_Port].TimerCountMax;
					TXHData.MBCountCutNum[MD_ConnectRX_Port][MD_ConnectRX_pGun_Father] = 0;
					MD_ConnectRX_CMDType = MD_Connect_RX_Buff[MD_ConnectRX_Port][15];
					Offset = 16;
					if (MD_ConnectRX_CMDType == 0xA1) // 机指令
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = 0;
						MD_ConnectRX_CMD = MD_ConnectRX_CMDType = MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++];
						switch (MD_ConnectRX_CMD)
						{
						case LTP_DriverCMDReadPassword: //
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Password_Lever = MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++];
							TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Password = (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++] << 24) |
																													  (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++] << 16) |
																													  (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++] << 8) |
																													  MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++];
						}
						break;
						case LTP_DriverCMDWritePassword: //
						{
						}
						break;
						case LTP_DriverCMDReadVerAndMac: //
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Version.VersionFindFlag = 1;
							for (i = 0; i < 10; i++)
								TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Version.Version[i] = MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset + i];
							Offset += 10;
							for (i = 0; i < 12; i++)
								TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Mac[i] = MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset + i];
							Offset += 12;
							for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNumber; DeviceNumber++) // 同一父设备下的子设备，握手状态同步
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + DeviceNumber].Handshake = 1;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + DeviceNumber].GunVersion.VersionFindFlag = 1;
								for (i = 0; i < 10; i++)
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + DeviceNumber].GunVersion.Version[i] = TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Version.Version[i];
							}
						}
						break;
						case LTP_DriverCMDLock: //
						{
						}
						break;
						case LTP_DriverCMDUnlock: //
						{
						}
						break;
						case LTP_DriverCMDSendFrame: //
						{
							TXHData.MBCountTimer[MD_ConnectRX_Port].TimerCountMax = TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.MBCountTime * 10; // 周期;//周期调整ms
							TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].FrameNow = (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset] << 8) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset + 1]);
							Offset += 2;
							if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].FrameNow >= TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.ROM_UpData.FrameTop)
							{
								TXHData.MBCountCutNum[MD_ConnectRX_Port][MD_ConnectRX_pGun_Father] = 6; // 离线
							}
							else
								TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LTP_DriverCMDSendFrame;
						}
						break;
						}
					}
					else if (MD_ConnectRX_CMDType == 0xA2) // 枪指令
					{

						for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNumber; DeviceNumber++)
						{
							MD_ConnectRX_pGun = TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart + DeviceNumber; //
							Offset++;																													// 抢号
							MD_ConnectRX_CMD = MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++];
							DeviceDataLen = Offset++; // 长度
							switch (MD_ConnectRX_CMD)
							{
							case LTP_GunCMDReadStateAndData: //
							{
								TXHData.LTGunState.State = MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++];
								if (TXHData.LTGunState.Flag.StartFlag == 1 || TXHData.LTGunState.Flag.GunUp == 0) // 提枪或者加油
								{
									MD_ConnectRX_pGun_SonDeviceBusy = 1;
								}
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.OilCNT = ((MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++] << 24) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++] << 8) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++]));
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData.MoneyCNT = ((MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++] << 24) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++] << 8) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++]));
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price = (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++] << 16) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++] << 8) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++]);
							}
							case LTP_GunCMDReadState: //
							{
								if (MD_ConnectRX_CMD == LTP_GunCMDReadState) //
								{
									TXHData.LTGunState.State = MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++];
									if (TXHData.LTGunState.Flag.StartFlag == 1 || TXHData.LTGunState.Flag.GunUp == 0) // 提枪或者加油
									{
										MD_ConnectRX_pGun_SonDeviceBusy = 1;
									}
									if (DeviceNumber == (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonNumber - 1))
									{
										if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online == 1 && MD_ConnectRX_pGun_SonDeviceBusy == 0)
										{
											if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart].ROM_UpData_State.Flag.Update_Flag && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart].ROM_UpData_State.Flag.Update_Flag == 0)
											{
												if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Version.VersionFindFlag)
												{
													for (i = 0; i < 6; i++) // 判断是不是同一个系列
														if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Version.Version[i] != TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.ROM_UpData_Version[i])
															break;
													if (i == 6)
													{
														for (i = 6; i < 10; i++) // 判断版本号是不是相同
															if (TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].Version.Version[i] != TXHData.MD_Port_Data[MD_ConnectRX_Port].PortData.ROM_UpData_Version[i])
																break;
														if (i != 10)
														{
															TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].FrameNow = 0;
															TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].SonStart].ROM_UpData_State.Flag.Update_Flag = 1;
															TXHData.MD_Port_Info[MD_ConnectRX_Port].FatherDevice[MD_ConnectRX_pGun_Father].MB_CMD_Next = LTP_DriverCMDSendFrame;
														}
													}
												}
											}
										}
									}
								}
								if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake < TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
								{
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 1 - TXHData.LTGunState.Flag.GunUp;
									if (TXHData.LTGunState.Flag.StartFlag == 0 && TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState == 1)
									{
										//												sprintf(Buff,"%d-AuthorizeState = 1",MD_ConnectRX_pGun);
										//												Log_Task(Buff,TrueCharBuffSize(Buff),MD_ConnectRX_Port,Info_String);
										TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = 1;
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.Start_Flag = 1;
										FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
									}
									TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 0x02;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadTotal;
								}
								else
								{
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 1 - TXHData.LTGunState.Flag.GunUp;
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag = TXHData.LTGunState.Flag.StartFlag;
									if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag != TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.Start_Flag)
									{
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.Start_Flag = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag;
										if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 1)
										{
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadStateAndData;
											if (TXHData.POS_Info.Link_Flag == 0 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number)
											{
												TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].RFIDState = 0x11;
												TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].MB_CMD_Next = RFID_MDConnectCmdWriteFullingInfo;
											}
										}
										else
										{
											//													sprintf(Buff,"%d-WaitPREXDATA_flag = 1",MD_ConnectRX_pGun);
											//													Log_Task(Buff,TrueCharBuffSize(Buff),MD_ConnectRX_Port,Info_String);
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadTotal;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 1;
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.ON_OFF = 1;
								            TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.TimerCountMax = 1000 * 5;
											if (TXHData.POS_Info.Link_Flag == 0 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number)
											{
												TXHData.MD_Port_Data[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunData[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].GunState.Flag.UpdateDisplay = 0;
												TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].RFIDState = 0;
												TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].MB_CMD_Next = RFID_MDConnectCmdWriteFullingInfo;
											}
										}
										FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
									}
									if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag != TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.GunUP_Flag)
									{
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].fuelState_B.Flag.GunUP_Flag = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag;
										if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag == 0) // 挂枪
										{
											if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState == 1 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag == 0 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.ON_OFF == 0 && TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 0) // 已经授权了，但是没有启动直接挂枪，同样要走结算流程
											{
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadTotal;
												TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 1;
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.ON_OFF = 1;
								                TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.TimerCountMax = 1000 * 5;
											}
											TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 0;
										}
										else // 提枪
										{
											if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag == 0)
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 1;
											else
											{
												TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call = 0;
												TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.GunUP_Flag = 0;
											}
											if (TXHData.POS_Info.Link_Flag == 0 || TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunControlState == Control_BoxAuto) // 离线了,判断一下是不是需要离线授权
											{
												if (TXHData.OfflineAuthorize == 1 && (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)) // 离线授权
												{
													if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call == 1 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Number == 0)
													{
														TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunCapture = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
														TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDAuthorize;
														TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0x00;
														TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = NowAuthorizeType_Offline_NoCard;
														FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
														for (i = 0; i < 6; i++)
															TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardNumber[i] = 0;
														for (i = 0; i < 15; i++)
															TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CarLicensePlate[i] = 0;
													}
													else if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Call == 1)
													{
														if (TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].RFIDState == 3) // 标签验证通过
														{
															TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].RFIDState = 0;
															TXHData.MD_Port_Info[MD_ConnectRX_Port].pGunCapture = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
															TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDAuthorize;
															TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0x00;
															TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = NowAuthorizeType_Offline_Card;
															FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
														}
													}
												}
											}
										}
										FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
									}
									if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.Flag == 1)
									{
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.Flag = 0;
										TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 0;
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadTotal;
									}
									if (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Start_Flag == 1 && TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next == LTP_GunCMDReadState)
									{
										TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadStateAndData;
									}
								}
							}
							break;
							case LTP_GunCMDReadTotal: //
							{
								Tempu64 = 0;
								for (i = 0; i < 6; i++)
								{
									Tempu64 <<= 8;
									Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++];
								}
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalLit = Tempu64;
								Tempu64 = 0;
								for (i = 0; i < 6; i++)
								{
									Tempu64 <<= 8;
									Tempu64 |= MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset++];
								}
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL.TotalMoney = Tempu64;
								if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake == TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
								{
									Tempu64 = MD_ConnectRX_Port * 16 + MD_ConnectRX_pGun;																  // 计算打印存储位置
									if (TXHData.POS_Info.Link_Flag == 0																					  // 离线了,判断一下是不是需要离线记录
										|| (TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunControlState == Control_BoxAuto)		  // 自主授权模式，判断一下是不是需要离线记录
										|| TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType > NowAuthorizeType_Online) // 离线启动的，判断一下是不是需要离线记录
									{
										TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].NowAuthorizeType = 0;
										TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL;
										TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData;
										TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
										TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].RTIME = TXHData.CTIME;
										TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price;
										TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
										TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber = 0;
										for (i = 0; i < 6; i++)
											TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CardNum[i] = TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].CardNumber[i + 4]; // 卡号信息有10字节，这里只取后6
										for (i = 0; i < 10; i++)
											TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].AssociatedDevices.location].CardNumber[i] = 0;
										AT45DBItemWrite(CA_PREXDATA, TXHData.PREXDATA_WaitUpNummber / 5);
										FMItemWrite(CF_PREXDATA_TTC, 0);
										if (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)
											TXHData.PREXDATA_WaitUpNummber++;
										FMItemWrite(CF_PREXDATA_WaitUpNummber, 0);
										TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;

										TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].OrderNumber;
										for (i = 0; i < 6; i++)
											TXHData.PrintLastRecord[Tempu64].CardNum[i] = TXHData.PREXDATA[TXHData.PREXDATA_WaitUpNummber % 5].CardNum[i];
									}
									else
									{
										TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateRecords = 1;
										TXHData.PrintLastRecord[Tempu64].OrderNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].OrderNumber;
										for (i = 0; i < 6; i++)
											TXHData.PrintLastRecord[Tempu64].CardNum[i] = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CardNumber[i];
									}
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
									FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
									TXHData.PrintLastRecord[Tempu64].CTOTAL = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].CTOTAL;
									TXHData.PrintLastRecord[Tempu64].FData = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].FData;
									TXHData.PrintLastRecord[Tempu64].GunNumber = TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunNummber;
									TXHData.PrintLastRecord[Tempu64].RTIME = TXHData.CTIME;
									TXHData.PrintLastRecord[Tempu64].Price = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Price;

									FMItemWrite(CF_PrintLastRecord, Tempu64);
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].WaitPREXDATA_flag = 0;
								    TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.TimerCount = 0;
								    TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].LTDelayTimer.ON_OFF = 0;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadState;
									//											sprintf(Buff,"%d-WaitPREXDATA_flag = 0",MD_ConnectRX_pGun);
									//											Log_Task(Buff,TrueCharBuffSize(Buff),MD_ConnectRX_Port,Info_String);
								}
								else
								{
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadState;
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.UpdateDisplay = 1;
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.Online = 1;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
									TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
								}
							}
							break;
							case LTP_GunCMDWritePrset: //
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadState;
								Offset += DeviceDataLen;
							}
							break;
							case LTP_GunCMDAuthorize: //
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadState;
								TXHData.MD_Port_Info[MD_ConnectRX_Port].LoopGunNextFlag = 1;
								if (MD_Connect_RX_Buff[MD_ConnectRX_Port][Offset] == 0x59)
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 1;
								else
									TXHData.MD_Port_Data[MD_ConnectRX_Port].GunData[MD_ConnectRX_pGun].GunState.Flag.AuthorizeState = 0;
								FMItemWrite(CF_MD_Port_Data, MD_ConnectRX_Port);
								Offset += DeviceDataLen;
							}
							break;
							case LTP_GunCMDStop: //
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadState;
								Offset += DeviceDataLen;
							}
							break;
							case LTP_GunCMDContinue: //
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadState;
								Offset += DeviceDataLen;
							}
							break;
							case LTP_GunCMDSuspend: //
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadState;
								Offset += DeviceDataLen;
							}
							break;
							case LTP_GunCMDReadEvent: //
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadState;
								Offset += DeviceDataLen;
							}
							break;
							case LTP_GunCMDReadError: //
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadState;
								Offset += DeviceDataLen;
							}
							break;
							case LTP_GunCMDReadParameter: //
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadState;
								Offset += DeviceDataLen;
							}
							break;
							case LTP_GunCMDWriteParameter: //
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = LTP_GunCMDReadState;
								Offset += DeviceDataLen;
							}
							break;
							}
						}
					}
				}
			}
			break;
			case PosPLC:
			{
				if (MD_Connect_RX_Buff[MD_ConnectRX_Port][0] == 0x03)
				{
					MD_ConnectRX_Len = MD_Connect_RX_Buff[MD_ConnectRX_Port][2];
					Tempu64 = (MD_Connect_RX_Buff[MD_ConnectRX_Port][MD_ConnectRX_Len + 4] << 8) | MD_Connect_RX_Buff[MD_ConnectRX_Port][MD_ConnectRX_Len + 3];
					TempBCD = CRC_Check(&MD_Connect_RX_Buff[MD_ConnectRX_Port][0], MD_ConnectRX_Len + 3);
					if (Tempu64 == TempBCD)
					{
						TXHData.CNGPLCState.Flag.Online = 1;
						TXHData.MBCountCutNum[MD_ConnectRX_Port][0] = 0;
						MD_ConnectRX_CMD = TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next;
						switch (MD_ConnectRX_CMD)
						{
						case PLC_MDConnectCmdReadData:
						{
							for (i = 0; i < MD_ConnectRX_Len; i += 4)
							{
								TXHData.CNGPLCData.Buff[i + 0] = MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i + 3];
								TXHData.CNGPLCData.Buff[i + 1] = MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i + 2];
								TXHData.CNGPLCData.Buff[i + 2] = MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i + 1];
								TXHData.CNGPLCData.Buff[i + 3] = MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i + 0];
							}
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = PLC_MDConnectCmdReadErro;
						}
						break;
						case PLC_MDConnectCmdReadErro:
						{
							for (i = 0; i < MD_ConnectRX_Len; i += 2)
							{
								TXHData.CNGPLCData.Buff[52 + i] = MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i + 1];
								TXHData.CNGPLCData.Buff[52 + i + 1] = MD_Connect_RX_Buff[MD_ConnectRX_Port][3 + i];
							}
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = PLC_MDConnectCmdReadData;
						}
						break;
						}
					}
				}
			}
			break;
			case PosPrice1_4:
			{
				MD_ConnectRX_pGun = 0;
				MD_ConnectRX_Len = MD_Connect_RX_Buff[MD_ConnectRX_Port][2];
				TempBCD = Price_DataCheck(&MD_Connect_RX_Buff[MD_ConnectRX_Port][2], MD_ConnectRX_Len - 1);
				Tempu64 = MD_Connect_RX_Buff[MD_ConnectRX_Port][MD_ConnectRX_Len + 1];
				if (Tempu64 == TempBCD)
				{
					TXHData.MBCountCutNum[MD_ConnectRX_Port][MD_ConnectRX_pGun] = 0;
					MD_ConnectRX_CMD = MD_Connect_RX_Buff[MD_ConnectRX_Port][4];
					switch (MD_ConnectRX_CMD)
					{
					case Price_MDConnectCmdWriteParameter: // 写参数
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = Price_MDConnectCmdReadPrice;
					}
					break;
					case Price_MDConnectCmdReadParameter: // 读参数
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = 1;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = Price_MDConnectCmdReadPrice;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].PriceTagData.State.Flag.Online = 1;
						TXHData.MD_Port_Info[MD_ConnectRX_Port].PriceTagData.SingleOrDouble = MD_Connect_RX_Buff[MD_ConnectRX_Port][7];
						TXHData.MD_Port_Info[MD_ConnectRX_Port].PriceTagData.PriceNumber = MD_Connect_RX_Buff[MD_ConnectRX_Port][8];
						TXHData.MD_Port_Info[MD_ConnectRX_Port].PriceTagData.Length = MD_Connect_RX_Buff[MD_ConnectRX_Port][9];
						TXHData.MD_Port_Info[MD_ConnectRX_Port].PriceTagData.Brightness = MD_Connect_RX_Buff[MD_ConnectRX_Port][11];
					}
					break;
					case Price_MDConnectCmdWritePrice: // 写单价
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = Price_MDConnectCmdReadPrice;
					}
					break;
					case Price_MDConnectCmdReadPrice: // 读单价
					{
						if (TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake < TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].PriceTagData.State.Flag.UpdateDisplay = 1;
							TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].Handshake = TXHData.MD_Port_Info[MD_ConnectRX_Port].Handshake_Top;
						}
						TXHData.MD_Port_Info[MD_ConnectRX_Port].PriceTagData.State.Flag.Online = 1;
						for (i = 0; i < TXHData.MD_Port_Info[MD_ConnectRX_Port].PriceTagData.PriceNumber; i++)
						{
							TXHData.MD_Port_Info[MD_ConnectRX_Port].PriceTagData.Price[i] = 0;
							for (j = 0; j < TXHData.MD_Port_Info[MD_ConnectRX_Port].PriceTagData.Length / 2; j++)
							{
								TXHData.MD_Port_Info[MD_ConnectRX_Port].PriceTagData.Price[i] |= MD_Connect_RX_Buff[MD_ConnectRX_Port][5 + j + i * TXHData.MD_Port_Info[MD_ConnectRX_Port].PriceTagData.Length / 2] << (8 * (TXHData.MD_Port_Info[MD_ConnectRX_Port].PriceTagData.Length / 2 - 1 - j));
							}
						}
					}
					break;
					case Price_MDConnectCmdWriteDecimal: // 写小数位
					{
						TXHData.MD_Port_Info[MD_ConnectRX_Port].GunInfo[MD_ConnectRX_pGun].MB_CMD_Next = Price_MDConnectCmdWritePrice;
					}
					break;
					}
				}
			}
			break;
			}
			for (i = 0; i < 20; i++)
				MD_Connect_RX_Buff[MD_ConnectRX_Port][i] = 0;
		}
		else if (TXHData.MDConnectState[MD_ConnectRX_Port].Flag.WorkMode == 0) // WiFi指令模式
		{
			switch (TXHData.MDConnectState[MD_ConnectRX_Port].Flag.SetModeCMDNext)
			{
			case WIFI_ATRec:
			{
				Temp16 = mystrstr(MD_Connect_RX_Buff[MD_ConnectRX_Port], "OK");
				if (Temp16)
				{
					TXHData.MBCountTimer[MD_ConnectRX_Port].TimerCount = 0;
					TXHData.MBCountTimer[MD_ConnectRX_Port].Flag = 1;
					TXHData.MDConnectState[MD_ConnectRX_Port].Flag.SetModeCMDNext = WIFI_WMODE;
				}
			}
			break;
			case WIFI_WMODE:
			{
				Temp16 = mystrstr(MD_Connect_RX_Buff[MD_ConnectRX_Port], "OK");
				if (Temp16)
				{
					TXHData.MBCountTimer[MD_ConnectRX_Port].TimerCount = 0;
					TXHData.MBCountTimer[MD_ConnectRX_Port].Flag = 1;
					TXHData.MDConnectState[MD_ConnectRX_Port].Flag.SetModeCMDNext = WIFI_WifiRST;
				}
			}
			break;
			case WIFI_WifiWSSSID:
			{
				Temp16 = mystrstr(MD_Connect_RX_Buff[MD_ConnectRX_Port], "OK");
				if (Temp16)
				{
					TXHData.MBCountTimer[MD_ConnectRX_Port].TimerCount = 0;
					TXHData.MBCountTimer[MD_ConnectRX_Port].Flag = 1;
					TXHData.MDConnectState[MD_ConnectRX_Port].Flag.SetModeCMDNext = WIFI_WifiSOCKET;
				}
			}
			break;
			case WIFI_WifiRSSI:
			{
				//							Temp16 = mystrstr(MD_Connect_RX_Buff[MD_ConnectRX_Port],"atus:");
				//							if(Temp16)
				{
					TXHData.MBCountTimer[MD_ConnectRX_Port].TimerCount = 0;
					TXHData.MBCountTimer[MD_ConnectRX_Port].Flag = 1;
					TXHData.POS_Info.WiFiRSSI = MD_Connect_BCDTou64(((MD_Connect_RX_Buff[MD_ConnectRX_Port][Temp16 + 5] - 0x30) << 4) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][Temp16 + 6] - 0x30));
					Temp16 = mystrstr(MD_Connect_RX_Buff[MD_ConnectRX_Port], ",");
					if (Temp16)
					{
						if (MD_Connect_RX_Buff[MD_ConnectRX_Port][Temp16 + 1] >= 0x30)
							TXHData.POS_Info.WiFiChannel = MD_Connect_BCDTou64(((MD_Connect_RX_Buff[MD_ConnectRX_Port][Temp16] - 0x30) << 4) | (MD_Connect_RX_Buff[MD_ConnectRX_Port][Temp16 + 1] - 0x30));
						else
							TXHData.POS_Info.WiFiChannel = MD_Connect_BCDTou64(MD_Connect_RX_Buff[MD_ConnectRX_Port][Temp16] - 0x30);
					}
					TXHData.MDConnectState[MD_ConnectRX_Port].Flag.SetModeCMDNext = WIFI_WifiSOCKET;
				}
			}
			break;
			case WIFI_WifiSOCKET:
			{
				Temp16 = mystrstr(MD_Connect_RX_Buff[MD_ConnectRX_Port], "OK");
				if (Temp16)
				{
					BEEP_OFF;
					TXHData.MDConnectState[MD_ConnectRX_Port].Flag.WorkMode = 1;
					TXHData.MBCountTimer[MD_ConnectRX_Port].TimerCountMax = 1000;
				}
			}
			break;
			case WIFI_WifiRST:
			{
				Temp16 = mystrstr(MD_Connect_RX_Buff[MD_ConnectRX_Port], "OK");
				if (Temp16)
				{
					TXHData.POSNetSetState.Flag.WorkMode = 0;
					TXHData.MDConnectState[MD_ConnectRX_Port].Flag.SetModeCMDNext = WIFI_WifiWSSSID;
					//								TXHData.POSNetSetState.Flag.POSNetSetNeedFlag = 0;
					TXHData.POSReLinkTimer.Flag = 0;
					TXHData.POSReLinkTimer.TimerCount = 0;
				}
			}
			break;
			}
		}
	}
}
