Recent

Author Topic: FP-VISA - A simple component to connect to VISA instruments  (Read 10507 times)

Laksen

  • Hero Member
  • *****
  • Posts: 744
    • J-Software
FP-VISA - A simple component to connect to VISA instruments
« on: September 20, 2014, 10:31:25 am »
I've done a simple header conversion for VISA, and implemented a small component to make it easy to communicate with SCPI instruments.

For now the header only supports windows, uses static linking, and has some known bugs, but it should be crossplatform with minimal changes. Feel free to send me a pull request if you get it working on Linux and mac :)

Over the years I've had great use of it for experiments, so here it is:
https://github.com/Laksen/FP-VISA

kamischi

  • Full Member
  • ***
  • Posts: 177
Re: FP-VISA - A simple component to connect to VISA instruments
« Reply #1 on: September 20, 2014, 11:21:21 am »
This is great and will replace my miniVisa headers, which i created for a test. Unfortunately, i did not succeed to install the drivers for an Agilent USB-Daq box on Windows and we finally switched to a cheap non-VISA box from BMC. I also tried to use the Agilent box from Mac OS X, but no success either. Maybe, I have another go at it, since I have a project with high school students with Delphi background. Besides naming the library, I expect no further changes for Mac OS X and Linux.

MiSchi
fpc 2.6.4, lazarus 1.4.0, Mac OS X, fink

Laksen

  • Hero Member
  • *****
  • Posts: 744
    • J-Software
Re: FP-VISA - A simple component to connect to VISA instruments
« Reply #2 on: September 20, 2014, 11:49:39 am »
Sounds strange. I've never had any problems with Agilent/Keysight's IO Libraries.

Did you try NI's VISA implementation instead?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: FP-VISA - A simple component to connect to VISA instruments
« Reply #3 on: September 20, 2014, 01:23:31 pm »
Btw, units like VISAtypes become increasingly redundant now that both FPC and current Delphi versions (say since XE2) have a full set of (u)int8..(u)int64 types defined.

Laksen

  • Hero Member
  • *****
  • Posts: 744
    • J-Software
Re: FP-VISA - A simple component to connect to VISA instruments
« Reply #4 on: September 20, 2014, 01:31:38 pm »
Sort of agreed, but it's just to provide actual visa compatible types, like viUint8, etc.

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: FP-VISA - A simple component to connect to VISA instruments
« Reply #5 on: September 20, 2014, 01:55:21 pm »
Quote
I've done a simple header conversion for VISA

WOW, great project, many thanks.

Fred
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: FP-VISA - A simple component to connect to VISA instruments
« Reply #6 on: September 20, 2014, 09:42:47 pm »
I've got an error: error in type definition (RawByteString)
win7 32 bit, Lazarus 1.2.4, FPC 2.6.4, svn: 45510

Laksen

  • Hero Member
  • *****
  • Posts: 744
    • J-Software
Re: FP-VISA - A simple component to connect to VISA instruments
« Reply #7 on: September 21, 2014, 01:24:00 pm »
Fixed that.

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: FP-VISA - A simple component to connect to VISA instruments
« Reply #8 on: September 21, 2014, 01:29:50 pm »
Thank you very much, Laksen! Also, thank you for your effort and sharing.

kamischi

  • Full Member
  • ***
  • Posts: 177
Re: FP-VISA - A simple component to connect to VISA instruments
« Reply #9 on: September 21, 2014, 02:01:53 pm »
Sounds strange. I've never had any problems with Agilent/Keysight's IO Libraries.

Did you try NI's VISA implementation instead?
In the end, I suspect that some Virus protection or such was the actual problem. However, I am not expert on that, I did not have access to the system for longer time and it wasn't my system and i did not want to take responsibility for wrecking it. But it sounds like i should give it another try on a system, where I am in a more powerful situation.

MiSchi
fpc 2.6.4, lazarus 1.4.0, Mac OS X, fink

dodgeydave

  • New Member
  • *
  • Posts: 17
  • PM me if needed.
Re: FP-VISA - A simple component to connect to VISA instruments
« Reply #10 on: March 02, 2022, 03:06:38 pm »
Hi.

Have been looking at this, and eventually managed to make it work with serial communications via NI's VISA Library on Win10.
(It is easier for me to develop code with some simple emulators attached by a serial link, before letting rip with expensive high power GPIB connected kit...)

