📄 ko.dpr
字号:
library KO;
uses
SysUtils,strutils,windows;
{$R *.res}
type
//写卡数据结构
PWriteCardData = ^TWriteCardData;
TWriteCardData = record
Work_ID :LongInt; //厂商代码(最大2位十进制数字)
Prog_ID :LongInt; //表型代码(最大2位十进制数字)
Card_ID :LongInt; //卡型代码(最大2位十进制数字)
User_ID :array[0..12] of char; //用户号(最大12位十进制数字)
Comm_ID :array[0..12] of char; //通讯号,卡号(最大12位十进制数字)
Office_ID :LongInt; //各供电局的地区代码(非常关键,必须写)
Far_ID :LongInt; //远抄表号。
Meter_Const :LongInt; //表常数
WarnDL1 :LongInt; //一级报警电量(金额)
WarnDL2 :LongInt; //二级报警电量(金额)
Max_HoardDL :LongInt; //最大囤积电量(金额)
Max_OverDL :LongInt; //最大透支电量(金额)
Max_Load :Double; //最大负荷(千瓦)
PTCT :LongInt; //倍率
CBDay :LongInt; //抄表日期
XLDTSJ :LongInt; //需量递推时间
Loadwarndelay :LongInt; //超负荷报警延时
Price_J :Double; //尖电价
Price_F :Double; //峰电价
Price_P :Double; //平电价
Price_G :Double; //谷电价
SaleDL :Double; //购电量(金额)
Sale_Num :LongInt; //购电次数(购电次数从1起)
TimeSegs :array[0..1024] of char; //时段参数
CycleDisplay :array[0..1024] of char; //显示参数
CBFlag: BOOL;//插表标识,TRUE->插表,false->没有插表 (必须返回)
//以下是扩展部分
TZ_State:bool; //跳闸状态字
CX_State:bool; //常显状态字
SQ_State:bool; //赊欠状态字
end;
//读卡数据结构
type
PReadCardData = ^TReadCardData;
TReadCardData = record
//以下标识数据项不管插没插表都必须返回
Work_ID :LongInt; //厂商代码(最大2位十进制数字)
Prog_ID :LongInt; //表型代码(最大2位十进制数字)
Card_ID :LongInt; //卡型代码(最大2位十进制数字)
User_ID :array[0..12] of char; //用户号(最大12位十进制数字)
Comm_ID :array[0..12] of char; //通讯号,卡号(最大12位十进制数字)
Office_ID :LongInt; //各供电局的地区代码(非常关键,必须写)
//如果没有插表,返回以下参数数据
Far_ID :LongInt; //远抄表号。
Meter_Const :LongInt; //表常数
WarnDL1 :LongInt; //一级报警电量(金额)
WarnDL2 :LongInt; //二级报警电量(金额)
Max_HoardDL :LongInt; //最大囤积电量(金额)
Max_OverDL :LongInt; //最大透支电量(金额)
Max_Load :Double; //最大负荷(千瓦)
PTCT :LongInt; //倍率
CBDay :LongInt; //抄表日期
XLDTSJ :LongInt; //需量递推时间
Loadwarndelay :LongInt; //超负荷报警延时
Price_J :Double; //尖电价
Price_F :Double; //峰电价
Price_P :Double; //平电价
Price_G :Double; //谷电价
SaleDL :Double; //购电量(金额)
Sale_Num :LongInt; //购电次数(购电次数从1起)
//如果插表,返回以下抄表数据
OverZeroDL_M :Double; //过零电量
RemainDL_M :Double; //剩余电量;
Sale_Num_M :LongInt; //表内购电次数(购电次数从1起)。
Power_Z_M :Double; //总用电量
Power_J_M :Double; //尖用电量
Power_F_M :Double; //峰用电量
Power_P_M :Double; //平用电量
Power_G_M :Double; //谷用电量
Read_Year_M :LongInt; //抄表年
Read_Mon_M :LongInt; //抄表月
Read_Day_M :LongInt; //抄表日
Read_Hour_M :LongInt; //抄表时
Read_Minute_M :LongInt; //抄表分
Read_Second_M :LongInt; //抄表秒
CBFlag: BOOL;//插表标识,TRUE->插表,false->没有插表 (必须返回)
//以下是扩展部分
//Acc_Salepower:Double;//累计购电量(和浩宁达商量去掉)
TZ_State:bool; //跳闸状态字
CX_State:bool; //常显状态字
SQ_State:bool; //赊欠状态字
end;
TWt_Card = function(AHandle :THandle; APort :LongInt; AWriteCardData :PWriteCardData) :LongInt; stdcall;
TRd_Card = function (AHandle :THandle; APort :LongInt; AReadCardData :PReadCardData) :LongInt; stdcall;
function swr_24c01a(icdev: longint;offset:smallint;length:smallint;data1:pchar):smallint;stdcall;
far;external 'MWIC_32.dll'name 'swr_24c01a';
function srd_24c01a(icdev: longint;offset:smallint;length:smallint;data1:pchar):smallint;stdcall;
far;external 'MWIC_32.dll'name 'srd_24c01a';
function auto_init(port: smallint;baud:longint): longint;stdcall;
far;external 'MWIC_32.DLL' name 'auto_init';
function ic_init(port: smallint;baud:longint): longint; stdcall;
far;external 'MWIC_32.DLL' name 'ic_init';
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_exit(icdev:longint): smallint;stdcall;
far;external 'MWIC_32.DLL' name 'ic_exit';
//4-19去掉的
{function chk_card(icdev:longint):smallint;stdcall;
far;external 'MWIC_32.dll' name 'chk_card'; }
//4-19加上去的
function chk_4442(icdev: longint):smallint;stdcall;
far;external 'MWIC_32.dll'name 'chk_4442';
function chk_24c01a(icdev: longint):smallint;stdcall;
far;external 'MWIC_32.dll'name 'chk_24c01a';
var
icdev:longint;
st:smallint;
//取错误信息
{procedure GetErrorMsg(AErrorCode :LongInt; var AMsg :PChar); stdcall;}
procedure GetErrorMsg(AErrorCode :LongInt; AMsg :PChar); stdcall;
begin
{ case AErrorCode of
-128: AMsg:='读错误';
-129: AMsg:='写错误'; //串口未打开,直接进行读卡写卡操作
-130: AMsg:='命令错误';
-131: AMsg:='密码错误';
-132: AMsg:='超时错误';
-133: AMsg:='测卡错误';
-134: AMsg:='无卡错误';
-135: AMsg:='超值错误';
-136: AMsg:='通讯错误';
-137: AMsg:='卡型错误';
-138: AMsg:='校验和错误';
-140: AMsg:='非法拔卡';
-141: AMsg:='通用错误'; //没连读卡器,打开串口
-142: AMsg:='命令头错误';
-144: AMsg:='地址错误';
-145: AMsg:='长度错误';
-149: AMsg:='串口被占用';
-202: AMsg:='校验和错误';
-203: AMsg:='长度错误';
-205: AMsg:='操作码错误';
-206: AMsg:='校验位错误';
-207: AMsg:='超时错误';
else AMsg:='未知错误'
end }
case AErrorCode of
-128: strcopy(AMsg,'读错误');
-129: strcopy(AMsg,'写错误'); //串口未打开,直接进行读卡写卡操作
-130: strcopy(AMsg,'命令错误');
-131: strcopy(AMsg,'密码错误');
-132: strcopy(AMsg,'超时错误');
-133: strcopy(AMsg,'测卡错误');
-134: strcopy(AMsg,'无卡错误');
-135: strcopy(AMsg,'超值错误');
-136: strcopy(AMsg,'通讯错误');
-137: strcopy(AMsg,'卡型错误');
-138: strcopy(AMsg,'校验和错误');
-140: strcopy(AMsg,'非法拔卡');
-141: strcopy(AMsg,'通用错误'); //没连读卡器,打开串口
-142: strcopy(AMsg,'命令头错误');
-144: strcopy(AMsg,'地址错误');
-145: strcopy(AMsg,'长度错误');
-149: strcopy(AMsg,'串口被占用');
-202: strcopy(AMsg,'校验和错误');
-203: strcopy(AMsg,'长度错误');
-205: strcopy(AMsg,'操作码错误');
-206: strcopy(AMsg,'校验位错误');
-207: strcopy(AMsg,'超时错误');
1:strcopy(AMsg,'写卡时通讯出错');
2:strcopy(AMsg,'写卡时写卡器中无卡');
3:strcopy(AMsg,'写卡时写卡器中卡型不匹配');
4:strcopy(AMsg,'写卡时初始化加密卡出错');
5:strcopy(AMsg,'写卡时写卡器中不是新卡');
6:strcopy(AMsg,'读卡时通讯出错');
7:strcopy(AMsg,'读卡时读卡器中无卡');
8:strcopy(AMsg,'读卡时读卡器中卡型不匹配');
9:strcopy(AMsg,'读卡时读卡器中是新卡');
10:strcopy(AMsg,'读卡时读卡出错');
11:strcopy(AMsg,'读卡时读卡器中非本局用卡');
12:strcopy(AMsg,'读卡时读卡器中未知卡');
13:strcopy(AMsg,'写卡失败');
14:strcopy(AMsg,'新卡,不用清卡');
15:strcopy(AMsg,'清卡时通讯出错');
16:strcopy(AMsg,'管理系统启动卡,不用清卡');
17:strcopy(AMsg,'清卡出错');
18:strcopy(AMsg,'清卡时初始化密码出错');
98:strcopy(AMsg,'串口打开失败');
99:strcopy(AMsg,'串口关闭失败');
-301: strcopy(AMsg,'串口打开失败');
-302: strcopy(AMsg,'卡类型不匹配');
-303: strcopy(AMsg,'KOB.DLL加载失败');
-304: strcopy(AMsg,'KOB.DLL加载函数失败');
-305: strcopy(AMsg,'此卡不是24c01a,SLE4442卡');
-306: strcopy(AMsg,'报警电量不能超过9999');
-307: strcopy(AMsg,'最大赊欠不能超过9999');
-308: strcopy(AMsg,'囤积电量不能超过999999');
-309: strcopy(AMsg,'最大负荷不能超过99.99');
-310: strcopy(AMsg,'购电量不能超过99999.9');
-311: strcopy(AMsg,'读卡异常');
-312: strcopy(AMsg,'写卡异常');
else strcopy(AMsg,'未知错误')
end // case语句结束
end;
//计算校验码
function getjym(hexstr:string):string;
var len,k,i:integer;
begin
len:=length(hexstr) div 2;
k:=0;
for I := 1 to len do k:=k+strtoint('$'+copy(hexstr,2*i-1,2));
result:=inttohex(k mod 256,2);
end;
//读出卡中所有地址 (返回十六进制字符串) hexstr_card(256)大于255,故加sharemem
function Read_Card_All(AHandle:THandle;var hexstr_card:string):longint;stdcall;
var
st1,st:smallint;
recdata:array[0..127] of char;
hexdata:array[0..255] of char;
begin
hexstr_card:='';
st:=srd_24c01a(AHandle,0,128,recdata); //从卡地址0向后读取128个字节
if st=0 then
begin
st1:=hex_asc(recdata,hexdata,128);
if st1=0 then
begin
result:=0;
hexstr_card:=hexdata;
exit;
end
else
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -