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

📄 icdate.pas

📁 集成酒店桑拿食管管理的完整程序
💻 PAS
字号:
unit icdate;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  Tic = class(TDataModule)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ic: Tic;
  function swr_4442(icdev: longint;offset:smallint;length:smallint;data1:pchar):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'swr_4442';
  function srd_4442(icdev: longint;offset:smallint;length:smallint; data1:pchar):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'srd_4442';
  function prd_4442(icdev: longint;length:smallint;data1:pchar):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'prd_4442';
  function pwr_4442(icdev: longint;offset:smallint;length:smallint;data1:pchar):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'pwr_4442';
  function chk_4442(icdev: longint):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'chk_4442';

  function csc_4442(icdev: longint;length:smallint;password:pchar):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'csc_4442';
  function wsc_4442(icdev: longint;length:smallint; password:pchar):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'wsc_4442';
  function rsc_4442(icdev: longint;length:smallint; password:pchar):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'rsc_4442';
  function rsct_4442(icdev: longint;counter:pchar):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'rsct_4442';

  //use general function
  function ic_init(port: smallint;baud:longint): longint; stdcall;
    far;external 'MWIC_32.DLL' name 'ic_init';
  function auto_init(port: smallint;baud:longint): longint; stdcall;
    far;external 'MWIC_32.DLL' name 'auto_init';
  function ic_exit(icdev: longint):smallint;stdcall;
    far;external 'MWIC_32.dll' name 'ic_exit';
  function get_status(icdev: longint;status:pchar):smallint;stdcall;
    far;external 'MWIC_32.dll' name 'get_status';

  function cmp_dvsc(icdev:longint;length:smallint;password:pchar):smallint;stdcall;
    far;external 'MWIC_32.dll' name 'cmp_dvsc';
  function setsc_md(icdev: longint;mode:smallint):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'setsc_md';
  function srd_dvsc(icdev: longint;length:smallint;password:pchar):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'srd_dvsc'
  function swr_dvsc(icdev: longint;length:smallint;password:pchar):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'swr_dvsc';

  function turn_off(icdev: longint):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'turn_off';
  function turn_on(icdev: longint):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'turn_on';
  function auto_pull(icdev: longint):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'auto_pull';
  function srd_ver(icdev: longint;length:smallint;ver:pchar):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'srd_ver';
  function dv_beep(icdev: longint;time:smallint):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'dv_beep';

  function asc_hex(asc:pchar;hex:pchar;len:smallint):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'asc_hex';
  function hex_asc(hex:pchar;asc:pchar;len:smallint):smallint;stdcall;
    far;external 'MWIC_32.dll'name 'hex_asc';

  function ic_encrypt(key:pchar;source:pchar;len:smallint;dest:pchar):smallint;
     stdcall;far;external 'MWIC_32.dll'name 'ic_encrypt';
  function ic_decrypt(key:pchar;dest:pchar;len:smallint;source:pchar):smallint;
     stdcall;far;external 'MWIC_32.dll'name 'ic_decrypt';
  Function CT_message(ret:integer):string;
  Function key(kh:string):string;

  function read_ic:string;
  function new_ic(ickh,bkkh,cz,xf:string):string;
  function w_ic(kh,cz,xf:string):string;
  Function open_com(dk:string):smallint;
  Function CT_close(icdev:smallint):smallint;

implementation

{$R *.DFM}
Function CT_message(ret:integer):string;
begin
   if ret=-1 then  CT_message:='调用参数错。';
   if ret=0  then CT_message:='函数调用成功。';
   if ret=128 then CT_message:='读错误';
   if ret=129 then CT_message:='写错误';
   if ret=130 then CT_message:='命令错误';
   if ret=131 then CT_message:='密码错误';
   if ret=132 then CT_message:='超时错误';
   if ret=133 then CT_message:='测卡错误';
   if ret=134 then CT_message:='无卡错误';
   if ret=135 then CT_message:='超值错误';
   if ret=136 then CT_message:='通讯错误';
   if ret=137 then CT_message:='卡型错误';
   if ret=138 then CT_message:='校验和错误';

   if ret=140 then CT_message:='非法拔卡';
   if ret=141 then CT_message:='通用错误';
   if ret=142 then CT_message:='命令头错误';
   if ret=144 then CT_message:='地址错误';
   if ret=145 then CT_message:='长度错误';
   if ret=149 then CT_message:='串口占用';
end;

Function key(kh:string):string;
var ls_str,ls_key:string;ls,i,ls_y:integer;
begin
  ls:=0;
  for i:=1 to length(kh) do
    ls:=ls+ord(kh[i]);
  ls_str:=inttostr(ls);
   while trim(ls_str)<>'' do
  begin
    ls:=strtoint(copy(ls_str,1,2));
    if ls>=33 then
    begin
      ls:=strtoint(copy(ls_str,1,1));
      ls_str:=trim(copy(ls_str,2,length(ls_str)));
    end
    else
      ls_str:=trim(copy(ls_str,3,length(ls_str)));
    ls_y:=1;
    for i:=1 to 3 do
      ls_y:=ls_y*ls;
    ls_y:=ls_y mod 33;
    ls_key:=ls_key+inttostr(ls_y);
  end;
  if length(ls_key)>=6 then
    key:=copy(ls_key,length(ls_key)-5,6)
  else
    key:=copy('00000'+ls_key,length(ls_key),6);
end;

Function open_com(dk:string):smallint;
var nResult,i:smallint;
begin
  if dk<>'' then
  begin
    nResult:=auto_init(strtoint(copy(dk,4,1))-1,9600); //初始化串口一,并将读写器波特率设为9600
  end
  else
  begin
    nResult:=0;
    for i:=0 to 3 do
    begin
      if nResult<=0 then
       nResult:= auto_init(i,9600);
    end;
  end;
  if nResult<=0 then
  begin
     open_com:=0;
     exit;
  end;
  open_com:=nResult;
end;

Function CT_close(icdev:smallint):smallint;
begin
  CT_close:=ic_exit(icdev);
end;

function w_ic(kh,cz,xf:string):string;
var k,st:integer;rece:pchar;
   ls:string;
begin
   ls:='';
   k:=open_com('');
   if k=0 then
   begin
     w_ic:='端口没有打开!';
     exit;
   end;
   rece:=stralloc(128);
   st:=chk_4442(k);               //检测是否4442卡
   if st<>0 then
   begin
      w_ic:='卡错误!';
      CT_close(k);
      exit;
   end;
   st:=srd_4442(k,8,12,rece);
   if st<>0 then
   begin
     w_ic:=CT_message(st);
     CT_close(k);
     exit;
   end;
   if COPY(StrPas(rece),9,4)<>'超微' then
   begin
     w_ic:='      此卡不是本系统卡!'+#13+#13+'请立即停止用非法卡对系统的侵害,'+#13+'    否则将由你承担一切后果!!';
     CT_close(k);
     exit;
   end;
  // ls:=key(COPY(StrPas(rece),1,8));
   ls:=COPY(StrPas(rece),1,8);
   st:=srd_4442(k,30,10,rece);
   if st<>0 then
   begin
     w_ic:=CT_message(st);
     CT_close(k);
     exit;
   end;
   if trim(COPY(StrPas(rece),1,10))<>kh then
   begin
     w_ic:='此卡卡号不正确!';
     CT_close(k);
     exit;
   end;
  st:=csc_4442(k,3,chr($27)+chr($17)+chr($31));
  //<><><>m<><><><><><><>
 //  st:=csc_4442(k,3,pchar(ls));
   if st<>0 then
   begin
     w_ic:='系统卡检测:'+#13+'      '+CT_message(st);
     CT_close(k);
     exit;
   end;
   st:=swr_4442(k,40,20,pchar(copy(cz+'          ',1,10)+copy(xf+'          ',1,10)));
   if st<>0 then
   begin
     w_ic:='写数据错误:'+#13+'      '+CT_message(st);
     CT_close(k);
     exit;
   end;
   w_ic:='ok';
   CT_close(k);
end;

function read_ic:string;
var k,st:integer;rece:pchar;
   ls,kh:string;
begin
   ls:='';kh:='';
   k:=open_com('');
   if k=0 then
   begin
     read_ic:='端口没有打开!';
     exit;
   end;
   rece:=stralloc(128);
   st:=chk_4442(k);               //检测是否4442卡
   if st<>0 then
   begin
      read_ic:='卡错误!';
      CT_close(k);
      exit;
   end;
   st:=srd_4442(k,8,12,rece);
   if st<>0 then
   begin
     read_ic:=CT_message(st);
     CT_close(k);
     exit;
   end;
   if COPY(StrPas(rece),9,4)<>'超微' then
   begin
     read_ic:='      此卡不是本系统卡!'+#13+#13+'请立即停止用非法卡对系统的侵害,'+#13+'    否则将由你承担一切后果!!';
     CT_close(k);
     exit;
   end;
   kh:=COPY(StrPas(rece),1,8);
  // kh:=COPY(StrPas(rece),1,8);
  // ls:=key(kh);
   ls:=kh;
  //<><><><><>
   st:=csc_4442(k,3,chr($27)+chr($17)+chr($31));
  // st:=csc_4442(k,3,pchar(ls));
   if st<>0 then
   begin
     read_ic:='系统卡检测:'+#13+'      '+CT_message(st);;
     CT_close(k);
     exit;
   end;
   st:=srd_4442(k,30,30,rece);
   if st<>0 then
   begin
     read_ic:=CT_message(st);
     CT_close(k);
     exit;
   end;
   read_ic:='ok'+kh+COPY(StrPas(rece),1,30);
   CT_close(k);
