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

📄 ko.dpr

📁 预付费表读卡写卡程序 使用明华的读卡器
💻 DPR
📖 第 1 页 / 共 4 页
字号:
                password_new:=copy(goudianqu,9,8);                              //新密码

                temp:=data_decrypt(password_new,copy(fanxiequ,7,36));           //解密数据域
                temp1:=data_decrypt(password_new,copy(goudianqu,23,92));        //解密购电区(找出购电次数)
                readstr:=goudianqu+copy(fanxiequ,1,6)+temp+copy(fanxiequ,43,4)
                +copy(fanxiequ,47,82);                                          //解密后卡中所有数据

                //AReadCardData^.ReadStred :=readstr;                             //解密后卡中所有数据

                //*******************以下为标准数据项***************************
                if card_id=129 then AReadCardData^.Card_ID :=3;                 //卡型代码

                AReadCardData^.CBFlag :=true;                                   //插表标识,已插表
                tempstr:=copy(temp,27,10);
                //tempstr:='00'+rightstr('0000000000'+tempstr,10);
                for I := 0 to 9 do AReadCardData^.Comm_ID[i]:=tempstr[i+1];    //通讯号(最大10位十进制数字)
                AReadCardData^.Comm_ID [10]:=#0;
                AReadCardData^.Comm_ID [11]:=#0;
                AReadCardData^.Comm_ID [12]:=#0;

                AReadCardData^.OverZeroDL_M :=strtoint(copy(temp,19,6));        //过零电量
                AReadCardData^.RemainDL_M :=strtoint(copy(temp,1,6));           //剩余电量
                AReadCardData^.Power_Z_M :=strtoint(copy(temp,13,6));           //总用电量(累计用电量)
                //AReadCardData^.Acc_Salepower :=strtoint(copy(temp,7,6));        //累计购电量

                if copy(goudianqu,19,2)='01' then
                  begin
                    //AReadCardData^.Sale_Num:=1;                                 //查看购电区的数据,如果是控制码是01那就是刚开户然后插表
                    AReadCardData^.Sale_Num_M :=1;
                    tempstr:=copy(temp1,83,10);                                 //购点次数
                    tempstr:='00'+rightstr('0000000000'+tempstr,10);
                    for I := 0 to 11 do AReadCardData^.User_ID[i]:=tempstr[i+1]; //用户号(最大12位十进制数字)
                    AReadCardData^.User_ID[12]:=#0;
                  end;
                  
                if copy(goudianqu,19,2)='02' then
                  begin
                    //AReadCardData^.Sale_Num:=strtoint(copy(temp1,17,4));        //如果控制码是02,是售电卡插表后
                    AReadCardData^.Sale_Num_M:=strtoint(copy(temp1,17,4));
                    tempstr:=copy(temp1,21,10);                                 //购点次数
                    tempstr:='00'+rightstr('0000000000'+tempstr,10);
                    for I := 0 to 11 do AReadCardData^.User_ID[i]:=tempstr[i+1];//用户号(最大12位十进制数字)
                    AReadCardData^.User_ID[12]:=#0;
                  end;
                exit;;
            end;
        else result:=-302;  //非普通售电卡
        end;
                                                                            // case语句结束
      end;
//**********************88
  finally
    ic_exit(icdev);
  end;

  end;//chk_card=1,24c01
//*************************

//*********北川的卡****************************
if ckflag=21 then
begin
  ic_exit(icdev);
  dllname := 'KOB.dll'; //dll路径
  hdll := LoadLibrary(PChar(dllname));//dll加载

  if hdll=0 then
  begin
    //messagebox(handle,'DLL加载失败','',64);
    result:=-303;
    exit;
  end;
  if hdll <> 0 then
  begin
    @rd := GetProcAddress(hdll, 'Read_Card');
    if @rd = nil then
    begin
      //messagebox(handle,'DLL加载函数失败','',64);
      result:=-304;
      exit;
    end;
    if @rd <> nil then
    begin
      retval := rd(ahandle, aport, AReadCardData);
      result:=retval;

      exit;
    end;
  end;
end;
result:=-305; //此卡不是24c01a,SLE4442卡

end;
}


