我想时间获取考勤机的刷卡的卡号(但在点击时出错,不知道是怎么回事)unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,Lanben;type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    pclk: PClockInfo;
    function OpenPort(pclk: PClockInfo; BroadCast: Boolean=False): THandle;
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var
  R: Boolean;
  card_buf: array[0..50]of char;
begin
   pclk.clock_id:=1;
   pclk.hport:=1;
   pclk.BaudRate:=19200;
   pclk.Clock_Type:=0;
   pclk.RunMode:=pclk.Clock_Type;
   pclk.icid:=false;
   pclk.hPort := OpenPort(pclk);
   if pclk.hPort=0 then Exit;
   R:=ReadCardNo(1, @card_buf, 0);
    if not R then Exit;
    try
      while true do
      begin
        RealReadCardNo(1, @card_buf, 10);
        if length(trim(card_buf))>8 then
           Caption:= card_buf;
      end;
    finally
    end;
end;function TForm1.OpenPort(pclk: PClockInfo; BroadCast: Boolean): THandle;
begin
  Result := OpenCommPort(pclk.hport, 9600);
  pclk.RunMode:=CallClock(Result, pclk.clock_id, BroadCast);
end;end.

解决方案 »

  1.   

    下面是调用的接口,厂方提供{*Lanben 智能卡函数库 Delphi 声明单元*}unit Lanben;interface
    uses
      Windows, SysUtils;const
      SOK            = 'OK';
      SERROR         = 'ERROR';
      SOVER          = 'OVER';
      Lanben_API     = 'Lanben10.dll';//     自定义通信错误常量
      ERROR_IO_CHECK=$00000001; //校验错误
      ERROR_IO_READ=$00000002; //读错误
      ERROR_IO_WRITE=$00000003; //写错误
      ERROR_IO_NOEND=$00000004; //串口接收未结束而中断
      ERROR_IO_NOPEN=$00000005; //不能打开端口
      ERROR_IO_COMMAND=$00000006; //命令错误
      ERROR_IO_NOHANDLE=$00000007; //无句柄错误
      ERROR_IO_TIMEOUT=$00000008; //通讯超时type
      PClockInfo = ^TClockInfo;
      TClockInfo = record
        hPort: THandle;
        clock_id: Byte;
        Ver: string;
        ICID: BOOL;
        Fireware: Double;
        RunMode: Integer;
        Port, BaudRate, SelType, Model, Clock_Type: integer;
        Block, CmdVerify, Connected, bSelected: Boolean;
      end;{设备联接类}//    打开端口及联接设备
    function ConnectClock(Port, BaudRate: Integer; ClockNo: Byte; BroadCast: Boolean=False): THandle; stdcall; external lanben_API
    //    Port       : 端口号, COM1=1, COM2=2;
    //    BaudRate   : 波特率, 一般为9600
    //    ClockNo    : 为机号, 范围0-252
    //    BroadCast  : 为开始群发功能, 不接收返回状态
    //    说明       : 返回值为端口句柄, 当返回-1时表示端口无效或是被占用, 返回0时代表无法联机//    断开联接及关闭端口
    function DisConnectClock(hPort: THandle): Boolean; stdcall; external Lanben_API
    //    此函数和ConnectClock 对应//    检查指定的机器是否在联机状态
    function CheckConnectClock(hPort: THandle; ClockNo: Byte; BroadCast: Boolean=False): Byte; stdcall; external Lanben_API
    //    ClockNo    : 为机号, 0-252
    //    BroadCast  : 为开始群发功能, 不接收返回状态
    //    说明       : 返回机器运行模式, 只能是下列值
    //      Return=0 联接不成功
    //      Return=1 考勤机, Return=2考勤门禁机, Return=3门禁机, Return=4份饭机//    联接指定的机器
    function CallClock(hPort: THandle; ClockNo: Byte; BroadCast: Boolean=False): Byte; stdcall; external Lanben_API
    //    ClockNo    : 为机号, 0-252
    //    BroadCast  : 为开始群发功能, 不接收返回状态
    //    说明       : 返回机器运行模式, 只能是下列值
    //      Return=0 联接不成功
    //      Return=1 考勤机, Return=2考勤门禁机, Return=3门禁机, Return=4份饭机//   取消联接机器
    function UnCallClock(hPort: THandle): Boolean; stdcall; external Lanben_API//    查询指定机号是否在线
    function TestCallClock(hPort: THandle; ClockNo: Byte; ATimeOut: Integer=0): Byte; stdcall; external Lanben_API
    //    ClockNo    : 为机号, 0-252
    //    ATimeOut   : 响应超时
    //    说明       : 返回机器运行模式, 只能是下列值
    //      Return=0 联接不成功
    //      Return=1 考勤机, Return=2考勤门禁机, Return=3门禁机, Return=4份饭机//    机器复位
    function ResetClock(hPort: THandle): Boolean;stdcall; external Lanben_API
    //    将卡钟复位到出厂状态,复位会清除所有数据和下载名单//    读设备型号参数
    function GetClockParam(hPort: THandle; var Model: Integer; var Fireware: Double; var ICID: BOOL): Boolean; stdcall; external Lanben_API
    //    自动识别机器型号, 一般在联机后马上调用以使DLL识别型号//    手动设置型号参数
    function SetClockParam(hPort: THandle; Model: Integer; Fireware: Double; ICID: BOOL): Boolean; stdcall; external Lanben_API
    //    手动设置机器型号, 自动识别机型失败时调用//    修改设备通信速率
    function SetClockBaudRate(hPort: THandle; BaudRate: DWORD): Boolean; stdcall; external Lanben_API
    //    BaudRate    : 波特率, 初始值为9600, 可以有以下值:
    //      9600, 19200, 38400//    设置端口超时时间
    function SetPortTimeOut(Value: Integer): Boolean; stdcall; external Lanben_API
    //    Value       : 超时值, 毫秒为单位, 默认为1000毫秒,//    设置IC卡读写卡操作的超时时间
    function SetPortRWCardTimeOut(hPort: THandle; Value: Integer): Boolean; stdcall; external Lanben_API
    //    Value       : 超时值, 毫秒为单位, 默认为30000毫秒,
      

  2.   

    {设备联接类}
    {版本控制类}
    //    取得库版本字串
    function GetDLLVersion(Version: PChar): Boolean; stdcall; external Lanben_API//    取得机器下层软件版本号
    function GetClockSoftwareVersion(hPort: THandle; Version: PChar): Boolean;stdcall; external Lanben_API
    //    说明       : Version 缓冲区长度要大於30个字符以上//    取得设备版本字串
    function GetClockVersion(hPort: THandle; Version: PChar): Boolean; stdcall; external Lanben_API
    //    说明       : Version 缓冲区长度要大於30个字符以上//    修改设备版本字符串(ER-980)
    function SetClockVersion(hPort: THandle; Version: PChar): Boolean; stdcall; external Lanben_API
    //    说明       : Version  新的版本字符串,替换版本字符串可重置部分//    取得设备序列号
    function ReadClockSerialNo(hPort: THandle; SerialNo: PChar): Boolean; stdcall; external Lanben_API//    设置设备序列号
    function SetClockSerialNo(hPort: THandle; SerialNo: PChar): Boolean; stdcall; external Lanben_API{版本控制类}{设备管理普通类}
    //    设置刷卡时显示卡号还是工号
    function SetupDisplayNumberType(hPort: THandle; Kind: Integer): Boolean;stdcall; external Lanben_API
    //    Kind       : 显示类型
    //      Kind=0   : 显示卡号
    //      Kind=1   : 显示工号function SetupBlackCardAttenType(hPort: THandle; Kind: Integer): Boolean;stdcall;  external Lanben_API
    //    Kind       : 黑名单报警类型
    //      Kind=0   :  蜂鸣器报警
    //      Kind=1   : 外界报警器报警function SetupBushCardType(hPort: THandle; Kind: Integer): Boolean;stdcall; external Lanben_API
    //    Kind       : 刷卡类型
    //      Kind=0   : 注册模式
    //      Kind=1   : 注册模式//    设置背景灯
    function SetupBackLight(hPort: THandle; Kind: Integer; TimeZone: PChar): Boolean;stdcall; external Lanben_API
    //    Kind       : 显示类型
    //      Kind=0   : 背景灯常闭
    //      Kind=1   : 背景灯常开
    //      Kind=2   : 背景灯在指定的时间内亮
    //    TimeZone   : 背景打开时段, 格式为 hhnnhhnn...
    //    说明       : 可群发//    设置打卡间隔
    function SetupBrushCardInterval(hPort: THandle; SameCardInterval: Integer; DifferCardInterval: Integer): Boolean;stdcall; external Lanben_API
    //    SameCardInterval: 重复刷卡间隔(0-99分)
    //    DifferCardInterval: 不同卡(最小有效刷卡间隔0-10秒)
    //    说明       : 可群发//    设置考勤刷卡时段(最多5段)
    function SetupBrushPeriods(hPort: THandle; Periods: PChar): Boolean;stdcall; external Lanben_API
    //    Periods    : 考勤可刷卡时段, 以hhnnhhnn(小时分钟小时分钟)形式顺序排列//    设置打铃时间(最多32个)
    function SetupHornTimes(hPort: THandle; HornTimes: PChar): Boolean;stdcall; external Lanben_API
    //    HornTimes  : 打铃时间串, 格式(hhnnddhhnndd...)最多32个
    //    hh         : 打铃时间小时
    //    nn         : 打铃时间分钟
    //    dd         : 打铃持续时间(01--99)//    设置门禁开门时间(最多8段)
    function SetupGuardPeriods(hPort: THandle; GuardPeriods: PChar): Boolean;stdcall; external Lanben_API
    //    GuardPeriods: 门禁开门时段串, 格式(hhnnhhnn...)最多8段
    //    hh         : 小时
    //    nn         : 分钟//    设置允许消费时段(4段)
    function SetupConsumptionPeriods(hPort: THandle; ConPeriods: PChar): Boolean;stdcall; external Lanben_API
    //    ConPeriods : 门禁开门时段串, 格式(hhnnhhnn...)最多4段
    //    hh         : 小时
    //    nn         : 分钟//    打铃设置(可群发)
    function SetupHornType(hPort: THandle; Value: Integer): Boolean;stdcall; external Lanben_API
    //    Value      : 打铃设置, 可为下列值
    //      Value=0    : 无铃声
    //      Value=1    : 蜂鸣器打铃
    //      Value=2    : 继电器1外接电铃
    //      Value=3    : 继电器2外接电铃//    定义外设接口定义(可群发)
    function SetupExternalPort(hPort: THandle; Value1,Value2,Value3: Integer): Boolean;stdcall; external Lanben_API
    //    Value      : 外设定义, 可为下列值
    //      Value=0    : 继电器外接电铃
    //      Value=1    : 继电器外接电锁//    设置通告消息
    function SetNotification(hPort: THandle; Kind: Integer; TimeZone: PChar; Notication: PChar; Company: PChar): Boolean;stdcall; external Lanben_API
    //    Kind       : 消息类型, Kind=0时显示公司名, Kind=1时显示通告消息
    //    TimeZone   : 消息显示时段, 共两段, 格式: hhnnhhnnhhnnhhnn
    //    Notication : 通告消息, 最多128个字节
    //    Company    : 显示公司名称, 最多72个字节//    设置机器编号及运行模式
    function SetClockID(hPort: THandle; ClockID: Byte; RunMode: Integer=0): Boolean; stdcall; external Lanben_API
    //    ClockID    : 新机号
    //    RunMode    : 新设备运行模式(参见CallClock返回值)//    取得设备编号
    function GetClockID(Port, BaudRate: Integer;var ClockID: Byte): Boolean; stdcall; external Lanben_API
    //    ClockID    : 返回机号//    设置设备标志字符
    function SetClockMark(hPort: THandle; Mark: Char): Boolean; stdcall; external Lanben_API
    //    说明: 字符显示屏的机型只可以使用十进制数字function ReadClockMark(hPort: THandle; var Mark: Char): Boolean; stdcall; external Lanben_API//    设置设备管理卡
    function SetManagerCard(hPort: THandle; CardNo: PChar): Boolean; stdcall; external Lanben_API
    //    CardNo     : 卡号//    读设备管理卡号码
    function ReadManagerCard(hPort: THandle; CardNo: PChar): Boolean; stdcall; external Lanben_API
    //    CardNo     : 返回管理卡号码, 缓冲区需大於11字节长度//    读取设备时间
    function ReadClockTime(hPort: THandle; var CurTime: Double): Boolean; stdcall; external Lanben_API//    设置设备时间
    function SetClockTime(hPort: THandle; SetTime: Double): Boolean; stdcall; external Lanben_API//    下载字库文件
    function DownLoadFontLib(hPort: THandle; lpData: PChar; Size: Integer): Boolean; stdcall; external Lanben_API
    //    lpData     : 字库数据指针
    //    Size       : 字库字节数量//    下载1页字库(16字节)
    function DownLoadFontPage(hPort: THandle; lpData: PChar; Size: Integer=16; First: Boolean=False; Finish: Boolean=False): Boolean; stdcall; external Lanben_API
    //    lpData     : 字库数据指针
    //    Size       : 字节数, 只能是16字节
    //    First      : 下载开始
    //    Finish     : 下载结束{设备管理普通类}
      

  3.   

    厂家也应该给你提供简单的Demo吧?
      

  4.   

    一般的硬件,有提供接口,而且一般你想操作,都先得初始化
    比如说先初始化端口(com口或者USB口)。你看看有没有这些初始化函数
      

  5.   

    我写的一个读取时间的例子,如下:procedure TForm1.Button1Click(Sender: TObject);
    var
      hPort:THandle;
      COMID:THandle;
      CCID:Byte;
      CurTime:double;
      ret:Byte;
      TryTimes:integer;
      IsOK:boolean;
    begin
      COMID:=strtoint(edit1.text);
      CCID:=strtoint(edit2.text);  hport:=ConnectClock(comid,9600,ccid);
      if hport>0 then
      begin
        sleep(1000);
        ret:=CallClock(hport,ccid);
        sleep(1000);
        if ret>0 then
        begin 
          curtime:=0;
          TryTimes:=5;
          IsOK:=false;      repeat
            IsOK:=ReadClockTime(hport,curtime);
            dec(TryTimes);
          until (IsOK)or(TryTimes<=0);      if IsOK then
          begin
            showmessage('读取到的时间为: '+floattostr(curtime));
          end
          else
            showmessage('读取时间失败!');    end
        else
          showmessage('联机失败!');    DisConnectClock(hport);
      end
      else
        showmessage('打开串口失败!'); 
    end;
    但是一直读不成功!