09-02-2011 07:05 PM
I'm using VC++ .NET to write an app to control the HP33120A device. Within the code I'm querying the device for the frequency that it is
set to in order to display the value to the user. However, to do this I'm trying to invoke viClear(Instrument) where Instrument is the recognized
ViSession. Below is the code that I used. It works except when CHECK(viClear(Instrument)); is invoked and I obtain Error 521 - an RS232
framing error. What would cause this? I'm using Parity: 8 bits, none and 1200 baud transmit rate. The code in question is bordered by *****.
If the code in question is excised - the program works great. I'm running on Win-XP.
CHECK(viOpenDefaultRM(&viDefaultRM));
CHECK(viOpen(viDefaultRM, TxtAddress, VI_EXCLUSIVE_LOCK, VI_NULL, &Instrument));
strcpy_s(SCPIcmd,sizeof(SCPIcmd), "*RST\n"); /* Reset function generator */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd), &actual));
strcpy_s(SCPIcmd,sizeof(SCPIcmd), "*CLS\n"); /* Clear errors and status registers */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd), &actual));
strcpy_s(SCPIcmd,sizeof(SCPIcmd), "SYSTem:REMote\n"); /* Put in remote mode */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd), &actual));
strcpy_s(SCPIcmd,sizeof(SCPIcmd), "FORMat:BORDer SWAP\n"); /* Swap data bytes (send LSB first) */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd), &actual));
strcpy_s(SCPIcmd,sizeof(SCPIcmd), "DISPlay ON\n"); /* Set display to on */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd), &actual));
strcpy_s(SCPIcmd,sizeof(SCPIcmd), "DISPLay:TEXT:CLEar\n"); /* Clear display */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd), &actual));
strcpy_s(SCPIcmd,sizeof(SCPIcmd), "FREQuency 0.5\n"); /* Output frequency */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd), &actual));
strcpy_s(SCPIcmd,sizeof(SCPIcmd), "VOLTage 0.75\n"); /* Output voltage */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd), &actual));
//strcpy_s(SCPIcmd, sizeof(SCPIcmd), "OUTPut:LOAD INF\n"); /* Output load */
strcpy_s(SCPIcmd,sizeof(SCPIcmd), "OUTPut:LOAD INF\n"); /* Output load */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd), &actual));
strcpy_s(SCPIcmd,sizeof(SCPIcmd), "FUNCtion:SHAPe SIN\n"); /* Output waveform shape */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd), &actual));
*****************************************************************************************************
CHECK(viClear(Instrument));
strcpy_s(SCPIcmd,sizeof(SCPIcmd), "FREQ?\n"); /* Freq query */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd), &actual));
CHECK(viRead(Instrument, (ViPBuf)buf, 256, &actual));
*****************************************************************************************************
strcpy_s(SCPIcmd,sizeof(SCPIcmd), "SYSTem:LOCal\n"); /* Set to local operation */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd), &actual));
CHECK(viClose(Instrument));
CHECK(viClose(viDefaultRM));
Solved! Go to Solution.
09-06-2011 08:01 PM
Hello HTinSB,
You may want to see if you get the same error if you open up an example specifically for communicating via serial. If you have our driver installed, then you should be able to go to the start menu, go to all programs>National Instruments>VISA>Examples>C>Serial, and then open up the main VC++ project that is in there. You may want to base your code off of these examples that use our serial drivers. Refer to this document for references on what commands to send to your HP33120A: http://www.home.agilent.com/upload/cmc_upload/All/6C0633120A_USERSGUIDE_ENGLISH.pdf?&cc=US&lc=eng. I hope this helps.
-Nathan H
09-09-2011 12:28 PM
Well, I used an example file SimpleSine, gotten from NI and located on my machine at
C:\Program Files\Agilent\IntuiLink\Waveform Generator\Examples\VC60\VISA\SimpleSine.
I compiled this example with Visual Studio C++ with the visa.h/visatype.h and visa32lib. It worked
as advertised. I then inserted the command viClear(Instrument) (where Instrument is the vi Session) to clear the output buffers.
Recompiling and re-running, I got the same result, -511, an RS232 framing error.
All I'm trying to do is query the machine for its frequency setting, but I can't unless I clear the output
buffers first. Should I be using a command other than viClear?
09-09-2011 12:33 PM
Sorry for the confusing subject heading, it should read:
Invoke viClear leads to Error 511 - RS232 framing error on the HP33120A
not 521 as I had originally stated.
09-09-2011 04:08 PM
Hello HTinSB,
Refer to this manual for function syntax: http://www.ni.com/pdf/manuals/370132b.pdf
In the above manual is seems like the correct syntax for this function is: viClear(ViSession vi). If you just want to clear the buffer, you may also want to try using viFlush. The syntax can be found on page 5-34 of the manual above.
You may also want to take a look at these forums, they may help:
http://forums.ni.com/t5/LabWindows-CVI/Framing-errors-with-RS232-in-CVI-2009/m-p/1565544#M52753
http://forums.ni.com/t5/Instrument-Control-GPIB-Serial/RS232-framing-error/td-p/1242438
I hope this helps!
-Nathan H
09-14-2011 02:08 PM
The viFlush command worked and I'm able to read from the device buffers. Still no clue why viClear gave me such trouble.
Thanks for your help.