我的 PC 中有一张 GP-IB 卡,通过 GP-IB 连接到 DMM。我已经在卡上运行了诊断程序并确认它正在工作。我能够控制它扔那里的软件测试。现在我正在尝试创建一个程序来执行此操作,但是当它发送命令时,它总是在 DMM 上给出错误。
我有 3 个源文件 Master.pas、SubClass.pas 和 ApiGpib.pas
在 master.pas 我有这个向设备发送命令。
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 这样的功能。
type
PDWORD=^DWORD
function GpTalk(Cmd:PDWORD; Srlen:DWORD; Srbuf:PChar):DWORD;stdcall;
...
...
...
Implementation
function GpTalk; external 'ApiGpib1.dll' ;
它会在 DMM 上出错,我无法查看 ApiGpib1.dll。
- 问题是
+你觉得逻辑有什么问题吗?
+我可以尝试什么来解决为什么这不起作用?
最后,只需将其放入 CheckRet 函数中。在 Subclass.pas 我有这个。
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;
编辑在 dll 中找到 GpTalk 函数。可能有助于找到错误?
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".