GB-IP功能无法正常工作 [英] GB-IP Function not working correctly

查看:116
本文介绍了GB-IP功能无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的PC上有一个GP-IB卡,它通过GP-IB连接到DMM。我在卡上运行了诊断程序,并确认它可以正常工作。我能够控制它并在那里进行软件测试。现在,我正在尝试创建一个程序来执行此操作,但是当它发送命令时,它总是在DMM上显示错误。

I have a GP-IB card in my PC connected to a DMM via GP-IB. I have ran diagnostician on the card and confirms it is working. I am able to control it threw there software test. Now I am trying to create a program to do it, but when it sends the command it always gives error on DMM.

我在master中有3个源文件Master.pas,SubClass.pas和ApiGpib.pas

I have 3 source files Master.pas, SubClass.pas, and ApiGpib.pas

PAS我有这个发送命令到设备。

In master.pas I have this to send a command to the device.

var
Ret                : DWORD;                           
Yradr               : DWORD;                  
Srlen               : DWORD;               
Cmd                 : array[0..31] of DWORD;        
csBuf               : String;   



 /Sending a command to the device////////////////////////////////////////////////
procedure TFormMaster1.ButtonSENDClick(Sender: TObject);
var
    srBuffer: String;                                       // command
    SendBuf: PChar;
begin  
    Yradr := StrToInt(YRADRBox.Text);                  //card address
    srBuffer := EditSENDDATA.Text;
    Srlen := Length(srBuffer);                             // Length of text
    SendBuf := PChar(srBuffer);                            // change string to Pchar 
    if Srlen <> $0 then                                    //string no empty
    begin                              // Send a command
        EditTEXTRET.Text := 'Waiting for return???';
        Refresh();                                        

        Cmd[0] := 2;                       // Number of equipment to talk to
        Cmd[1] := Myadr;                   // My device address
        Cmd[2] := Yradr;                   // Card address
        Ret := GpTalk(@Cmd, Srlen, SendBuf);           // Sends address's, length, text
        CheckRet('GpTalk', (Ret and $FF), csBuf);      // return value up to 255 length
        EditTEXTRET.Text := csBuf;                     // Return text
    end
    else
        EditTEXTRET.Text := 'No text to send';

end;

现在在ApiGpib.pas中,我具有像这样的GpTalk功能。

Now in ApiGpib.pas I have the functions GpTalk like so.

type
   PDWORD=^DWORD
   function  GpTalk(Cmd:PDWORD; Srlen:DWORD; Srbuf:PChar):DWORD;stdcall;
   ...
   ...
   ...
Implementation
   function  GpTalk;              external 'ApiGpib1.dll' ;

在DMM上会出错,我无法查看ApiGpib1.dll。

It will error out here on DMM, I cant view the ApiGpib1.dll.


  • 问题是

    +您是否发现逻辑有误?

    +什么我可以尝试对为什么它不起作用进行故障排除吗?

最后,只是在CheckRet函数中添加了某些内容。在Subclass.pas中,我有这个。

Last of all just incase its something in the CheckRet function. In Subclass.pas I have this.

type
function CheckRet(Func:String;Ret:DWORD;var csBuf:string):DWORD;

Implementation
function CheckRet(Func: String; Ret: DWORD; var csBuf: String):DWORD;
var
    RetCode,Ret1: DWORD;
