GB-IP Function not working correctly

故事扮演 提交于 2019-12-13 04:26:28

问题


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.

I have 3 source files Master.pas, SubClass.pas, and ApiGpib.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;

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' ;

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

  • Question is
    +Do you see anything wrong with the logic?
    +What can I try in troubleshooting as to why this dont work?

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 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:


  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;


来源:https://stackoverflow.com/questions/35077071/gb-ip-function-not-working-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!