📄 ko.dpr
字号:
AReadCardData^.SaleDL :=strtoint(copy(temp,11,6)); //购电量
//AReadCardData^.Sale_Num :=strtoint(copy(temp,17,4)); //购电次数
AReadCardData^.Sale_Num_M :=strtoint(copy(temp,17,4));
exit;
end;
129:begin //售电返写卡
password_old:=copy(goudianqu,1,8); //原密码
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;
end; // case语句结束
end;
result:=-302;//卡不匹配
{end;}//ckflag
except
result:=-311 ;//异常07-1-13加的
end;
finally
ic_exit(icdev); //释放串口
end;
end;
//***********************写卡操作***********************************************
function Write_Card(AHandle :THandle; APort :LongInt; AWriteCardData :PWriteCardData) :LongInt; stdcall;
var
str_card_num,str_meter_const,str_card_power,str_sale_num,str_Alarm_Power,
str_Max_FCharge,str_Max_TjPower,str_Max_OverPower,str_tz_state,str_cx_state,
str_sq_state,str_password_old,str_password_new,str_run_state,str_user_id,
temp,jymstr,jym,datastr1,datastr2:string;
hexdata:array[0..127] of char;
offset,i,k:integer;
st1:smallint;
ckflag,ckflag1:smallint;
dllname:string;
hdll:THANDLE;
wt: Twt_Card;
retval:integer;
begin
try //1-13加
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_card (icdev);//4-19去掉的
//if ckflag=1 then //4-19去掉的
ckflag:=chk_24c01a (icdev); //4-19加上去的
ckflag1:=chk_4442 (icdev); //4-19加上去的
if ckflag=0 then //4-19加上去的
begin
{try} //1-13号改写
str_password_old:='12345678'; //固定12345678
str_password_new:='12345678'; //固定12345678
str_run_state:='00'; //固定为00
str_card_num:='';str_user_id:='';
for I := 0 to 9 do str_card_num:=str_card_num+AWriteCardData^.Comm_ID[i]; //通讯号取前面10位
for I := 2 to 11 do str_user_id:=str_user_id+AWriteCardData^.User_ID[i]; //总户号取后面10位
str_meter_const:=rightstr('000000'+inttostr(AWriteCardData^.Meter_Const),6); //表常数
str_card_power:=rightstr('000000'+floattostr(AWriteCardData^.SaleDL),6); //卡内电量
str_sale_num:=rightstr('0000'+inttostr(AWriteCardData^.Sale_Num),4); //购电次数
str_Alarm_Power:=rightstr('000000'+inttostr(AWriteCardData^.WarnDL1),6); //报警电量
str_Max_FCharge:=rightstr('000000'+floattostr(AWriteCardData^.Max_Load),6); //最大负荷
str_Max_TjPower:=rightstr('000000'+inttostr(AWriteCardData^.Max_HoardDL),6); //囤积门限
str_Max_OverPower:=rightstr('000000'+inttostr(AWriteCardData^.Max_OverDL),6); //赊欠门限
if AWriteCardData^.TZ_State =true then str_tz_state:='11' else str_tz_state:='00'; //跳闸控制字
str_cx_state:='11'; //常显控制子
if AWriteCardData^.SQ_State =true then str_sq_state:='11' else str_sq_state:='00'; //赊欠控制字
case AWriteCardData^.Card_ID of //
2: begin
//************************开户卡***************************************************//
// 开户AWriteCardData^传入DLL的记录共有11项,其中10项写入卡中,卡型代码做判断标识 //
// 写入卡的数据为19项,其中9项在DLL程序里已赋值,再加上应用程序传入的10项 //
// 新密码,旧密码,电量状态字已在DLL固定 //
// 剩余电量,累计购电量已在DLL中自动赋值(等于开户电量) //
// 累计用电量,过零电量已在DLL中自动赋值(等于0) //
// 购电次数已在DLL中自动赋值(等于1) //
// 常显状态字11 //
//*********************************************************************************//
clear_Card(icdev);
datastr1:=str_card_num+str_Alarm_Power+str_meter_const+str_Max_FCharge
+str_Max_OverPower+str_Max_TjPower+str_tz_state+str_cx_state
+str_sq_state+str_card_power+'0001'+str_card_power
+str_card_power+'000000'+'000000'+str_run_state+str_user_id; //数据域(17项)
jymstr:='012E'+datastr1; //加总户号后数据长度要加5
jym:=getjym(jymstr); //计算校验和
datastr2:=data_decrypt(str_password_new,datastr1); //加密(包括总户号)
temp:=str_password_old+str_password_new+'68012E'+datastr2+jym+'16'; // 加总户号后数据长度要加5 ,68012E
offset:=0; //写入地址
end;
3,4: begin //售电卡
//**********************购电卡(电量无效),补卡************************************************
// 购电AWriteCardData^传入DLL的记录共有5项,其中4项写入卡中,卡型代码做判断标识 //
// 写入卡的数据为4项总户号,通讯号,够电量,够电次数 // //
//*********************************************************************************//
clear_Card(icdev);
datastr1:=str_card_num+str_card_power+str_sale_num+str_user_id; //数据域
jymstr:='020F'+datastr1;
jym:=getjym(jymstr); //计算校验和
datastr2:=data_decrypt(str_password_new,datastr1); //加密
temp:=str_password_old+str_password_new+'68020F'+datastr2+jym+'16';
offset:=0; //写入地址
end;
end; // case语句结束
k:=length(temp) div 2;
hexdata:='';
st1:=asc_hex(pchar(temp),hexdata,k) ; //转换成ASC
if st1=0 then
begin
result:=swr_24c01a(icdev,offset,k,hexdata);
exit;
end
else
begin
result:=st1;
exit;
end;
{finally
ic_exit(icdev);//1-13号改写
end;}
end;
//if ckflag=21 then //4-19去掉的
if ckflag1=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
@wt := GetProcAddress(hdll, 'Write_Card');
if @wt = nil then
begin
//messagebox(handle,'DLL加载函数失败','',64);
result:=-304;
exit;
end;
if @wt <> nil then
begin
if AWriteCardData.WarnDL1>9999 then
begin
result:=-306;
exit;
end;
if AWriteCardData.Max_OverDL >9999 then
begin
result:=-307;
exit;
end;
if AWriteCardData.Max_HoardDL >999999 then
begin
result:=-308;
exit;
end;
if AWriteCardData.Max_Load >99.99 then
begin
result:=-309;
exit;
end;
if AWriteCardData.SaleDL >99999.9 then
begin
result:=-310;
exit;
end;
//retval := wt(ahandle, aport, AWriteCardData); //1-13号改写
result:=wt(ahandle, aport, AWriteCardData); //1-13号改写
//result:=retval; //1-13号改写
//icdev:=auto_init(APort-1,9600); //4-19去掉的
icdev:=auto_init(APort-1,115200); //4-19加上的
exit;
end;
end;
end;
result:=-305; //此卡不是24c01a,SLE4442卡
except
result:=-312;//07-1-13加异常
end;
finally
ic_exit(icdev);//1-13加
end;
end;
exports
Write_Card,Read_Card,Clear_Card,GetErrorMsg,Read_Card_All;
begin
end.
{1-13改写的主要是try except finally,还有北川读写完函数直接赋值result
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -