⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cashdll.cpp

📁 利用串口读写数据实现的识币器驱动程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	{
		return iLastError;
	}
}
/*
	[brief]	The CmdSetSecurity function sends SET SECURITY LEVELS command
	[param]	wS	a parameter of type DWORD - a bitmap containing security levels to set
	[param	Addr]	a parameter of type BYTE containing device address. Refer to \link Addr Device address list \endlink for the valid values
	[return	int]  RE_NONE if exchange successfully completed
*/
_CASHCODEDLL_API int _stdcall CmdSetSecurity(DWORD wS,BYTE Addr)
{
	BYTE Data[256]={SYNC,0,9,SET_SECURITY,(BYTE)(wS>>16),(BYTE)(wS>>8),(BYTE)wS,0,0};
	CCommand cmd(Data,0);
	CCommand Response=Transmit(cmd,Addr);
	BYTE ack;
	int iLastError;
	if(!(iLastError=Response.GetCode()))
	{
		if((ack=Response.GetData()[3])!=ACK)
		{
			iLastError=(ack!=ST_INV_CMD)?ER_NAK:ER_INVALID_CMD;
			return iLastError;
		}
		else return RE_NONE;

	}
	else 
	{
		return iLastError;
	}
}
/*	
    [brief]	The CmdBillType function sends ENABLE BILL TYPE command

	[param	enBill]	 a parameter of type DWORD - a bitmap containing 1 in the positions corresponding to the enabled bill types
	[param	escBill] a parameter of type DWORD - a bitmap containing 1 in the positions corresponding to bill type processed with escrow
	[param	Addr]	 a parameter of type BYTE containing device address. Refer to \link Addr Device address list \endlink for the valid values

	[return	int]  RE_NONE if the command was acknowledged

	
*/
_CASHCODEDLL_API int _stdcall CmdBillType(DWORD enBill, DWORD escBill, BYTE Addr)
{
	BYTE Data[256]={SYNC,0,12,BILL_TYPE,
					(BYTE)(enBill>>16),(BYTE)(enBill>>8),(BYTE)enBill,
					(BYTE)(escBill>>16),(BYTE)(escBill>>8),(BYTE)escBill,
					0,0};
	CCommand cmd(Data,0);
	CCommand Response=Transmit(cmd, Addr);
	BYTE ack;
	int iLastError;
	if(!(iLastError=Response.GetCode()))
	{
		if((ack=Response.GetData()[3])!=ACK)
		{
			iLastError=(ack!=ST_INV_CMD)?ER_NAK:ER_INVALID_CMD;
			return iLastError;
		}
		else return RE_NONE;

	}
	else 
	{
		return iLastError;
	}
}
/*
	[brief]	The CmdPack function sends STACK command

	[param	Addr]	a parameter of type BYTE containing device address. Refer to \link Addr Device address list \endlink for the valid values

	[return	int]   RE_NONE if the command was acknowledged

*/
_CASHCODEDLL_API int _stdcall CmdStack(BYTE Addr)
{
	BYTE Data[256]={SYNC,0,6,STACK,0,0};
	CCommand cmd(Data,0);
	CCommand Response=Transmit(cmd,Addr);
	BYTE ack;
	int iLastError;
	if(!(iLastError=Response.GetCode()))
	{
		if((ack=Response.GetData()[3])!=ACK)
		{
			iLastError=(ack!=ST_INV_CMD)?ER_NAK:ER_INVALID_CMD;
			return iLastError;
		}
		else return RE_NONE;

	}
	else 
	{
		return iLastError;
	}
}
/*	
    [brief]	The CmdReturn function sends RETURN command

	[param	Addr]  a parameter of type BYTE containing device address. Refer to \link Addr Device address list \endlink for the valid values

	[return	int]  RE_NONE if the command was acknowledged
*/
_CASHCODEDLL_API int _stdcall CmdReturn(BYTE Addr)
{
	BYTE Data[256]={SYNC,0,6,RETURN,0,0};
	CCommand cmd(Data,0);
	CCommand Response=Transmit(cmd,Addr);
	BYTE ack;
	int iLastError;
	if(!(iLastError=Response.GetCode()))
	{
		if((ack=Response.GetData()[3])!=ACK)
		{
			iLastError=(ack!=ST_INV_CMD)?ER_NAK:ER_INVALID_CMD;
			return iLastError;
		}
		else return RE_NONE;

	}
	else 
	{
		return iLastError;
	}
}

