 |
|
 |
You all ways have a friend when you join, Hoo-Raa!
|
|
|
|
 |
|
 |
HELLO!!
I'm ROK Marines 2007~2009
Best Of Best!! MarineCorps!
|
|
|
|
 |
|
 |
I am communicating to an agilent function generator using C#. I am able to send commands to the device, for example, set the frequency to a particular value by using the function.generator dll.
I can write to the device with the following code:
m_gpib.BeginWrite("Freq 1000000");
But I am unable to read from the device. I would like to read the voltage and the frequency back from the function generator, but I am having trouble doing so. I tried to use the following code:
m_gpib.BeginWrite("Freq?");
m_gpib.BeginRead(text);
but a get an error during compile.
Got any ideas on how I can read from the function generator?
M_Pry Doctor
|
|
|
|
 |
|
 |
I would strongly recommend not using Asych Reads/Writes for simple device communication (i.e. using BeginWrite/BeginRead). That could be the cause of your communication failures. One thing to note as well is that most instruments require some sort of termination to be sent at the end the write data, for example CR, LF, or both. If you are using the National Instruments cards/drivers, it will not automatically send these terminators, you must implicitly append them to all of your data. If the required terminator is not sent to the device with the data, the command will never terminate and the instrument will wait for more data before responding.
Remember as well that most instruments send a terminator back to you with the data (usually the same type of terminator that it responds to during write operations).
Here is a simple example:
'Set the Frequency to 1 MHz
m_gpib.Write("FREQ 1000000" & vbCrLf)
'Request the Frequency
m_gpib.Write("FREQ?" & vbCrLf)
'Read the data, replacing the terminators that are received from the instrument and trimming the data.
Dim Reading As String = m_gpib.ReadString.Replace(vbCr, "").Replace(vbLf, "").Trim
The reason for stripping the terminators should be obvious, it has no use after it has been received.
I would recommend creating a base instrument class that has a method for writting data and functions for reading data that incorporate the functionallity of sending the terminators on writes and stripping the terminators on reads to speed up procedure development.
I use these functions in my base AutomatedInstrument class (there are many more you can use as well):
Public MustInherit Class AutomatedInstrument
Private fDevice As NationalInstruments.NI4882.Device
Public Overridable Sub Write(ByVal data as string, Optional ByVal terminator As String = vbCrLf)
Me.fDevice.Write(data & terminator)
End Sub
Public Overridable Function ReadString() As String
Return Me.fDevice.ReadString.Replace(vbCr, "").Replace(vbLf, "").Trim
End Function
Public Overridable Function ReadDouble As Double
Return CDbl(Me.ReadString)
End Function
Public Overridable Function QueryString(ByVal data as string, Optional ByVal writeTerminator AS String = vbCrLf) As String
Me.Write(data, writeTerminator
Return Me.ReadString
End Function
Public Overridable Function QueryDouble(ByVal data as string, Optional ByVal writeTerminator AS String = vbCrLf) As Double
Me.Write(data, writeTerminator
Return Me.ReadDouble
End Function
End Class
I hope this helps, if you have any other problems, let me know.
Scott Page
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
 |
|
 |
I tried the following code:
string reading;
m_gpib.Write("FREQ 1500000\n");//includes carriage return
m_gpib.Write("VOLT?\n") ; //includes carriage return
reading = m_gpib.ReadString();
textBox1.Text = reading;
m_gpib.Write() doesn't seem to work, but m_gpib.BeginWrite() does work.
Also, I am still unable to read the correct voltage value from the function generator, although I do receive some random values (these values change every time I run the program)
|
|
|
|
 |
|
 |
What Manufacturer/Model of Function Generator are you using?
Also, what are the errors you are receiving when you try m_gpib.Write?
That should give me enough information to replicate your problem or at least solve it for you.
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
 |
|
 |
I just thought about something after I replied with my last post. The BeginWrite and BeginRead methods exist primarily for long operations where you need to have the rest of the application responsive. The Write and ReadString methods are still the best route to take when synchronizing communication.
One possible reason that the BeginWrite and BeginRead methods work is that the instrument places some data in its output buffer long after it is requested (hence the reason I explained the "long operations" for the Begin methods). So the most likely reason is, the instrument is not ready to send data due to improper commands or command sequence.
Please let me know the Manufacturer/Model and the errors you are getting. You can also try the NISpy program that installs with the NI software. It will show you all Board and Device communication as it happens on the bus.
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
 |
|
 |
Its an Agilent 33220A function generator.
|
|
|
|
 |
|
 |
I have a 33120A in my lab (same commands). I just finished creating a test application with sample Instrument drivers for the 33120A and 33220A.
If you want a copy of it, send me an email and I'll zip the contents of this project and sent it right back to you. The app works great on my station, so if it doesn't work for you, then something is going on with your hardware setup. Bad cables, wrong address, to many instruments on the bus, etc...
Let me know by email if you want a copy of this program, hopefully it will help you diagnose what the problem is.
Scott
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
 |
|
 |
I just remembered that my email address isn't displayed anywhere. I'll setup a download file for you and post the website. Give me about 6 hours to get home and set it up.
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
 |
|
 |
Download this file http://cffinc.biz/gpibcommunication/gpibcommunication.zip[^]
It includes a VS.NET 2003 solution with two sample drivers and several instrument base classes to get you started. The meat of the read/writes is in the AutomatedInstrument.vb file near the bottom. You will see how I strip the terminators and how the data is sent using the Device.Write and Device.ReadString methods.
Hope this helps!
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
 |
|
|
 |
|
 |
My bust, I went home last night and created the directory and just after that I changed the virtual directory of the domain without thinking about the link. I just moved it to a location that will be accessable from the same link you tried before.
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
 |
|
 |
Can you possibly provide example code in C# on how to communicate with the Agilent 33220A?
The real problem is querying the device for frequency and amplitude. I send the command "FREQ?", but
I am unable to read it from the device. And it would be helpful to see how you accomplished this in C#.
|
|
|
|
 |
|
 |
I'm not very well versed in C#, I can read the code, but I would have trouble constructing the example. I will convert my previous example using one of the online conversion apps.
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
 |
|
 |
I've finally figured out how to read/write to instruments using C# and gpib. The solution is to reference the 'NationalInstruments4882.dll'. Within this namespace, I a am able to use the class called 'device', which contains the various methods I need to use for reading and writing to almost any gpib commutable instrument.
thanks!
|
|
|
|
 |
|
 |
Hi,
I'm trying to control a Willtek Stabilock 4032 using this code. Sending commands to it works fine. However, when I try to read from the device, it returns a timeout error. Using NI's spy application it is clear that the device does return the valid string, but it never reaches the application. For example, here's a short trace of the spy:
73. ibwtr(UD0, "ident;", 6 (0x6))
ibsta: 0x100 iberr: 0 ibcntl: 6(0x6)
74. ThreadIbcntl()
ibsta: 0x100 iberr: 0 ibcntl: 6(0x6)
>75. ibrd(UD0, "Willtek STABI...", 1024 (0x400))
>ibsta: 0xc100 iberr: 6 ibcntl: 100(0x64)
>76. ThreadIbcntl()
>ibsta: 0xc100 iberr: 6 ibcntl: 100(0x64)
>77. ThreadIberr()
>ibsta: 0xc100 iberr: 6 ibcntl: 100(0x64)
>78. ThreadIbcntl()
>ibsta: 0xc100 iberr: 6 ibcntl: 100(0x64)
I have tried allowing more time for a response, but this does not seem to work either.
I would really appreciate any help.
Thanks
|
|
|
|
 |
|
 |
I am having a very similar problem. Is your device old? If it is it may be using IEEE 488.1 rather than 488.2. That's my situation. Another guy wrote a VB6 program which works pretty well. After initializing, the device returns a timeout error for the first command. But if he sends the same command a second time it works just fine and continues working for the whole program. I'm using VB.NET 2005 and my program does the same thing. The first command always returns a timeout error, the second command always works and the rather than continuing cooperatively, all subsequent issued commands return a timeout error.
Regarding my issue (and yours) I am wondering if the automatic polling of information on a separate thread (ThreadIbsta for me and ThreadIbcntl for you) is interfering. I'm working on figuring out how to disable these threads. The threaded status checks, in fact, are the only difference in the NISpy trace from my program (doesn't work) and the VB6 program (does work) hmmm...?
|
|
|
|
 |
|
 |
Sorry for the WAY late response (see my blog post for a detailed "excuse").
Make sure you are sending the correct terminator for the GPIB. Older devices require, or suggest, that a ; be sent after each command. However, it is often overlooked in all instruments, new and old, that a Carriage Return (CR), Line Feed (LF), or both (CRLF - same as NewLine) be sent after at the end of the command in a Write operation on the Device. --- BTW: vbCR, vbLF and vbCRLF are shortcuts for the CR, LF and NewLine respectively in .NET, verses importing the Microsoft.VisualBasic.ControlChars for each project.
A good reason (not saying that this is your specific solution) for the timeout or delay of returned data, is that the device is waiting for a terminator. In laymen’s terms, the employee (device) was given some command(s), but the meeting with the boss (controller) was never ended, because the command to "GO do what I asked" was never given.
P.S.
As a side note for some extreme instruments (i.e. the HP 8902A), require that you only request a specific number of bytes per read. In the HP 8902A, 15 is the maximum number you can read and have normal response times, beyond that, it WILL hang for 15 seconds or more per request for data, even if data is available per an SRQ.
I hope all of this helps. Again, sorry for the late response.
Scott
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
 |
|
 |
I downloaded the Demo. But I can't find it's source code. Most of the folders in the zip file I downloaded were empty. The only one containing anything contained all the dll's and an executable.
Generaly if anybody has used this libraries to work with Network analyzers I would be very happy to get the code. Even more if we're talking about Agilent Agilent8753D
Thanks. Yigi.
PS. I can be reached at yigimanb@yahoo.com
|
|
|
|
 |
|
 |
Sorry about the mixup. The program is to large to upload the Source Code and the demo (the demo is really just the full program). Let me know if you would like my current work (massive updates and additions). I'll send you a link or the zipped source code).
Funny you should mention the Network Analyzers, I just finished a large portion of the calibration routines and forms for entering the "Frequency List".
Also, I have started to bind all instruments to a datasource that dynamically calls up instrument information based off of Asset Numbers. Good for storing test data, etc..
Again, let me know what I can do to help, I'll send the entire package to you.
Thanks for the input,
Scott
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
 |
|
|
 |
|
 |
The main goal is to eliminate code as a form of instrument control (for the end user) and to speed up the process of calibration (or instrument control) on units that have no automated procedure written or new units that need to be calibrated ASAP.
The whole project started in Excel VBA (before I discovered that NI has a .NET API). I was tired of using cumbersome software packages like HP Basic, HT Basic, SureCal and MetCal. All of those applications have nice math features, however, thay all lack in the OOP area. I wanted instruments to no longer be physical devices but controls that can be dragged and dropped on to the screen. For the past 6 months I spent several hours writing the logic for each instrument family (DMM, SpecAn, SigGen, ect..). I also created the instrument specific classes to contain the tolerances, capabilities, test points, and GPIB commands.
With all of that said, my goal is to create a fully interactive visual application that allows for pluggins without recompiling the source. Additionally, I want to have data sent between instruments, messagebox and prompts created on the fly (based on connectors between instruments) along with tests and procedures created from scratch with just a few clicks of the mouse.
I have just completed (today) the first working visual model with drag and dropping of instruments as well as the connectors from one to the other.
As for different drivers being able to be used, I have not started to incorporate any preexisting drivers (NI, Agilent, Etc.) When I find the time I will start a project to add those instruments to the collection.
Anytime you need a copy of my source, let me know and I will send you what I have. The instrument classes I created no longer inherit from NationalInstrument.NI4882.Device, that all inherit from Control and have a Device as a variable (this allows for the visual effects without creating a wrapper.
Thanks for the input,
Scott
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
 |
|
 |
I tried to download the VS project files, but they don't build - there appear to be numerous resource files missing throughout all of the projects. Can you make those available?
Glenn B.
|
|
|
|
 |
|
 |
Unfortunately I only have SharpDevelop (www.sharpdevelop.com), so I couldn't create the resource files for VS.NET. I have discovered in the past that if I am missing a resource file, if I remove the resource reference then open the form in design view, a new resource file is created. Since none of the forms in FreeCal use resource files in the code, there is no need to worry about loosing important information. I'll look into getting the resource files converted to .resx (the format the VS.NET uses), instead of the .resources extension.
Sorry I couldn't help any more right now. One more thing you could try though is to download SharpDevelop (it's free) and run the project. Otherwise, feel free to just copy any part of my code you need for your own project(s).
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
 |