Home > Back-end >  Delphi via usb control equipment
Delphi via usb control equipment

Time:09-19

Private Sub Command1_Click ()
Dim defrm As Long
Dim vi As Long
The usb resources
'to get visaCall viOpenDefaultRM (defrm)

'to open the equipmentCall viOpen (defrm, "USB0: : x1ab1:0:0 x0e11: : DP8F192200227: : INSTR", 0, 0, vi)
'send set command
Call viVPrintf (vi, ": the OUTP CH1, ON" + $(10) CRH, 0)
'close the resources
Call viClose (vi)
Call viClose (defrm)
End Sub
Above is written in VB DP831 dc power through USB control procedures, test no problem, but after I change this code into Delphi, operation error, exclude please maze! The following is my Delphi code

The function viOpenDefaultRM (sesn1: PLongint) : Longint; Stdcall external 'visa32. DLL';
The function viOpen (sesn1: PLongint; RsrcName: PChar; AcessMode: Longint; Timeout: Longint; Sesn2: PLongint) : Longint; Stdcall external 'visa32. DLL';
The function viPrintf (vi: PLongint; WriteFmt: pchar; Ss: Longint) : integer; Cdecl; External 'VISA32. DLL';
The function viClose (sesn: PLongint) : Longint; Stdcall external 'visa32. DLL';

Procedure TForm1. Button1Click (Sender: TObject);
Var
Defrm, vi: PLongint;
The begin
//get visa usb resources
ViOpenDefaultRM (defrm);
//open the equipment
ViOpen (defrm, 'USB0: : x1ab1:0:0 x0e11: : DP8F192200227: : INSTR', 0, 0, vi);
//send the set command
ViPrintf (vi, ': OUTP CH1, ON' + # 10, 0).
ViClose (vi);
ViClose (defrm);
end;
I don't know where is wrong?

CodePudding user response:

Not the USB communication SDK?

Check to Delphi variable types, according to the error message debug it slowly

CodePudding user response:

I feel mostly send command has a problem, VB source code is the following
'send set command
Call viVPrintf (vi, ": the OUTP CH1, ON" + $(10) CRH, 0)
And I use the Delphi code is
ViPrintf (vi, ': OUTP CH1, ON' + # 10, 0).
Step through here, after the equipment to a remote command error, do not know what a teacher can help me find the problem?

CodePudding user response:

VB ": the OUTP CH1, ON" + $(10) and CRH into Delphi should be what kind of?

CodePudding user response:

Why viPrintf statement as cdecl, the rest are stdcall
For this kind of question should be no statement
  • Related