Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Invoke viClear leads to Error 521 - RS232 framing error on the HP33120A

Solved!
Go to solution

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));

0 Kudos
Message 1 of 6
(4,120 Views)

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 

Software Developer
National Instruments
0 Kudos
Message 2 of 6
(4,102 Views)

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?

0 Kudos
Message 3 of 6
(4,096 Views)

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.

0 Kudos
Message 4 of 6
(4,094 Views)
Solution
Accepted by topic author HTinSB

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 

Software Developer
National Instruments
0 Kudos
Message 5 of 6
(4,021 Views)

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.

0 Kudos
Message 6 of 6
(4,002 Views)