/*	[brief]	The CmdCsStatus function sends RECYCLING CASSETTE STATUS request
            The function is applicable for Bill-To-Bill units only. It sends RECYCLING CASSETTE STATUS request 
            and translates the response data into the CCRSProtocol::Cassettes array so it contains the image of 
            the unit's cassettes.

    [return	int]  RE_NONE if the request succeeded
*/
_CASHCODEDLL_API int _stdcall CmdCsStatus(BYTE Addr,_Cassete *Cassetes)
{
	int iLastError;
	BYTE Data[256]={SYNC,0,6,C_STATUS,0,0};
	CCommand cmd(Data,0);
	CCommand Response=Transmit(cmd,Addr);
	if(!(iLastError=Response.GetCode()))
	{
		if((Response.GetData()[2]==6)&&(Response.GetData()[3]==ST_INV_CMD)) 
		{
			iLastError=ER_INVALID_CMD;
			for(int i=0;i<32;i+=2)
			{
			Cassetes[i/2].BillNumber=0;
			Cassetes[i/2].bEscrow=0;
			Cassetes[i/2].BillType=0;
			Cassetes[i/2].Status=CS_NU;
			} 
			return iLastError;
		}
		for(int i=0;i<(Response.GetData()[2])-5;i+=2)
		{
			Cassetes[i/2].BillNumber=Response.GetData()[i+4];
		
			Cassetes[i/2].BillType=((Response.GetData()[i+3]) & 0x1F);
			Cassetes[i/2].bEscrow=((Cassetes[i/2].BillType==BT_ESCROW));
			if(!((Response.GetData()[i+3]) & 0x80))
				Cassetes[i/2].Status=CS_NU;
			else
				if((Cassetes[i/2].BillType==(BT_NO_TYPE& 0x1F)))
					Cassetes[i/2].Status=CS_NA;
							else Cassetes[i/2].Status=CS_OK;
		}
		for(i;i<32;i+=2)
		{
			Cassetes[i/2].BillNumber=0;
			Cassetes[i/2].bEscrow=0;
			Cassetes[i/2].BillType=0;
			Cassetes[i/2].Status=CS_NU;
		} 
		return RE_NONE;
	}
	else 
	{
		return iLastError;
	}
}
/*	
     [brief]	The CmdUnload function sends UNLOAD command to Bill-To-Bill unit

	 [param	Cass]	a parameter of type BYTE specifiying the source cassette for operation
	 [param	Num]	a parameter of type BYTE specifiying number of bills to unload

	 [return int]  RE_NONE if the command was acknowldged
*/
_CASHCODEDLL_API int _stdcall CmdUnload(BYTE Addr,BYTE Cass, BYTE Num) 
{
	BYTE Data[256]={SYNC,0,8,UNLOAD,0,0};
	WORD bUnload=0;
	Data[4]=Cass+1;
	Data[5]=Num;
	CCommand cmd(Data,0);
	CCommand Response=Transmit(cmd,Addr);
	BYTE ack;
	int iLastError;
	if(!(iLastError=Response.GetCode()))
	{
		if((ack=Response.GetData()[3])!=ACK)
		{
			iLastError=(ack!=ST_INV_CMD)?ER_NAK:ER_INVALID_CMD;
			return iLastError;
		}
		else return RE_NONE;

	}
	else 
	{
		return iLastError;
	}
}
/*	
   [brief]	The CmdIdentEx function sends EXTENDED IDENTIFICATION request
            The function sends EXTENDED IDENTIFICATION request and stores device identification in the member CCCRSProtocol::Ident structure.
            The request is supported by new Bill-To-Bill units only.
   //
   [param	Addr]	a parameter of type BYTE containing device address. Refer to \link Addr Device address list \endlink for the valid values

   [return	int]  RE_NONE if the exchange was successfully completed and data received
*/
_CASHCODEDLL_API int _stdcall CmdIdentExt(BYTE Addr,LPCSTR pPartNumber,
												 LPCSTR pSerialNum,LPCSTR pAssertNum)
{
	int iLastError;
	BYTE Data[256]={SYNC,0,6,IDENT_EXT,0,0};
	CCommand cmd(Data,0);
	CCommand Response=Transmit(cmd,Addr);
	if(!(iLastError=Response.GetCode()))
	{
		if((Response.GetData()[3]==ST_INV_CMD)&&(Response.GetData()[2]==6))
		{
			iLastError=ER_INVALID_CMD;
			return iLastError;
		}
		
		char sTemp[64];
		int iPos=3,iLen=15;
		strncpy(sTemp,(char*)Response.GetData()+iPos,iLen);
		sTemp[iLen]=0;
		iPos+=iLen;
		strcpy((char *)pPartNumber,sTemp);

		iLen=12;
		strncpy(sTemp,(char*)Response.GetData()+iPos,iLen);
		sTemp[iLen]=0;
		iPos+=iLen;
		strcpy((char *)pSerialNum,sTemp);

		iLen = 7;
		strncpy(sTemp,(char*)Response.GetData()+iPos,iLen);
		sTemp[iLen]=0;
		iPos += iLen;
		strcpy((char *)pAssertNum,sTemp);
		return RE_NONE;
	}
	else 
	{
		return iLastError;
	}
}
/*
    [brief]	The CmdSetCasseteType function sends SET RECYCLING CASSETTE TYPE command to Bill-To-Bill unit

	[param	Cass]	a parameter of type BYTE specifiying cassette to setup.
	[param	Status]	a parameter of type BYTE specifiying a new cassette status. refer to \link CSStatus cassette status lest \endlink 
					for possible values
	[param	Type]	a parameter of type BYTE specifiying bill type to assign to the cassette

	[return	int]  RE_NONE if the command was acknowldged
*/
_CASHCODEDLL_API int _stdcall CmdSetCasseteType(BYTE Addr,BYTE Cass, BYTE Status, BYTE Type)
{
	BYTE Data[256]={SYNC,0,8,SET_CASSETES,Cass+1,0,0};
	CCommand cmd(Data,0);
	BYTE Y1=Type;
	BYTE g1=0x1F;
	if(Status==CS_NA) 
	{
		Y1=g1;
	}
	else
	{
		Y1=Type;
	}
	switch(Status)
	{
	case CS_ESCROW:
		Y1|=0x20;
		break;
	case CS_OK:
	case CS_MALFUNCTION:
	case CS_FULL:
		Y1|=0x80;
		break;
	case CS_NA:	
		Y1=0x40|g1;
		break;
	case CS_NU:
	default:
		break;
	}
	cmd.SetByte(Y1,5);
	CCommand Response=Transmit(cmd,Addr);
	BYTE ack;
	int iLastError;
	if(!(iLastError=Response.GetCode()))
	{
		if((ack=Response.GetData()[3])!=ACK)
		{
			iLastError=(ack!=ST_INV_CMD)?ER_NAK:ER_INVALID_CMD;
			return iLastError;
		}
		else 
			return RE_NONE;
	}
	else 
	{
		return iLastError;
	}
}
/*	
    [brief]	The CmdSetOptions function

	[param	dwOpt]	a parameter of type DWORD containing bitmap with options to enable. refer to \link Options Options list \endlink
	[param	Addr]	a parameter of type BYTE containing device address. Refer to \link Addr Device address list \endlink for the valid values

	[return	int]   RE_NONE if the command was acknowledged
*/
_CASHCODEDLL_API int _stdcall CmdSetOptions(DWORD dwOpt, BYTE Addr)
{
	BYTE Data[256]={SYNC,0,10,SET_OPTIONS,
					(BYTE)(dwOpt>>24),(BYTE)(dwOpt>>16),(BYTE)(dwOpt>>8),(BYTE)dwOpt,
					0,0};
	CCommand cmd(Data,0);

	//send commands
	CCommand Response=Transmit(cmd, Addr);
	BYTE ack;
	int iLastError;
	if(!(iLastError=Response.GetCode()))
	{
		if((ack=Response.GetData()[3])!=ACK)
		{
			iLastError=(ack!=ST_INV_CMD)?ER_NAK:ER_INVALID_CMD;
			return iLastError;
		}
		else return RE_NONE;

	}
	else 
	{
		return iLastError;
	}
}

/*	
   [brief]	The CmdGetOptions function sends GET OPTIONS command
            The function reads currently set options from the device. Is applicable to new Bill-To-Bill units only.

   [param	dwOpt]	a parameter of type DWORD & containing a reference to the DWORD variable receiving current options.
   [param	Addr]	a parameter of type BYTE containing device address. Refer to \link Addr Device address list \endlink for the valid values

   [return	int]   RE_NONE if response successfully received
*/
_CASHCODEDLL_API int _stdcall CmdGetOptions(LPDWORD dwOpt, BYTE Addr)
{
	BYTE Data[256]={SYNC,0,6,GET_OPTIONS,0,0};
	CCommand cmd(Data,0);
	CCommand Response=Transmit(cmd,Addr);
	int iLastError;
	if(!(iLastError=Response.GetCode()))
	{
		if((Response.GetData()[3]==ST_INV_CMD)&&(Response.GetData()[2]==6))
		{
			iLastError=ER_INVALID_CMD;
			dwOpt[0]=0;
			return iLastError;
		}
		dwOpt[0]=Response.GetData()[6]+((DWORD)Response.GetData()[5]<<8)+((DWORD)Response.GetData()[4]<<16)+((DWORD)Response.GetData()[3]<<24);
		return RE_NONE;
	}
	else 
	{
		dwOpt=0;
		return iLastError;
	}
}

