📄 machineinterface.pas
字号:
begin
// frmMsgBox.MessageBox('通讯出错!请检查通讯线是否正确连接?','',MB_OK or MB_ICONWARNING);
Result := -1;
end;
end;
function KQ_ModifyDateTime(MachineID: Integer; Device: String;DateTime: TDateTime): Boolean;
var
Cmd: array[0..4] of char;
Buf: array[0..10] of Char;
Year,Month,Day,Week : Word;
Hour,Min,Sec,MSec :Word;
begin
Week := DayOfWeek(DateTime) - 1;
if Week = 0 then Week := 7;
DecodeDate(DateTime,Year,Month,Day);
DecodeTime(DateTime,Hour,Min,Sec,MSec);
Cmd[0] := Char(MachineID);
Cmd[1] := #197;
Cmd[2] := #0;
Cmd[3] := #0;
ZeroMemory(PChar(@Buf[0]),10);
Buf[0] := char(StrToIntDef('$' + IntToStr(Sec),0));
Buf[1] := char(StrToIntDef('$' + IntToStr(Min),0));
Buf[2] := char(StrToIntDef('$' + IntToStr(Hour),0));
Buf[3] := char(StrToIntDef('$' + IntToStr(Week),0));
Buf[4] := char(StrToIntDef('$' + IntToStr(Day),0));
Buf[5] := char(StrToIntDef('$' + IntToStr(Month),0));
Buf[6] := char(StrToIntDef('$' + IntToStr(Year - 2000),0));
if ( senddata(4,@Cmd[0],10,@Buf[0],PChar(Device)) = 0) then
begin
Result := True
end else
begin
// showmessage('通讯出错!请检查通讯线是否正确连接?')
// frmMsgBox.MessageBox('通讯出错!请检查通讯线是否正确连接?','',MB_OK or MB_ICONWARNING);
Result := False;
end;
end;
function SF_GetRecordCount(MachineID :Integer; Device :String; var TotalMoney :Extended; var Count :Integer) :Boolean;
var
Cmd: array[0..4] of char;
Buf: array[0..10] of Char;
st :LongWord;
Hi,Lo : Integer;
s :String;
begin
Result := False;
TotalMoney := 0;
Count := 0;
Cmd[0] := Char(MachineID);
Cmd[1] := #161;
Cmd[2] := #0;
Cmd[3] := #0;
ZeroMemory(PChar(@Buf[0]),10);
st := GetData(4,@Cmd[0],7,@Buf[0],PChar(Device));
if st = 0 then
begin
Hi := Integer(Buf[2]);
Lo := Integer(Buf[1]);
Count := (Hi shl 8) + Lo;
s := IntToHex(Integer(Buf[6]),2) + IntToHex(Integer(Buf[5]),2) + IntToHex(Integer(Buf[4]),2) + '.' + IntToHex(Integer(Buf[3]),2);
TotalMoney := StrToFloat(s);
Result := True;
end;
end;
function SF_GetRecordList(MachineID :Integer; Device :String;RecordList :TList):LongWord;
var
st :LongWord;
Cmd: array[0..4] of char;
Rec: array[0..11] of char;
Buf: PChar;
Hi,Lo : Integer;
RecordCount : Integer;
TotalMoney :Extended;
SF_Data : TSF_DataFormat;
i : Integer;
begin
Result := 0;
Cmd[0] := Char(MachineID);
Cmd[1] := #162;
Cmd[2] := #0;
Cmd[3] := #0;
SF_GetRecordCount(MachineID,Device,TotalMoney,RecordCount);
if RecordCount = 0 then exit;
GetMem(Buf,RecordCount * 12 + 2);
ZeroMemory(Buf,RecordCount * 12 + 2);
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]);
RecordCount := (Hi shl 8) + Lo;
for i := 0 to RecordCount-1 do
begin
CopyMemory(PChar(@Rec[0]),PChar(@Buf[2 + i * 12]),12);
SF_Data := TSF_DataFormat.Create;
//卡号
Hi := Integer(Rec[1]); Lo := Integer(Rec[2]);
SF_Data.CardNo := '00000' + IntToStr((Hi shl 8 ) + Lo);
SF_Data.CardNo := Copy(SF_Data.CardNo,Length(SF_Data.CardNo) - 4,5);
//使用次数
Hi := Integer(Rec[3]); Lo := Integer(Rec[4]);
SF_Data.UsedCount := (Hi shl 8) + Lo;
//卡上余额
SF_Data.RemainMoney := (Integer(Rec[7]) shl 16) + (Integer(Rec[6]) shl 8) + Integer(Rec[5]);
SF_Data.RemainMoney := SF_Data.RemainMoney / 100;
//销费
SF_Data.UsedMoney := (Integer(Rec[8]) shl 8) + Integer(Rec[9]);
SF_Data.UsedMoney := SF_Data.UsedMoney / 100;
//月
SF_Data.Month := Integer(Rec[0]) shr 4;
//日
SF_Data.Day := (Integer(Rec[10]) shr 3) and $1f;
//时
SF_Data.Hour:= ((Integer(Rec[10]) and $07) shl 2) + ((Integer(Rec[11]) and $C0) shr 6);
//分
SF_Data.Min := (Integer(Rec[11]) and $3F);
RecordList.Add(SF_Data);
end;
end;
FreeMem(Buf);
Result := RecordCount;
end;
function SF_GenHangupString(Buf : PChar; DataSet : TDataSet; FieldName : String) : Boolean;
var
Index : Integer;
CardNo : Integer;
nBit : Integer;
ch : Integer;
st :LongWord;
SQL : String;
begin
Result := False;
if (DataSet = nil) Or (FieldName = '') then exit;
//取得最大的卡号
if DataSet.Active = False then
begin
DataSet.Open;
end;
if DataSet.RecordCount = 0 then exit;
//生成挂失信息
DataSet.First;
while not DataSet.Eof do
begin
try
CardNo := StrToInt(Trim(DataSet.FieldByName(FieldName).AsString));
Index := CardNo div 8;
nBit := CardNo mod 8;
if nBit = 0 then
nBit := 8
else nBit := nBit - 1;
ch := Integer(Buf[Index]); //得到当前值
ch := ch or ($01 shl nBit); //加上挂失位
Buf[Index] := Char(ch);
except
//有错误
end;
DataSet.Next;
end;
Result := True;
end;
function SF_SetSystemInfo(MachineID :Integer; Device :String;SF_Info : TSF_InfoFormat) : Boolean;
var
st :LongWord;
Cmd: array[0..4] of char;
Year,Month,Day,Week,Hour,Min,Sec,mSec : Word;
InfoHead :TSF_InfoHead;
HangupLen : Integer;
nLow,nHight : Integer;
begin
Result := False;
ZeroMemory(@InfoHead,Sizeof(InfoHead));
InfoHead.SysInfoLen := 53;//Sizeof(InfoHead) - 9;
Week := DayOfWeek(SF_Info.DateTime) - 1;
DecodeDateTime(SF_Info.DateTime,Year,Month,Day,Hour,Min,Sec,mSec);
Year := Year - 2000;
InfoHead.Sec := (Sec div 10) * 16 + Sec mod 10;
InfoHead.Min := (Min div 10) * 16 + Min mod 10;
InfoHead.Hour := (Hour div 10) * 16 + Hour mod 10;
InfoHead.Day := (Day div 10) * 16 + Day mod 10;
InfoHead.Week := (Week div 10) * 16 + Week mod 10;
InfoHead.Month:= (Month div 10) * 16 + Month mod 10;
InfoHead.Year := (Year div 10) * 16 + Year mod 10;
InfoHead.UnitPasswd[0] := 0;
InfoHead.UnitPasswd[1] := (Ord(SF_Info.UnitPasswd[1])- Ord('0')) * 16 + Ord(SF_Info.UnitPasswd[2])- Ord('0');
InfoHead.UnitPasswd[2] := (Ord(SF_Info.UnitPasswd[3])- Ord('0')) * 16 + Ord(SF_Info.UnitPasswd[4])- Ord('0');
//135,117,123,1
InfoHead.Zero1[0] := 135;
InfoHead.Zero1[1] := 117;
InfoHead.Zero1[2] := 123;
InfoHead.Res := 1;
ZeroMemory(@InfoHead.Zero3,2);
ZeroMemory(@InfoHead.Zero4,14);
InfoHead.CRC := InfoHead.UnitPasswd[0] + InfoHead.UnitPasswd[1] + InfoHead.UnitPasswd[2] +
InfoHead.Zero1[0] + InfoHead.Zero1[1] + InfoHead.Zero1[2] + InfoHead.Res;
nLow := SF_Info.TiptopConsume - (SF_Info.TiptopConsume div 100) * 100;
nHight := SF_Info.TiptopConsume div 100;
InfoHead.Consume_Low := (nLow div 10) * 16 + nLow mod 10;
InfoHead.Consume_Hight := (nHight div 10) * 16 + nHight mod 10;
InfoHead.MachineNum := 1; //机号总数
InfoHead.MachineID := MachineID; //机号
InfoHead.ConsumeType := $01; //消费类别
InfoHead.AllowCardType := 1;
if SF_Info.AllowCardType > 7 then SF_Info.AllowCardType := 0;//
InfoHead.AllowCardType := (1 shl SF_Info.AllowCardType);
InfoHead.AllowCardType := 127;//允许卡类
//处理挂失
HangupLen := 8192; //挂
ZeroMemory(@InfoHead.Zero5,8192 + 4);//挂失信息长度+2字节长度信息+2字节空
InfoHead.Zero5[0] := HangupLen And $ff;
InfoHead.Zero5[1] := (HangupLen shr 8) And $ff;
//生成挂失内容
SF_GenHangupString(@InfoHead.Zero5[4],SF_Info.HangupDataSet,SF_Info.CardNoFieldName);
Cmd[0] := Char(MachineID);
Cmd[1] := #165;
Cmd[2] := #0;
Cmd[3] := #0;
Cmd[4] := #0;
st := senddata(4,@Cmd[0],59 + HangupLen,@InfoHead,PChar(Device));
if ( st = 0) then Result := True;
end;
function Card_SendCard(Device :String; secnr :Integer; cfCard : TCard_Format) :Boolean;
var
S :String;
Buf : array[0..32] of char;
strTemp : String;
iCardNo :Integer;
Year,Month,Day,Hour,Min ,Sec,mSec:Word; //使用时间
Byte1OfDate,Byte2OfDate : Byte;
st :LongWord;
snr : LongInt;
ICdev: LongInt;
Port :Integer;
i :Integer;
begin
Result := False;
if Device = 'COM1' Then
Port := 0
else Port := 1;
ICDev := rf_init(Port,BAUD_RATE); //串口1 波特率115200
if ICDev <= 0 then
begin
// showmessage('通讯出错!请检查通讯线是否正确连接?')
// frmMsgBox.MessageBox('串口初始化出错!','',MB_OK or MB_ICONWARNING);
exit;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -