06-14-2012 08:57 PM
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.
06-15-2012 08:21 AM - edited 06-15-2012 08:22 AM
@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.
explains it better than I can
06-15-2012 09:40 AM
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.
06-15-2012 12:59 PM
If you have to put a 1 second delay after *RST, then 2 seconds isn't enough.
06-15-2012 01:14 PM
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.
06-15-2012 01:51 PM
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.
06-15-2012 01:58 PM
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.
06-15-2012 02:23 PM
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.
06-15-2012 02:59 PM
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.
06-15-2012 03:20 PM
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.