Agilent Technologies

VISA COM: Borland Delphi Sample Test Program

To get the VISA COM type information into your project you must use the Component-Import Component menu pick.
Then click through until you see a choice of "Add Unit to Project1.bdsproj" or whatever your current project
name is. Choose that to add the type information to your project.

Included is a console project that outputs a *IDN? All the files are in the .zip, but you may need to adjust
the relative path to the VisaComLib_TLB.pas file in the project. The code looks similar enough to the C++
versions that a person familiar with COM programming shouldn't take too long to get up-to-speed on using
VISA COM in Delphi. There are examples in C++ on the Agilent website and with the product that should be
easily translatable to Delphi by such a person.


Below is the source code from the zip file.

***********************************************

program Project1;

{$APPTYPE CONSOLE}

uses SysUtils {: CoClass},
ActiveX,
VisaComLib_TLB in 'c:\program files\borland\bds\4.0\Imports\VisaComLib_TLB.pas'; // This path may need to change
depending on how you get the VISA COM type info

var rm : IResourceManager3;
var io : IMessage;
var sess : IVisaSession;
var retCount : Integer;
var readResult : WideString;
begin
CoInitializeEx (NIL, COINIT_APARTMENTTHREADED); // Start COM on this thread
rm := CoResourceManager.Create; // Create the VISA COM I/O Resource manager
rm.Open('GPIB0::23::INSTR', NO_LOCK, 0, '', sess); // Use the resource manager to create a VISA COM Session
sess.QueryInterface(IID_IMessage, io); // The IVisaSession interface is very general and does not have string
reading/writing , we want to be able to read and write to the instrument

io.WriteString('*IDN?', retCount); // Write to the instrument
io.ReadString(1000, readResult); // read the result
sess := nil; // cause Delphi to release the COM objects before the program closes to avoid leaked resources and errors
io.Close(); // ...
rm := nil; // ...
Writeln(readResult); // Write the result to the console
Readln(readResult); // Read from the console so that the program just does not disappear
end.


=============================================================================================

Date: May 17, 2006
Version: 1.0.0.0
Language: Borland Delphi
Operating System: Windows(r) 2000, XP
   &nbsp VISA Com using Agilent IO Library Suite 14.0 or above


Microsoft, Windows, NT, XP are registered trademarks of Microsoft Corporation


Copyright (c) 2005 Agilent Technologies Inc. All rights reserved.

You have a royalty-free right to use, modify, reproduce and distribute these example 
files (and/or any modified version) in any way you find useful, provided that you 
agree that Agilent has no warranty, obligations or liability for any Sample 
Application Files.

Agilent Technologies will not modify the program to provide added
functionality or construct procedures to meet your specific needs.




© Agilent 2000-2006