end;

function new_ic(ickh,bkkh,cz,xf:string):string;
var k:integer;rece:pchar;st:word;
   ls:string; bSecret:array[0..2] of char;
begin
   ls:='';
   k:=open_com('');
   if k=0 then
   begin
     new_ic:='端口没有打开!';
     exit;
   end;
   rece:=stralloc(10);
   st:=chk_4442(k);               //检测是否4442卡
   if st<>0 then
   begin
      new_ic:='卡错误!';
      CT_close(k);
      exit;
   end;
   st:=srd_4442(k,8,12,rece);
   if st<>0 then
   begin
     new_ic:=CT_message(st);
     CT_close(k);
     exit;
   end;
   ls:=StrPas(rece);
   if COPY(ls,9,4)='超微' then
   begin
    // ls:=key(COPY(StrPas(rece),1,8));
     ls:=COPY(StrPas(rece),1,8);
   //  ls:=key(COPY(StrPas(rece),1,8));
{     bSecret[0]:=strtoint('$'+copy(ls,1,2));
     bSecret[1]:=strtoint('$'+copy(ls,3,2));
     bSecret[2]:=strtoint('$'+copy(ls,5,2));  }
   end
   else
   begin
     new_ic:='      此卡不是本系统卡!'+#13+#13+'请立即停止用非法卡对系统的侵害,'+#13+'    否则将由你承担一切后果!!';
     CT_close(k);
     exit;
     ls:='ffffff';
//     bSecret[0]:=$ff;bSecret[1]:=$ff;bSecret[2]:=$ff;
   end;
   {bSecret[0]:=chr(strtoint('$'+copy(ls,1,2)));
   bSecret[1]:=chr(strtoint('$'+copy(ls,3,2)));
   bSecret[2]:=chr(strtoint('$'+copy(ls,5,2)));}
 //  st:=csc_4442(k,3,pchar(ls));chr($27)+chr($17)+chr($31)
   st:=csc_4442(k,3,chr($27)+chr($17)+chr($31));
   if st<>0 then
   begin
     new_ic:=CT_message(st);
     CT_close(k);
     exit;
   end;
  { ls:=key(COPY(ickh+'        ',1,8));
   bSecret[0]:=chr(strtoint('$'+copy(ls,1,2)));
   bSecret[1]:=chr(strtoint('$'+copy(ls,3,2)));
   bSecret[2]:=chr(strtoint('$'+copy(ls,5,2))); }
  // st:=wsc_4442(k,3,bSecret);//chr(strtoint('$'+copy(ls,1,2)))+chr(strtoint('$'+copy(ls,3,2)))+chr(strtoint('$'+copy(ls,5,2))));
   st:=wsc_4442(k,3,chr($27)+chr($17)+chr($31));//chr(strtoint('$'+copy(ls,1,2)))+chr(strtoint('$'+copy(ls,3,2)))+chr(strtoint('$'+copy(ls,5,2))));
 ////  nResult:=wsc_4442(fd,3,chr($27)+chr($17)+chr($31));  ///
   if st<>0 then
   begin
     new_ic:=CT_message(st);
     CT_close(k);
     exit;
   end;
   st:=swr_4442(k,8,12,pchar(copy(ickh+'          ',1,8)+'超微'));
   if st<>0 then
   begin
     new_ic:=CT_message(st);
     CT_close(k);
     exit;
   end;
   st:=swr_4442(k,30,30,pchar(copy(bkkh+'          ',1,10)+copy(cz+'          ',1,10)+copy(xf+'          ',1,10)));
   if st<>0 then
   begin
     new_ic:=CT_message(st);
     CT_close(k);
     exit;
   end;
   new_ic:='ok';
   CT_close(k);
end;


end.

⌨️ 快捷键说明

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