LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sr830 connected with rs232, reading freq and voltage doesnot happen simultaneously

Solved!
Go to solution

Hi,

 

I am having a problem, trying to set the frequency and voltage in the auxiliary output simultaneously. I wrote two codes, one to set frequency and another to set voltage in the auxiliary output and used them as sub VIs to my main program which at this moment contains only these two elements. When I run the program the first time, both the frequency and voltages are set, but on subsequent runs only one item is set whilw the other retains the older value and I have to run the program again to set this parameter. What is the problem? can u please help me out. I am just one week into labview programming but I have to set up C-V hysterysis in very shor time, of which these controls are a part. Please find the programs attached.

Download All
0 Kudos
Message 1 of 6
(4,186 Views)

Both of those subVIs have problems. First, you do not want to configure the serial port in them and close the VISA session. Both should be done in you top level program only once. Second, the OUTXO command is terminated with a \r\n (carriage return\line feed). You don't terminate the frequency or voltage command. Third, each subVI should have an error in and error out connection. Place them on the connector pane in the expected locations (lower right and lower left) and wire all of the error clusters straight through. That will also allow you to eliminate that silly sequence structure.

Message 2 of 6
(4,172 Views)

You've got some issues with your code.

 

First of all, in your subVI's, you have a most of your controls hidden on the front panel.  This makes it hard to find the controls and determine what their default values are.  You have them wired to the connector pane, but you never really wire anything to them where they are placed in your main VI.

 

Second, you have 4 single frame flat sequence structures in your main VI, but none of them have any control over the data flow.  Three wrap around each subVI and a delay timer.  The fourth just wraps up those 3.  Those 3 frames of code are all going to execute at the same time more or less, and the two subVI's will execute right away.  The Delay timer doesn't delay anything, but having the main VI come back to edit mode at the end of execution.

 

Third,  both subVI's are set to write to com port 1.  They also both close the com port.  Since the two subVI's execute simulataneously, you'll actually have somewhat of a race condition of how the code inside them execute.  A serial port is a single entity that can only transmit the data sent to it in series.    The two VISA writes in the two subVI's will actually all compete with each other as to which one executes first.  My guess is that the order of the writes are getting jumbled in a way that the device never gets the second message accurately.

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

Thank you guyz for your respective suggestions, I have replaced the two serial port initialization into one and I have placed the write functions sequentially, with a VISA close and simple error handler at the end. I have aso terminated all the voltage, freq., and amplitude commands with EOL (\r\n) Now, when I run this program, in the first run nothing happens, the values for voltage, frequency and amplitude remains the same. On the second run only the first component, i.e., the voltage is set to the defined value the freq and amplitude remains unchanged and on subsequent runs, nothing happens at all. o, I can only set the voltage, but not the next two components. I am sorry, but I don´t if I am making some silly mistake, but why doesnot the write functions work sequentially now?  and BTW i have only one serial port connected to the Stanford research SR830 lock-in amplifier.

0 Kudos
Message 4 of 6
(4,153 Views)
Solution
Accepted by topic author mssrb

The next problem is your termination characters.  Your string constants show a \r\n, but the problem is that they are in normal mode and thus are sending 4 bytes  of a backslash, r, backslash, n.  You need to change those constants to be in backslash mode "\mode" so that when you enter \r\n, it is actually two bytes consisting of a carriage return (ASCII 13) and a line feed character (ASCII 10)

Message 5 of 6
(4,145 Views)

Thanks man that was it!!! now it works like magic. 

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