我要做一个自动控制系统的软件,需要访问一个采集卡的端口(220H+4),在turbo c语言里用 inportb()和outputb(),而在delphi里是那个函数?
我查了一下在turbo pascal利用的是port[]专用数组访问端口,如 port[$220+4]:=30;
即把30送到220H+4端口。可是在delphi里,编译说是potr未定义,看来不能用!
如果没有的话,我只好嵌入汇编了。可是有些麻烦,需要A/D, D/A转换。哪位知道?救我!

解决方案 »

  1.   

    function PortIn(IOport:word):byte; assembler;
    asm
      mov dx,ax
      in al,dx
    end;function PortInW(IOport:word):word; assembler;
    asm
      mov dx,ax
      in ax,dx
    end;procedure PortOut(IOport:word; Value:byte); assembler;
    asm
      xchg ax,dx
      out dx,al
    end;procedure PortOutW(IOport:word; Value:word); assembler;
    asm
      xchg ax,dx
      out dx,ax
    end;
      

  2.   

    unit wInOut;interfaceuses
      SysUtils;//向端口写一个字节
    function OutP32(const PortAddress:SmallInt;const Value:Byte):Boolean;
    function InP32(const PortAddress:SmallInt):Byte;implementationfunction OutP32(const PortAddress:SmallInt;const Value:Byte):Boolean;
    begin
      Asm
        push dx
        mov dx,PortAddress
        mov al,Value
        out dx,al
        pop dx
      End;
      Result:=True;
    end;function InP32(const PortAddress:SmallInt):Byte;
    begin
      Asm
        push dx
        mov dx,PortAddress
        in al,dx
        mov Result,al
        pop dx
      End;
    end;
    end.
      

  3.   

    还要用汇编?
    那还不如用C或者是汇编整来的快。有没有其它方法?比如把端口设备看成文件,读写文件(就像linux下面的一样)
      

  4.   

    有没有搞错?你在Windows NT/2000下用In或者Out指令试试看?要是这样就行了还要Driver干什么?
      

  5.   

    谢谢各位的热心,我当天回去就搞定了。
    无奈,还是最后嵌入了汇编,用汇编实现了采集、A/D、D/A、和OUT
    做得挺成功,其他人用C还没做出来。
    就是时间太紧张,本来给了一星期,由于大家有事,所以耽误了三天,无奈只好用三天做了。
      

  6.   

    感谢wks的热心询问和帮助,我用的汇编语句和你的差不多,不过在delphi里,
    把变量定义为integer,要放入eax,放入ax时,编译说是不匹配。
      

  7.   

    可以用MSCOMM控件实现呀,挺简单的。