📄 cashdll.cpp
字号:
#include <StdAfx.h>
#include "ComPort.h"
#include "CashDll.h"
#include "Command.h"
#include "ErrAndCmd_Code.h"
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
CCOMPort *pCom = NULL;
CCommand cmdOut;
CCommand cmdIn;
typedef struct {
int *v;
g_BillTable *pt;
}ThreadPara;
char values[100] = {100,50,20,10,5,2,1};
int intValues[7] = {0};
int *v1 = 0;
DWORD WINAPI CheckThrd(LPVOID lParam);
CCommand Transmit(CCommand CMD, BYTE Addr);
//////////////////////////////////////////////////////////////////////////
_CASHCODEDLL_API BOOL _stdcall OpenPort(int iPortNumber)
{
if(!pCom)
{
pCom = new CCOMPort;
}
return pCom->OpenCOM(iPortNumber);
}
_CASHCODEDLL_API void _stdcall ClosePort()
{
if(pCom !=NULL)
{
pCom->CloseCOM();
delete pCom;
pCom = NULL;
}
}
_CASHCODEDLL_API BOOL _stdcall InitPort(int iPortNumber,int iTo)
{
char S_COM9600[]="9600,N,8,1";
return pCom->InitCOM(iPortNumber,S_COM9600,iTo);
}
/*
[brief] the CmdIdentification function send POLL RESET to th unit
[param Addr] Peripheral Addresses.you can refer to the Command document
[return bool ] true if the command was acknowldged
*/
_CASHCODEDLL_API int _stdcall ResetCMD(BYTE addr)
{
int iLastError;
BYTE Data[256]={SYNC,0,6,RESET,0};
CCommand cmd(Data,0,6);
CCommand Response=Transmit(cmd,addr);
BYTE ack;
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 CmdIdentification function send POLL COMMAND to th unit
[param Addr] Peripheral Addresses.you can refer to the Command document
[param z1] a parameter of type BYTE point is use for containning the third read data
[param z1] a parameter of type BYTE point is use for containning the fourth read data
[return bool ] true if the command was acknowldged
*/
_CASHCODEDLL_API int _stdcall PollCMD(BYTE Addr,LPBYTE z1,LPBYTE z2)
{
int iLastError;
BYTE Data[256]={SYNC,0,6,POLL,0,0};
CCommand cmd(Data,0);
CCommand Response=Transmit(cmd, Addr);
if(!(iLastError=Response.GetCode()))
{
//readAry = Response.GetData();
(*z1)=Response.GetData()[3];
(*z2)=Response.GetData()[4];
return RE_NONE;
}
else
{
(*z1)=0;
(*z2)=0;
return iLastError;
}
}
/*
[brief] the CmdIdentification function send GET STATUS COMMAND to th unit
[param Addr] Peripheral Addresses.you can refer to the Command document
[param BillStatus] a parameter of type point points to a Array,
[return bool] true if the command was acknowldged
*/
_CASHCODEDLL_API int _stdcall CmdStatus(BYTE Addr,LPBYTE BillStatus)
{
BYTE Data[256]={SYNC,0,6,GET_STATUS,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))
{
iLastError=ER_INVALID_CMD;
for(int i=0;i<6;i++)
{
BillStatus[i] = 0;
}
return iLastError;
}
for(int i=0;i<(Response.GetData()[2])-5;i++)
{
BillStatus[i]=Response.GetData()[i+3];
}
return RE_NONE;
}
else
{
return iLastError;
}
}
_CASHCODEDLL_API int KNAPI BV_GetStatus()
{
int iLastError;
BYTE z1,z2;
BYTE Data[256]={SYNC,0,6,POLL,0,0};
CCommand cmd(Data,0);
CCommand Response=Transmit(cmd, 3);
if(!(iLastError=Response.GetCode()))
{
//readAry = Response.GetData();
z1=Response.GetData()[3];
z2=Response.GetData()[4];
if (z1 == 0x43||z1 == 0x46)
{
return 1009;
}
if (z1 == 0x41)
{
return 1008;
}
if (z2 == 0x66)
{
return 1004;
}
if (z1 == 0x19)
{
return 1000;
}
return 0;
}
else
{
z1=0;
z2=0;
return 1;
}
}
/*
[brief] the CmdIdentification function send IDENTIFICATION COMMAND to th unit
[param Addr] Peripheral Addresses.you can refer to the Command document
[param pPartNumber] a parameter of type point points to a Array
[param pSerialNum] a parameter of type point points to a Array
[return bool] true if the command was acknowldged
*/
_CASHCODEDLL_API int _stdcall CmdIdentification(BYTE Addr,LPCSTR pPartNumber,
LPCSTR pSerialNum)
{
int iLastError;
BYTE Data[256]={SYNC,0,6,IDENTIFICATION,0,0};
CCommand cmd(Data,0);
CCommand Response=Transmit(cmd,Addr); //send IDENTIFICATION COMMAND
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);
/*char *strTemp=(char*)Response.GetData()+iPos;
INT64 DS1;
DS1=0;iPos+=8;
for(int i=0;i<7;i++)
{
DS1<<=8;
DS1+=strTemp[i];
}
sprintf((char *)pAssertNum,"%L",DS1);*/
//char *strTemp=(char*)Response.GetData()+iPos;
return RE_NONE;
}
else
{
return iLastError;
}
}
/*
[brief] the CmdIdentification function send GETBILLTABLE COMMAND to th unit
[param Addr] Peripheral Addresses.you can refer to the Command document
[param BillTable] a parameter of type point points to a g_BillTable of the struct,
about this struct you can refernce DLL API document
[return bool] true if the command was acknowldged
*/
_CASHCODEDLL_API int _stdcall GetBillTable(BYTE Addr,g_BillTable *BillTable)//24
{
BYTE Data[256]={SYNC,0,6,GET_BILL_TABLE,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;
for(int i=0;i<24;i++)
{
BillTable[i].iCashValue=0;
strcpy(BillTable[i].sCountryCode,"");
}
return iLastError;
}
for(int i=0;i<(Response.GetData()[2])-5;i+=5)
{
BillTable[i/5].iCashValue=Response.GetData()[i+3];
char sTmp[5];
strncpy(sTmp,(const char *)(Response.GetData()+i+4),3);
sTmp[3]='\0';
strcpy(BillTable[i/5].sCountryCode,sTmp);
if(((Response.GetData())[i+7])&0x80)
{
for(int j=0; j<((Response.GetData()[i+7])&0x7F);j++)
BillTable[i/5].iCashValue /= 10;
}
else
{
for(int j=0; j<((Response.GetData()[i+7])&0x7F);j++)
BillTable[i/5].iCashValue *= 10;
}
}
for(i;i<24*5;i+=5)
{
BillTable[i/5].iCashValue = 0;
strcpy(BillTable[i/5].sCountryCode,"");
}
return RE_NONE;
}
else
{
return iLastError;
}
}
/*
[brief] The CmdDispenseNew function sends a new-style DISPENSE command
[param Addr] Peripheral Addresses.you can refernce Command document
[param pBills] a parameter of type LPBYTE pointing to the array containing actual command parameters or
numbers of bills of each bill type to dispense depending on value of bTypes parameter.
[param bTypes] a parameter of type bool defining format of data in the pBills array:
[false] the array contains numbers of bills of each bill type to dispense.
The position in the array should correspond to the bill type, the value
at that position - number of bils of that type to dispense.
[true] the array contains pairs (bill type),(bill number)
[return bool] true if the command was acknowldged
*/
_CASHCODEDLL_API int _stdcall CmdDispenseNew(BYTE Addr,LPBYTE pBills, bool bTypes)
{
BYTE Data[256]={SYNC,0,0,DISPENSE,0,0,0,0,0,0,0,0,0,0,0,0};
DWORD dwUnload=0;
BYTE ByteNum=23;
BYTE ArrPoint=4;
int iLastError;
if(bTypes)
{
for(int i=0;i<25;i++)
{
if (pBills[i]) { Data[ArrPoint++]=i;Data[ArrPoint++]=pBills[i]; }
}
}
else
{
for(int i=0;i<6;i+=2)
{
if((pBills[i+1]!=0xff)){Data[ArrPoint++]=pBills[i];Data[ArrPoint++]=pBills[i+1];}
}
}
Data[2]=ArrPoint+2;
CCommand cmd(Data,0);
CCommand Response=Transmit(cmd,Addr);
BYTE ack;
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 CCCRSProtocol::CmdSetBarParams function sends SET BARCODE PARAMETERS command
[param Format] a parameter of type BYTE specifiying barcode format
[param Length] a parameter of type BYTE specifiying barcode length
[param Addr] a parameter of type BYTE containing device address. Refer to \link Addr Device address list \endlink for the valid values
[return bool] - true if the command was acknowledged
*/
_CASHCODEDLL_API int _stdcall CmdSetBarParams(BYTE Format, BYTE Length, BYTE Addr)
{
BYTE Data[256]={SYNC,0,8,SET_BAR_PARAMS,
Format, Length,
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 CCCRSProtocol::CmdExtractBarData function sends EXTRACT BARCODE DATA command
[param sBar] a parameter of type LPSTR containing pointer to a zero-terminated string receiving the barcode value.
[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 response was successfully received
*/
_CASHCODEDLL_API int _stdcall CmdExtractBarData(LPSTR sBar, BYTE Addr)
{
BYTE Data[256]={SYNC,0,6,EXTRACT_BAR_DATA,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;
return iLastError;
}
strcpy(sBar,"");
for (int i=3; i<Response.GetData()[2]-2;i++)
sBar[i-3]= Response.GetData()[i];
return RE_NONE;
}
else
{
return iLastError;
}
}
/*
[brief] The CmdHold function sends HOLD command to the device
[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 CmdHold(BYTE Addr)
{
BYTE Data[256]={SYNC,0,6,HOLD,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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -