📄 machineinterface.pas
字号:
unit MachineInterFace;
interface
uses
SysUtils, Classes, Windows, DateUtils, DB;
type
TKQ_DataFormat = class(TObject)
CardNo : String;
KqDate : TDateTime;
end;
TSF_DataFormat = class(TObject) //收费机记录格式
CardNo : String; //卡号
UsedCount : Integer; //使用次数
Month : Integer; //月
Day : Integer; //日
Hour : Integer; //小时
Min : Integer; //分
RemainMoney : Extended; //余额
UsedMoney : Extended; //消费额
end;
//
TSF_InfoHead = record
SysInfoLen : WORD; //信息长度
//以下可修改收费机当前时间
Sec : Byte;
Min : Byte;
Hour : Byte;
Week : Byte;
Day : Byte;
Month : Byte;
Year : Byte;
Zero1 : Array[0..2] of Byte; //4字节的零
UnitPasswd : Array[0..2] of Byte; //单位密码3
Res : Byte;
CRC : Byte; //前7字节的检验和
//早餐
Morning_Start_Hour : Byte; //开餐时间--小时
Morning_Start_Min : Byte; //开餐时间--分钟
Morning_End_Hour : Byte; //终止时间--小时
Morning_End_Min : Byte; //终止时间--分钟
//中餐
MiddleMeal_Start_Hour : Byte;
MiddleMeal_Start_Min : Byte;
MMiddleMeal_End_Hour : Byte;
MiddleMeal_End_Min : Byte;
//晚餐
Supper_Start_Hour : Byte;
Supper_Start_Min : Byte;
Supper_End_Hour : Byte;
Supper_End_Min : Byte;
//夜餐
NightMeal_Start_Hour : Byte;
NightMeal_Start_Min : Byte;
NightMeal_End_Hour : Byte;
NightMeal_End_Min : Byte;
//深夜餐
NightMeal_Start_Hour2 : Byte;
NightMeal_Start_Min2 : Byte;
NightMeal_End_Hour2 : Byte;
NightMeal_End_Min2 : Byte;
//***********************
MachineNum : Byte; //机号数 n =1
//以下n 个7字节
MachineID : Byte; //机号
ConsumeType : Byte; //消费类别 0x01 为普通消费
Consume_Hight : Byte; //最高消费高4位
Consume_Low : Byte; //最高消费低4位
// TiptopConsume : Word; //最高消费 十进制
AllowCardType : Byte; //允许消费卡类,127
Zero3 : Array [0..1] of Byte;//两字节零
//***********************
Zero4 : Array [0..9] of Byte;//10个字节0
Zero5 : Array [0..8195] of Byte;//8K挂失信息
end;
TSF_LossInfo = record
LossInfoLen : WORD; //两字节信息长度
Zeoro : Array [0..1] Of Byte;//两字节0
//后两是挂失信息,按位表示,位为'1'表示对应的卡号被挂失
//如: 01 00 10 00 表示1号卡和24号卡被挂失
end;
TSF_InfoFormat = record
DateTime : TDateTime; //日期/时间
UnitPasswd : String; //单位密码2个字符
//早餐
Morning_Start_Hour : Byte; //开餐时间--小时
Morning_Start_Min : Byte; //开餐时间--分钟
Morning_End_Hour : Byte; //终止时间--小时
Morning_End_Min : Byte; //终止时间--分钟
//中餐
MiddleMeal_Start_Hour : Byte;
MiddleMeal_Start_Min : Byte;
MMiddleMeal_End_Hour : Byte;
MiddleMeal_End_Min : Byte;
//晚餐
Supper_Start_Hour : Byte;
Supper_Start_Min : Byte;
Supper_End_Hour : Byte;
Supper_End_Min : Byte;
//夜餐
NightMeal_Start_Hour : Byte;
NightMeal_Start_Min : Byte;
NightMeal_End_Hour : Byte;
NightMeal_End_Min : Byte;
ConsumeType : Integer; //消费类别 01-普通消费,02....
TiptopConsume : WORD; //最高消费
AllowCardType : Byte; //允许的卡类,每一位代表一类卡
HangupDataSet : TDataSet; //挂失数据源
CardNoFieldName : String; //挂失卡号字段名
end;
TCard_Format = record
CardNo : String; //卡号
UnitPasswd : String; //单位密码 (2位)
CardType : Byte; //卡类 (1,2,3...7)
CardFlag : Byte; //卡标志(02,55)
UsedCount : Integer; //使用次数
UsedDay : Integer; //使用时间 天
UsedHour : Integer; //小时
UsedMin : Integer; //分钟
Money : Extended; //卡余额
end;
var
BAUD_RATE : Integer = 115200; //通讯波特率
const
LOAD_KEY = 'FFFFFFFFFFFF'; // 12位密码
LOAD_PASSWD_MODE = 0; //加载密码的模式
//考勤机操作
//取考勤机记录数
function KQ_GetRecordCount(MachineID :Integer; Device :String) :Integer;
//取考勤列表
function KQ_GetRecordList(MachineID :Integer; Device :String;RecordList :TList):LongWord;
//修改考勤机日期与时间
function KQ_ModifyDateTime(MachineID :Integer; Device :String;DateTime :TDateTime) :Boolean;
//收费机操作
//读取收费机的记录数及总金额
function SF_GetRecordCount(MachineID :Integer; Device :String; var TotalMoney :Extended; var Count :Integer) :Boolean;
//采集收费记录
function SF_GetRecordList(MachineID :Integer; Device :String;RecordList :TList):LongWord;
//产生挂失信息串
function SF_GenHangupString(Buf : PChar; DataSet : TDataSet; FieldName : String) : Boolean;
//系统设置:修改时间,下传信息等在此函数完成
function SF_SetSystemInfo(MachineID :Integer; Device :String;SF_Info : TSF_InfoFormat) : Boolean;
//卡操作
//读物理卡号
function Card_GetCardPhyID(Device :String) : String;
//发卡
function Card_SendCard(Device :String; secnr : Integer; cfCard : TCard_Format) :Boolean;
//读卡信息
function Card_GetInfo(device :String; secnr : integer;var cfcard : Tcard_Format) :Boolean;
//加金额
function Card_IncMoney(Device :String; secnr :integer; Money : Extended) : Boolean;
//减金额
function Card_DecMoney(Device :String; secnr :integer; Money : Extended) : Boolean;
//清除金额
function Card_ClearMoney(Device :String;secnr :integer) : Boolean;
//-----------------导入DLL函数------------------------------------------------
//考勤机接口
function SendData(n1 :integer; command :PChar; n2 :integer; senddata :PChar; device :PChar) : integer; stdcall;far;external 'standcom.dll' name 'senddata';
function GetData(n1 :integer; command :PChar; n2 :integer; getdata :PChar; device :PChar) : integer; stdcall;far;external 'standcom.dll' name 'getdata';
//卡函数
{comm function.}
function rf_init(port: smallint;baud:longint): longint; stdcall;
far;external 'mwrf32.dll' name 'rf_init';
function rf_exit(icdev: longint):smallint;stdcall;
far;external 'mwrf32.dll'name 'rf_exit';
function rf_encrypt(key:pchar;ptrsource:pchar;msglen:smallint;ptrdest:pchar):smallint;stdcall;
far;external 'mwrf32.dll' name 'rf_encrypt';
//
function rf_request(icdev:longint;mode:smallint;snr:pchar):smallint;stdcall;
far;external 'mwrf32.dll'name 'rf_request';
function rf_card(icdev:longint;mode:smallint;snr:pchar):smallint;stdcall;
far;external 'mwrf32.dll'name 'rf_card';
function rf_load_key(icdev:longint;mode,secnr:smallint;nkey:pchar):smallint;stdcall;
far;external 'mwrf32.dll' name 'rf_load_key';
function rf_load_key_hex(icdev:longint;mode,secnr:smallint;nkey:pchar):smallint;stdcall;
far;external 'mwrf32.dll' name 'rf_load_key_hex';
function rf_authentication(icdev:longint;mode,secnr:smallint):smallint;stdcall;
far;external 'mwrf32.dll' name 'rf_authentication';
//
function rf_read(icdev:longint;adr:smallint;data:pchar):smallint;stdcall;
far;external 'mwrf32.dll' name 'rf_read';
function rf_read_hex(icdev:longint;adr:smallint;data:pchar):smallint;stdcall;
far;external 'mwrf32.dll' name 'rf_read_hex';
function rf_write(icdev:longint;adr:smallint;data:pchar):smallint;stdcall;
far;external 'mwrf32.dll' name 'rf_write';
function rf_write_hex(icdev:longint;adr:smallint;data:pchar):smallint;stdcall;
far;external 'mwrf32.dll' name 'rf_write_hex';
function rf_halt(icdev:longint):smallint;stdcall;
far;external 'mwrf32.dll' name 'rf_halt';
//M1 CARD
//DEVICE
function rf_beep(icdev:longint;time:smallint):smallint;stdcall;
far;external 'mwrf32.dll' name 'rf_beep';
implementation
//uses MsgBox;
function KQ_GetRecordList(MachineID: Integer; Device: String;RecordList: TList): LongWord;
var
st :LongWord;
RecordCount :Integer;
Hi,Lo : Integer;
Cmd: array[0..4] of char;
OneRecord: array[0..11] of char;
Buf: PChar;
i : Integer;
DateTime :String;
KQ_Data : TKQ_DataFormat;
No : DWORD;
begin
Result := 0;
RecordCount := KQ_GetRecordCount(MachineID,Device);
if RecordCount = 0 then exit;
GetMem(Buf,RecordCount * 12 + 2);
ZeroMemory(Buf,RecordCount * 12 + 2);
Cmd[0] := Char(MachineID);
Cmd[1] := #194;
Cmd[2] := #0;
Cmd[3] := #0;
Cmd[4] := #0;
st := GetData(4,@Cmd[0],RecordCount * 12 + 2,@Buf[0],PChar(Device));
if st = 0 then
begin
Hi := Integer(Buf[1]);
Lo := Integer(Buf[0]);
Result := (Hi shl 8) + Lo;
for i := 0 to Result -1 do
begin
KQ_Data := TKQ_DataFormat.Create;
CopyMemory(PChar(@OneRecord[0]),PChar(@Buf[2 + i * 12]),12);
{
KQ_Data.CardNo := IntToStr(Integer(OneRecord[0])) +
IntToHex(Integer(OneRecord[1]),2) +
IntToHex(Integer(OneRecord[2]),2);
}
No := Integer(OneRecord[0]) * $10000 + Integer(OneRecord[1]) * $100 + Integer(OneRecord[2]);
KQ_Data.CardNo := Trim('00000' + IntToStr(No));
KQ_Data.CardNo := Copy(KQ_Data.CardNo,Length(KQ_Data.CardNo) - 4,5);
DateTime := '20' + IntToHex(Integer(OneRecord[3]),2) + '-' +
IntToHex(Integer(OneRecord[4]),2) + '-' +
IntToHex(Integer(OneRecord[5]),2) + ' ' +
IntToHex(Integer(OneRecord[6]),2) + ':' +
IntToHex(Integer(OneRecord[7]),2);
KQ_Data.KqDate := StrToDateTime(DateTime);
RecordList.Add(KQ_Data);
end;
end else
begin
// MessageBox( '通讯出错!','','',0)
// frmMsgBox.MessageBox('通讯出错!请检查通讯线是否正确连接?','',MB_OK or MB_ICONWARNING);
end;
FreeMem(Buf);
end;
function KQ_GetRecordCount(MachineID: Integer; Device: String): Integer;
var
st :LongWord;
Hi,Lo : Integer;
Cmd: array[0..4] of char;
Buf: array[0..10] of Char;
begin
Cmd[0] := Char(MachineID);
Cmd[1] := #193;
Cmd[2] := #0;
Cmd[3] := #0;
Cmd[4] := #0;
st := GetData(4,@Cmd[0],7,@Buf[0],PChar(Device));
result := 0;
if st = 0 then
begin
Hi := Integer(Buf[2]);
Lo := Integer(Buf[1]);
Result := (Hi shl 8) + Lo;
end else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -