1.钱箱说明
钱箱使用COM4,接口方式为RJ11。
2.通信方式
采用串口通信,波特率:9600;数据位:8;校验位:无校验位;停止位:1位。
3.指令集
(1) 打开钱箱:
十六进制:1b 70 00 50 10
十进制 :27 112 0 80 16
(2)检测钱箱状态:
十六进制:1d 72 02
十进制 :29 114 2
Window下请调用客显动态库中的HSComOpenDrawer, HSComCheckDrawer,也可以自己根据以上指令写程序。
4.串口钱箱函数库及例程
#include
#include
#include
#define LSR 0x5
#define DBUF 0
const int giSDCPt = 3; //COM3
const unsigned int nPortAddress = 0x3e8;
const unsigned char Open_Command[5] = {0x1b, 0x70, 0x00, 0x50, 0x10};
const unsigned char Check_Command[3] = {0x1d, 0x72, 0x02};
void InitSCD(void); //初始化通信端口
int OpenSCD(void); //打开串口钱箱
int CheckSCD(void); //检查串口钱箱状态
char RecOneCh(void); //接收钱箱返回的状态
//函数名:InitSCD
//功能:初始化串口
//输入参数:无
//输出参数:无
void InitSCD(void)
{
bioscom(0,0xe0|0x03|0x00|0x00,giSDCPt-1); //9600,8,1,N
delay(100);
return;
}
//函数名:OpenSCD
//功能:打开串口钱箱
//输入参数:无
//输出:0
int OpenSCD(void)
{
int i;
int iWaitTime;
for(i=0; i<5; i++)
{
iWaitTime = 3000;
while(!(inportb(nPortAddress+LSR) & 0x20) && iWaitTime)
iWaitTime--;
if(iWaitTime)
outportb(nPortAddress, Open_Command[i]);
}
return 0;
}
//函数名:CheckSCD
//功能:检查串口钱箱的状态
//输入参数:无
//输出参数:钱箱状态iResult
//备注:iResult: 0:打开;1:关闭
int CheckSCD(void)
{
int i;
int iResult;
int iWaitTime;
for(i=0; i<3; i++)
{
iWaitTime = 3000;
while(!(inportb(nPortAddress+LSR) & 0x20) && iWaitTime)
iWaitTime--;
if(iWaitTime)
outportb(nPortAddress, Check_Command[i]);
}
delay(20);
iResult = RecOneCh();
iResult=iResult & 0x01;
return iResult;
}
//函数名:RecOneCh
//功能: 用读地址的方式从串口读取状态1个字符
//输入参数:无
//输出参数: 读取的字符.
char RecOneCh(void)
{
char ch=0;
unsigned int iWaitTime = 0xffff;
if (!giSDCPt)
{
return 0;
}
while( !(inportb(nPortAddress+LSR) & 0x01) && iWaitTime)
iWaitTime--;
if (iWaitTime)
{
ch = inportb(nPortAddress+DBUF);
}
return ch;
}
//主函数
int main()
{
int iSta = -1;
char ch;
printf("This is a test for the ComCashDrawer, First the \
application will open the drawer!\n");
printf("before test, please make sure that the drawer is connect with COM3!\n");
InitSCD();
printf("Please input Enter to open the Drawer\n");
ch = getchar();
if(ch == 0x0d)
{
OpenSCD();
}
printf("Now check the status of the drawer.\n");
iSta = CheckSCD();
if(iSta == 1)
printf("The Drawer is Closed.\n");
else if(iSta == 0)
printf("The Drawer is Open.\n");
else
printf("Communication Erro!\n");
return ;
}