我的PC上有一张GP-IB卡,通过GP-IB连接到数字万用表。我在卡上运行了诊断程序并确认它正在运行。我能控制它扔软件测试。现在我正在尝试创建一个程序来执行它,但是当它发送命令时,它总是在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;
EDIT 找到了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".
答案 0 :(得分:0)
PAnsiChar
和AnsiString
作为数据缓冲区
(因为PChar
在现代Delphi版本中是PWideChar
。 Srbuf
吗?如果是这样,缓冲区长度是否足以响应?
srBuffer: AnsiString; // command
SendBuf: PAnsiChar;
...
SendBuf := PAnsiChar(srBuffer); // change string to Pchar
...
function GpTalk(Cmd:PDWORD; Srlen:DWORD; Srbuf: PAnsiChar):DWORD;stdcall;