/*
    [brief]	The CmdGetCRC32 function sends CRC32 request

	[param	dwCRC]	a parameter of type DWORD & containing a reference to the variable receiving CRC32 of the firmware.
	[param	Addr]	a parameter of type BYTE containing device address. Refer to \link Addr Device address list \endlink for the valid values

	[return	int]   RE_NONE if the request was answered
*/
_CASHCODEDLL_API int _stdcall CmdGetCRC32(LPDWORD dwCRC, BYTE Addr)
{
	BYTE Data[256]={SYNC,0,6,CRC32,0,0};
	CCommand cmd(Data,0);
	CCommand Response=Transmit(cmd,Addr);
	int iLastError;
	if(!(iLastError=Response.GetCode()))
	{
		if((Response.GetData()[3]==ST_INV_CMD)&&(Response.GetData()[2]==6))
		{
			iLastError=ER_INVALID_CMD;
			dwCRC[0]=0;
			return iLastError;
		}
		dwCRC[0]=Response.GetData()[6]+((DWORD)Response.GetData()[5]<<8)+((DWORD)Response.GetData()[4]<<16)+((DWORD)Response.GetData()[3]<<24);
		return RE_NONE;
	}
	else 
	{
		dwCRC[0]=0;
		return iLastError;
	}
}
/*
   [brief]	The CmdPowerRecovery function sens POWER RECOVERY command
            The function sends POWER RECOVERY command and stores the response data in the supplied parameters.
            Is applicable to Bill-To-Bill units only.

   [param	State]	a parameter of type BYTE & containing a reference to the variable receiving the Power Up state.
   [param	pBuffer]	a parameter of type LPBYTE containing pointer to the array receiving state extension data.
   [param	iLen]	a parameter of type int & containing a reference to a variable receiving length of the state extension data.

   [return	int] RE_NONE if the request was successfully answered.
*/
_CASHCODEDLL_API int _stdcall CmdPowerRecovery(BYTE Addr,LPBYTE State, LPBYTE pBuffer, int &iLen)
{
	BYTE Data[256]={SYNC,0,6,POWER_RECOVERY,0,0};
	CCommand cmd(Data,0);
	CCommand Response=Transmit(cmd,Addr);
	int iLastError;
	if(!(iLastError=Response.GetCode()))
	{
		if((Response.GetData()[2]==6)&&(Response.GetData()[3]==ST_INV_CMD)) 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -