08-09-2016 03:39 AM
Hello,
I am using Excel VBA and visa32.dll to communicate with dmm Keithley2700 by using serial port. However it seems that I cannot write/read to/from the equipment. Below are the codes that I am struggling and stuck. I really appreciate any advice or sharing some example. Thank you.
Dim stat As ViStatus
Dim defaultRM As ViSession
Dim instr As ViSession
Dim retCount As Long
Dim sesn As ViSession
Dim buffer As String
Dim idnResult As String
stat = viOpenDefaultRM(defaultRM)
If (stat < VI_SUCCESS) Then
Rem Error initializing VISA...exiting
Cells(1, 3).Value = Error
Exit Sub
End If
stat = viOpen(defaultRM, "ASRL3::INSTR", 0, 50, sesn)
stat = viSetAttribute(sesn, VI_ATTR_TMO_VALUE, 5000)
stat = viWrite(sesn, "*IDN?", 5, retCount)
stat = viRead(sesn, idnResult, 72, retCount)
Cells(1, 4).Value = idnResult
stat = viClose(sesn)
stat = viClose(defaultRM)
01-24-2017 03:44 PM
Hello,
I wouldn't really recommend to use Excel or other such applications for actual data acquisition with their inbuilt code. However that is not to say it is not possible, from what I found, someone has developed an example with GPIB with walk through comments as the steps required:
Does the device also appear in MAX?
There is a GPIB driver for use with Measurement Studio and Visual Studio:
http://sine.ni.com/apps/utf8/niid_web_display.model_page?p_model_id=1460
I would suggest using Visual Studio community if this is for personal use, it is free to use, you only need register/sign in with an email account.
Once you have installed the Keithley driver, you should be able to add it in NI MAX with the following:
http://www.ni.com/tutorial/2761/en/
Then follow similar to the first example I gave, if issues still occur then we should be at the debugging level now. You can use NI I/O Trace to see the low level communication in the driver to indicate where the code is failing:
http://digital.ni.com/public.nsf/allkb/282C5D41E2BA04F2862574BA007803B9
Best regards,
Ed
04-18-2017 09:31 PM
I am using Excel VBA right now, I know most people don't recommend it, but I find it very convenient.
Make sure to open Visual Basic (Alt-F11) and go to Tool --> References... and select VISA COM 5.5 or something that looks similar. VBA must be pointed to VISA COM dll.
This is a copy of working code:
Dim ioMgr As VisaComLib.ResourceManager
Dim instrument As VisaComLib.FormattedIO488
Dim idn As String
Set ioMgr = New VisaComLib.ResourceManager
Set instrument = New VisaComLib.FormattedIO488
Set instrument.IO = ioMgr.Open("GPIB0::24")
instrument.WriteString "*IDN?"
idn = instrument.ReadString()
ActiveSheet.Cells(1, 1) = idn
01-25-2018 04:30 AM
Thanks vitoal, for this example. Successfully tried it to remote control a power supply from my Excel-VBA-program.
Is there a helpfile or Manual for this component?
What else can be done with that component, beside FormattedIO488?
I got it also installed on my Windows 10-machine by installing LabVIEW 2016.
This method of controlling simple GPIB-communication seems to be much more compact, than using the examples from National Instrument for 488.2 communication based on the files niglobal.bas and vbib-32.bas.
Regards,
Joe
01-25-2018 08:00 AM
This is what i found so far:
Use the NI-VISA class library to quickly create
bus-independent and/or bus-specific instrument control applications.
The NI-VISA class library supports I/O operations, locking, event
handling, and interface-specific extensions. With this class library, you can
access the functionality available in NI-VISA for communicating with
message-based and register-based instruments using the following
interfaces:
• GPIB
• PXI
• Serial (RS-232 and RS-485)
• TCP/IP
• USB
• VXI
05-30-2018 02:42 PM
Might be a little late here, but I had to generate an example for a customer recently. See the following:
https://forum.tek.com/viewtopic.php?f=62&t=140571
Code is attached for convenience.
05-30-2018 05:32 PM
Thanks for your informative example, jbrown.
Due to a missing helpfile, only examples can reaveal.
It shows me some more properties for serial communication.
I am using also
- Set ... = New VisaComLib.ResourceManager
- Set ... = New VisaComLib.FormattedIO488
- WriteString() and
- ReadString() for the actual communication
I am using USB-GPIB interface from NI only.
Interestingly also Serial communication is possible with this library functions.
Regards,
John
Dim ... As VisaComLib.ISerial
.BaudRate = 9600
.FlowControl = ASRL_FLOW_NONE
.Timeout = 10000
.IO.SendEndEnabled = True
.IO.TerminationCharacter = 10 ' could be 10 (line feed) or 13 (carriage return)
.IO.TerminationCharacterEnabled = True
.IO.Timeout = 10000
Also