Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

using multiple viwrite or viprintf commands causing problems (Visa serial communication using visual c++)

I am trying to program a power supply using  visual studio c++.To give some information:It has USB connection and it is listed under MAX in Serial&Parallel. I can control the outputs,read ,write etc. using VISA interactive control.

 

I am trying to run a simple code where I first send *IDN?  and then *RST.When I first query *IDN? the model number is displayed  but *RST command doesn't work.When I exit the program and run the program again it resets the power supply and displays 'Error reading a response from the device'.When I exit and rerun the program this time it displays the model number again but doesn't reset... Do I need to flush the buffers after using viwrite or viprintf? I tried to use viflush but it didn't help. I think the problem might have something to do with the buffers but I am not sure.The code is attached.

 

Thank you in advance.

Download All
0 Kudos
Message 1 of 12
(4,223 Views)

@Sorensen_XBT wrote:

I am trying to program a power supply using  visual studio c++.To give some information:It has USB connection and it is listed under MAX in Serial&Parallel. I can control the outputs,read ,write etc. using VISA interactive control.

 

I am trying to run a simple code where I first send *IDN?  and then *RST.When I first query *IDN? the model number is displayed  but *RST command doesn't work.When I exit the program and run the program again it resets the power supply and displays 'Error reading a response from the device'.When I exit and rerun the program this time it displays the model number again but doesn't reset... Do I need to flush the buffers after using viwrite or viprintf? I tried to use viflush but it didn't help. I think the problem might have something to do with the buffers but I am not sure.The code is attached.

 

Thank you in advance.


I don't program with Visual C++, but a *RST may take longer than 2 seconds which is the current timeout that is in the code snippets you attach.

 

I generally use use a *OPC? query after a *RST and with the timeout set to something like 30 seconds.

 

http://www.home.agilent.com/agilent/editorial.jspx?cc=US&lc=eng&ckey=602673&nid=-11144.0.00&id=60267...

explains it better than I can

 

0 Kudos
Message 2 of 12
(4,213 Views)

Thank you your response helped me to figure out what's wrong. 2seconds is enough for the RST command. But in my code the program exits right after RST that's why I wasn't able to observe anything.I just put a 1second delay after RST and it works now. 

0 Kudos
Message 3 of 12
(4,203 Views)

If you have to put a 1 second delay after *RST, then 2 seconds isn't enough.

0 Kudos
Message 4 of 12
(4,197 Views)

When I tried it out in VISA interactive control, timeout was set to 2 seconds and all commands worked.That's why i used the same value. It haven't measured the execution time of RST yet but it probably takes less than 1second to because RST and all the other commands  worked when i put 1 second delay.

0 Kudos
Message 5 of 12
(4,194 Views)

When you are using VISA interactive control, you the human are sending the commands. How do you know you are putting *exactly* a 2 second interval between sending the *RST and the *IDN? ? You don't. The computer is more exact than a person, hence your need to put an additional 1 second delay between the two commands in the program.

 

 

 

 

0 Kudos
Message 6 of 12
(4,191 Views)

I am not putting any delay between IDN and RST. I just put the delay after RST. I haven't measured the exact execution time for each command.However, if I put 2 seconds delay after each command it would make my controller useless since I need to  use the voltage output to control another hardware and I need fast response.In the user manual voltage response is given as 10ms and I'm hoping I don't need to wait longer than that everytime I send a new value for the voltage output.

0 Kudos
Message 7 of 12
(4,188 Views)

You are not really understanding what I am saying.

 

Perhaps if you'd post your code about this 1 second delay and what exactly it looks like, then maybe we can be on the same page.

 

Commands such as *RST are time-consuming. They always are. You're going to have to deal with that if you use it.

 

 

0 Kudos
Message 8 of 12
(4,186 Views)

I hope I got you right.The code is the same except that I added Sleep(1000); after the line:

status = viPrintf(instr, "*RST\n");

 

I am not going to use RST.Before using a device-specific command I wanted to make sure the communication works. I just used it as a simple test since it is a common command and I can hear the beep noise once the command is executed. The only function that I will use is the command to change the voltage output. Even if I put Sleep(10); after each command everything works perfectly fine.I think if there is no delay  the command doesn't have enough time to be executed.

0 Kudos
Message 9 of 12
(4,181 Views)

Since you claim that the 2 second GPIB timeout that was set up earlier in the code is adequate for the instrument to complete *RST and respond to the next command, then you shouldn't need the Sleep.

 

0 Kudos
Message 10 of 12
(4,176 Views)