begin
    RetCode := 0;                          
    Ret1 := Ret and $ff;                      
    if Ret1 >= 3 then
    begin                                  
        RetCode := 1;                          
        case Ret1 of
            3:   csBuf := Func + ' : FIFO"à‚É‚Ü‚¾ƒf[ƒ^‚ªŽc‚Á‚Ä‚¢‚Ü‚·B';
            80:  csBuf := Func + ' : I/OƒAƒhƒŒƒXƒGƒ‰[‚Å‚·B';
            82:  csBuf := Func + ' : ƒŒƒWƒXƒgƒŠÝ’è‚̃Gƒ‰[‚Å‚·BConfig.exe‚ÅŠm"F‚µ‚Ä‚­‚¾‚³‚¢B';
            128: csBuf := Func + ' : ŽóMƒoƒbƒtƒ@‚ð’´‚¦‚½A‚Ü‚½‚ÍSRQ‚ðŽóM‚µ‚Ä‚¢‚Ü‚¹‚ñB';
            200: csBuf := Func + ' : ƒXƒŒƒbƒh‚ªì¬‚Å‚«‚Ü‚¹‚ñB';
            201: csBuf := Func + ' : ‘¼‚̃Cƒxƒ"ƒgŠÖ"‚ªŽÀs’†‚Å‚·B';
            210: csBuf := Func + ' : DMA‚ªÝ’è‚Å‚«‚Ü‚¹‚ñ‚Å‚µ‚½B';
            240: csBuf := Func + ' : EscƒL[‚ª‰Ÿ‚³‚ê‚Ü‚µ‚½B';
            241: csBuf := Func + ' : ƒtƒ@ƒCƒ‹"üo—̓Gƒ‰[‚Å‚·B';
            242: csBuf := Func + ' : ƒAƒhƒŒƒXŽw’肪ŠÔˆá‚Á‚Ä‚¢‚Ü‚·B';
            245: csBuf := Func + ' : ƒoƒbƒtƒ@‚ª¬‚³‚·‚¬‚Ü‚·';
            246: csBuf := Func + ' : •s³‚ȃIƒuƒWƒFƒNƒg–¼‚Å‚·B';
            247: csBuf := Func + ' : ƒfƒoƒCƒX–¼‚̉¡‚̃`ƒFƒbƒN‚ª–³Œø‚Å‚·B';
            248: csBuf := Func + ' : •s³‚ȃf[ƒ^Œ^‚Å‚·B';
            249: csBuf := Func + ' : ‚±‚êˆÈãƒfƒoƒCƒX‚ð’ljÁ‚Å‚«‚Ü‚¹‚ñB';
            250: csBuf := Func + ' : ƒfƒoƒCƒX–¼‚ªŒ©‚‚©‚è‚Ü‚¹‚ñB';
            251: csBuf := Func + ' : ƒfƒŠƒ~ƒ^‚ªƒfƒoƒCƒXŠÔ‚ňá‚Á‚Ä‚¢‚Ü‚·B';
            252: csBuf := Func + ' : GP-IBƒGƒ‰[‚Å‚·B';
            253: csBuf := Func + ' : ƒfƒŠƒ~ƒ^‚Ì‚Ý‚ðŽóM‚µ‚Ü‚µ‚½B';
            254: csBuf := Func + ' : ƒ^ƒCƒ€ƒAƒEƒg‚µ‚Ü‚µ‚½B';
            255: csBuf := Func + ' : ƒpƒ‰ƒ[ƒ^ƒGƒ‰[‚Å‚·B';
        end;
    end
    else
        csBuf := Func + ' : ³íI—¹‚µ‚Ü‚µ‚½B';


    Ret1 := Ret and $ff00;                 
    case Ret1 of
        $100: csBuf := csBuf + ' -- [SRQ]‚ðŽóM<STATUS>';            // 10 -> [256]
        $200: csBuf := csBuf + ' -- [IFC]‚ðŽóM<STATUS>';            // 10 -> [512]
        $300: csBuf := csBuf + ' -- [SRQ]‚Æ[IFC]‚ðŽóM<STATUS>';     // 10 -> [768]
    end;

    Result := RetCode;
end;

EDIT
在dll中找到了GpTalk函数。

EDIT Found the GpTalk function thats in the dll. Might help find an error?

Format                 
 (C)
   DWORD Srlen, Ret;
   DWORD * Cmd;
   char * Srbuf;
   Ret = GpTalk(Cmd, Srlen, Srbuf);



(Visual Basic)
   Dim Srlen As Long, Ret As Long
   Dim Cmd(xxxx) As Long '(xxxx specifies the maximum number of command arrays.)
   Dim Srbuf As String
   Dim SrbufB(xxxx) As Byte '(xxxx specifies the maximum amount of data.)
   Ret = GpTalk(Cmd(0), Srlen, Srbuf)
   Ret = GpTalkBinary(Cmd(0), Srlen, SrbufB(0))



Mode        Master mode/Slave mode

 Parameters          
         Cmd       : 

        [0] Number of talkers and listeners ( = Number of listeners+1)
                (Slave mode = 0)
        [1] Talker address
        [2] Listener address


        Srlen       :     Transmit data length (byte)
        Srbuf       :     Transmit data
        SrbufB     :     Transmit data array(for binary)
        Ret          :     Return value
        0     :  Normal completion
        80    :  GpIni() hasn't execute
        140  :  Asynchronous function is executing now
        240  :  ESC key pressed
        242  :  Miss in address specified
        243  :  Miss in buffers
        252  :  GP-IB error
        254  :  Timeout
        255  :  Illegal call




Notes             
1 Command array:
Since the number of commands to be sent is given to Cmd[0], specify 0 for Cmd[0] in slave mode.

2  1Mbyte will be sent if transmit data length = 0.
3  If you have already used DOS-Version, you do not need to execute Dmainuse function when using FIFO.
4  When transmits binary data by VB, use GpTalkBinary. And secure buffers by Byte type. Refer to VB's help "unicode".


推荐答案


  1. 在D10-西雅图您必须将 PAnsiChar AnsiString 用于数据缓冲区

    (因为 PChar 在现代Delphi版本中为 PWideChar )。

  2. GpTalk 返回数据是否为 Srbuf ?如果是这样,缓冲区长度是否足以响应?

  1. In D10-Seattle you have to use PAnsiChar and AnsiString for data buffers
    (because PChar is PWideChar in modern Delphi versions).
  2. Does GpTalk return data is Srbuf? If so, is buffer length enough for response?

   srBuffer: AnsiString;                                       // command
    SendBuf: PAnsiChar;
...
    SendBuf := PAnsiChar(srBuffer);                            // change string to Pchar 
...
 function  GpTalk(Cmd:PDWORD; Srlen:DWORD; Srbuf: PAnsiChar):DWORD;stdcall;

这篇关于GB-IP功能无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