//***********************读卡操作*****************************************
function Read_Card(AHandle :THandle; APort :LongInt; AReadCardData :PReadCardData) :LongInt; stdcall;
var
  bz:longint;
  temp,temp1,readstr,temp_readstr,password_old,password_new,
  goudianqu,fanxiequ,tempstr:string;
  card_id,temp_card_id,i:integer;
  ckflag,ckflag1:integer;
  dllname:string;
  hdll:THANDLE;
  rd: TRd_Card;
  retval:integer;
begin
  try
   try  //1-13加异常
    //icdev:=auto_init(APort-1,9600); //4-19号去掉的                            //串口不判断是否成功打开,反正下面读卡时有错误标识符返回
    icdev:=auto_init(APort-1,115200); //4-19号加上去的
    if icdev<0 then
    begin
      result:=-301;
      exit;
    end;

      ckflag:=chk_24c01a (icdev); //4-19加上去的
      ckflag1:=chk_4442 (icdev); //4-19加上去的
      if ckflag1=0 then  //4-19加上去的

     // bz:=check_card(icdev,temp_readstr,temp_card_id); //4-19去掉的                         //temp_readstr为卡中所有数据未解密,检测卡
     // if bz<>0 then                                    //4-19去掉的                         //如果检测卡失败
        begin
          ic_exit(icdev);
          dllname := 'KOB.dll'; //dll路径
          hdll := LoadLibrary(PChar(dllname));//dll加载

          if hdll=0 then
          begin
          //messagebox(handle,'DLL加载失败','',64);
            result:=-303;
            exit;
          end;
          if hdll <> 0 then
          begin
            @rd := GetProcAddress(hdll, 'Read_Card');
            if @rd = nil then
            begin
            //messagebox(handle,'DLL加载函数失败','',64);
              result:=-304;
              exit;
            end;
         if @rd <> nil then
         begin
           //retval := rd(ahandle, aport, AReadCardData); //1-13号改写
           result:=rd(ahandle, aport, AReadCardData);  //1-13号改写
           //result:=retval;                          //1-13号改写
           retval :=result ;                          //1-13号改写
           if retval=0 then
           begin
             if areadCardData.CBFlag =false then
               areadCardData.Sale_Num_M :=areadCardData.Sale_Num ;
           end;
           //icdev:=auto_init(APort-1,9600); //4-19去掉的
           icdev:=auto_init(APort-1,115200); //4-19加上去的
           exit;
         end;
       end;

          //result:=bz;                                                                    //函数返回检测卡结果,见函数check_card
          exit;                                                                 //退出程序
        end;

      //if bz=0 then   //4-19去掉的                                                           //如果检测卡成功
      if ckflag=0 then  //4-19加上去的
      begin
        bz:=check_card(icdev,temp_readstr,temp_card_id);//4-19加上去的
        result:=0;                                                              //函数返回为0
        readstr:=temp_readstr;                                                  //readstr为卡中所有数据(未解密)
        AReadCardData^.Work_ID :=7;                                             //厂商代码,我公司为"7"
        AReadCardData^.Prog_ID :=13;                                            //取DTSY2078最后1位"78"
        //AReadCardData^.ReadStr:=temp_readstr;                                   //卡中所有数据(未解密)
        //AReadCardData^.ReadStred:=temp_readstr;                                 //卡中所有数据(解密)
        goudianqu:=copy(temp_readstr,1,128);                                    //购电区所有数据
        fanxiequ:=copy(temp_readstr,129,128);                                   //返写区所有数据
        card_id:=temp_card_id;                                                  //卡类型(命令码)

        case card_id of
               1:begin                                                          //开户卡
                   password_old:=copy(goudianqu,1,8);                           //原密码
                   password_new:=copy(goudianqu,9,8);                           //新密码

                   temp:=data_decrypt(password_new,copy(goudianqu,23,92));      //解密数据域
                   readstr:=copy(goudianqu,1,22)+temp+copy(goudianqu,115,4)
                   +copy(goudianqu,119,10)+fanxiequ;                            //解密后卡中所有数据

                   //AReadCardData^.ReadStred :=readstr;                          //解密后卡中所有数据

                   //*******************以下为标准数据项************************
                   if card_id=1 then AReadCardData^.Card_ID :=2;
                   if card_id=4 then AReadCardData^.Card_ID :=8;
                   if card_id=11 then AReadCardData^.Card_ID :=12;              //卡型代码(最大2位十进制数字)

                   AReadCardData^.CBFlag :=false;                               //插表标识,未插表
                   tempstr:=copy(temp,83,10);
                   tempstr:='00'+rightstr('0000000000'+tempstr,10);
                   for I := 0 to 11 do AReadCardData^.User_ID[i]:=tempstr[i+1]; //用户号(最大12位十进制数字) 事实上卡欧表只用10位,取后面10位
                   AReadCardData^.User_ID[12]:=#0;

                   tempstr:=copy(temp,1,10);
                   //tempstr:=rightstr('000000000000'+tempstr,12);
                   for I := 0 to 9 do AReadCardData^.Comm_ID[i]:=tempstr[i+1]; //通讯号(最大12位十进制数字) 事实上卡欧表只用10位,取前面10位
                   AReadCardData^.Comm_ID [10]:=#0;
                   AReadCardData^.Comm_ID [11]:=#0;
                   AReadCardData^.Comm_ID [12]:=#0;

                   AReadCardData^.Meter_Const :=strtoint(copy(temp,17,6));      //表常数
                   AReadCardData^.WarnDL1 :=strtoint(copy(temp,11,6));          //报警电量
                   AReadCardData^.Max_HoardDL :=strtoint(copy(temp,35,6));      //囤积门限
                   AReadCardData^.Max_OverDL :=strtoint(copy(temp,29,6));       //赊欠门限
                   AReadCardData^.Max_Load :=strtoint(copy(temp,23,6));         //最大负荷(千瓦)
                   AReadCardData^.SaleDL :=strtoint(copy(temp,47,6));           //购电量
                   //AReadCardData^.Sale_Num :=strtoint(copy(temp,53,4));         //购电次数
                   AReadCardData^.Sale_Num_M :=strtoint(copy(temp,53,4));
                   AReadCardData^.OverZeroDL_M :=strtoint(copy(temp,75,6));     //过零电量
                   AReadCardData^.RemainDL_M :=strtoint(copy(temp,57,6));       //剩余电量
                   AReadCardData^.Power_Z_M :=strtoint(copy(temp,69,6));        //总用电量(累计用电量)

                   //************以下为扩展部分*********************************
                   if copy(temp,41,2)='11' then AReadCardData^.TZ_State:=true
                   else AReadCardData^.TZ_State:=false;                         //跳闸状态字 00:允许跳闸  11:禁止跳闸
                   AReadCardData^.CX_State:=true;                               //常显状态字 00:常显 11:不常显
                   if copy(temp,45,2)='11' then AReadCardData^.SQ_State:=true
                   else AReadCardData^.SQ_State:=false;                         //赊欠状态字 00:允许赊欠 11:禁止赊欠
                   //AReadCardData^.Acc_Salepower :=strtoint(copy(temp,63,6));    //累计购电量

                   exit;
                 end;

               2:begin                                                          //售电卡(电量有效)
                   password_old:=copy(goudianqu,1,8);                           //原密码
                   password_new:=copy(goudianqu,9,8);                           //新密码

                   temp:=data_decrypt(password_new,copy(goudianqu,23,30));      //解密数据域                    
                   readstr:=copy(goudianqu,1,22)+temp+copy(readstr,53,4)
                   +copy(goudianqu,57,72)+fanxiequ;                             //解密后卡中所有数据

                   //AReadCardData^.ReadStred :=readstr;                          //解密后卡中所有数据
                   
                   //*******************以下为标准数据项************************
                   if card_id=2 then AReadCardData^.Card_ID :=5;
                   if card_id=6 then AReadCardData^.Card_ID :=4;
                   if card_id=12 then AReadCardData^.Card_ID :=4;               //卡型代码(最大2位十进制数字)

                   AReadCardData^.CBFlag :=false;                               //插表标识,未插表
                   tempstr:=copy(TEMP,21,10);
                   tempstr:='00'+rightstr('0000000000'+tempstr,10);
                   for I := 0 to 11 do AReadCardData^.User_ID[i]:=tempstr[i+1]; //用户号(最大12位十进制数字)
                   AReadCardData^.User_ID[12]:=#0;

                   tempstr:=copy(temp,1,10);
                   //tempstr:=rightstr('000000000000'+tempstr,12);
                   for I := 0 to 9 do AReadCardData^.Comm_ID[i]:=tempstr[i+1]; //通讯号(最大12位十进制数字)
                   AReadCardData^.Comm_ID [10]:=#0;
                   AReadCardData^.Comm_ID [11]:=#0;
                   AReadCardData^.Comm_ID [12]:=#0;

⌨️ 快捷键说明

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