Especially as I see NI now have a VISA download for Debian Linux and derivatives.  Yet to be explored...  (On a sacrificial 'nix install!)

It took a while, as I could not find an way to manipulate a serial port's settings (speed, data bits, parity etc) as VISA's SetAttributes call's need a handle relating to the instance of the VISA session, that in turn, I could not find any way to identify from outside the VisaSession code.   So, I added it..

In the session unit, under public. I added...
Code: Pascal  [Select][+][-]
  1.    function GetHandle: ViSession;
  2.  

In the Implementation part, I added
Code: Pascal  [Select][+][-]
  1. function TVisaSession.GetHandle: ViSession;
  2. Begin
  3.    result := fHandle;
  4. end;
  5.  

I can now access the needed handle for the VISA call's to manipulate the serial port settings, and all is well.

(I guess I could have just moved fHandle from the private deceleration to public, but I can see potential issues doing that...  But if the brains trust say that's OK, I'll go that way instead.)

Anyway...
In the projects Unit1.pas

Code: Pascal  [Select][+][-]
  1.    VisaSession1.Address := 'ASRL4::INSTR'  // Windows COM4
  2.    
  3.       VisaSession1.Active := True;
  4.       If Status = VI_SUCCESS then begin
  5.          viHandle := VisaSession1.GetHandle;
  6.  
  7.          status := viSetAttribute(viHandle, VI_ATTR_ASRL_PARRITY, VI_ASRL_PAR_ODD);
  8.  
  9.  

etc..  Things now work as NI document with serial ports...

NOTE!  The above is not Copy/Pasted from with a Lazarus project, but fat finger transcribed from one PC to another, so errors and commissions may have occurred, as well as spulling mistooks.

If someone can come up with a reason why not to do access the session handle that way, OK..  But what is the accepted alternative?   As I've not yet found any documentation for FP-Visa at all, other than the sources on Github, where such info is sadly missing.

Otherwise, if anyone wants, I can provide the working example code, so far, for those who like to laugh at others attempts, or wish to play with...

Regards to All.

DodgeyDave.


I've done a simple header conversion for VISA, and implemented a small component to make it easy to communicate with SCPI instruments.

For now the header only supports windows, uses static linking, and has some known bugs, but it should be crossplatform with minimal changes. Feel free to send me a pull request if you get it working on Linux and mac :)

Over the years I've had great use of it for experiments, so here it is:
https://github.com/Laksen/FP-VISA
Who let the smoke out?

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: FP-VISA - A simple component to connect to VISA instruments
« Reply #11 on: March 02, 2022, 03:35:36 pm »
Nicely done. I've got older test equipment which I normally talk to via a cheap IEEE-488 adapter.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Kepsz

  • New Member
  • *
  • Posts: 32
Re: FP-VISA - A simple component to connect to VISA instruments
« Reply #12 on: August 09, 2023, 01:07:33 pm »
Thanks Lasken for this component!

Btw, it is not documented at all, so I wrote a simple program.

Steps:
-Install Ni-Visa from here: https://www.ni.com/en/support/downloads/drivers/download.ni-visa.html#484351
-Reboot, connect your USBTMC capable device. In my case, that is a Siglent SPS5051X
-Open VISA Interactive Control, and look for the "USB Instrument Resource". That is the address of the device. For my device, it is: USB0::0xF4EC::0x1453::SPS51ABD6R0511::INSTR
-Download the FP-VISA package from Lasken's repo: https://github.com/Laksen/FP-VISA
-Open the .lpk package file in lazarus, then choos install and rebuild the IDE.
-Now you can drga-and-drop the TVisaSession object from the Lazarus toolbar.

Verry basic code to read ID, read / set voltage on CH1 and turn CH1 On/Off on an already connected and powered device:

Code: Pascal  [Select][+][-]
  1. unit main;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, session,
  9.   LazLogger;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     SetVolt: TButton;
  17.     IdData: TEdit;
  18.     Output: TToggleBox;
  19.     VoltageData: TEdit;
  20.     Label1: TLabel;
  21.     Label2: TLabel;
  22.     ReadVolt: TButton;
  23.     VisaSession1: TVisaSession;
  24.     procedure FormCreate(Sender: TObject);
  25.     procedure FormShow(Sender: TObject);
  26.     procedure OutputClick(Sender: TObject);
  27.     procedure ReadVoltClick(Sender: TObject);
  28.     procedure SetVoltClick(Sender: TObject);
  29.   private
  30.  
  31.   public
  32.  
  33.   end;
  34.  
  35. const
  36.   ADDRESS = 'USB0::0xF4EC::0x1453::SPS51ABD6R0511::INSTR';
  37.  
  38. var
  39.   Form1: TForm1;
  40.  
  41. implementation
  42.  
  43. {$R *.lfm}
  44.  
  45. { TForm1 }
  46.  
  47. //create object
  48. procedure TForm1.FormCreate(Sender: TObject);
  49. begin
  50.   VisaSession1 := TVisaSession.Create(nil);
  51. end;
  52.  
  53. //activate connection, read device identifier
  54. procedure TForm1.FormShow(Sender: TObject);
  55. begin
  56.    VisaSession1.Address := ADDRESS;
  57.    VisaSession1.Active := True;
  58.    IdData.Caption := VisaSession1.Query('*IDN?');
  59. end;
  60.  
  61. //read the measured voltage
  62. procedure TForm1.ReadVoltClick(Sender: TObject);
  63. begin
  64.    VoltageData.Caption := VisaSession1.Query(':MEASure:VOLTage? CH1');
  65. end;
  66.  
  67. //sets CH1 voltage
  68. procedure TForm1.SetVoltClick(Sender: TObject);
  69. begin
  70.    VisaSession1.Write(':SOURce:VOLTage:SET CH1,' + VoltageData.Caption);
  71.    VoltageData.Caption := VisaSession1.Query(':MEASure:VOLTage? CH1');
  72. end;
  73.  
  74. //On-Off CH1
  75. procedure TForm1.OutputClick(Sender: TObject);
  76. begin
  77.    if Output.Checked then begin
  78.      VisaSession1.Write('OUTPut 1');
  79.    end else begin
  80.      VisaSession1.Write('OUTPut 0');
  81.    end;
  82. end;
  83.  
  84. end.

 

TinyPortal © 2005-2018