LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does this read_write.vi work in second run?

Solved!
Go to solution

I set my buffer size for the I/O Transmit buffer.  You set yours for the Receive buffer.

 

Setting the Transmit buffer worked when I had that error message.  Transmit and Receive may work, also.  But I don't think setting it for the Receive buffer only is good enough because the error is being generated on the VISA write which implies the transmit buffer.

 

One other thing, I compared the error code to -1073807339 which is the error code for timeout, so it would feed the timeout boolean indicator.  You are comparing to 1073676294 and feeding that to the timeout boolean indicator.  That value is a warning to tell you got exactly the number of bytes you were asking for.  That isn't the same as a timeout, and to me is usually a meaningless warning.

 

And do you have your query boolean pressed when you run the VI?  If you don't, then you get your original command back.  That sounds like what is happening to you.  I wouldn't normally want to get the command repeated back in the indicator if I wasn't doing a query for the Read, but that was how your original VI was coded, so I just duplicated that.

0 Kudos
Message 11 of 25
(1,230 Views)

Hello Ravens,

Could you post your suggested code in vi format?

It would be great.

Thanks

0 Kudos
Message 12 of 25
(1,222 Views)

It's a snippet.  You can drag and drop the image from your browser into a block diagram.

0 Kudos
Message 13 of 25
(1,218 Views)

Hello Revans,

Thank u for your message, I ran the program that you created, and select the correct port number, and entered a command "1TS".

This time I got error out from VISA read. Please see the figure in below.

I am wondering if you have any idea why I get this error?

Thanks

ErrorOut.JPG

0 Kudos
Message 14 of 25
(1,201 Views)

You did not set the termination character at the VISA Configure Serial Port. See the comment that says "Set other parameters as necessary"? Well, you're supposed to do that. You need to correctly set the baud rate, number of data bits, number of stop bits, etc. The termination character is used by the VISA Read to know when to stop reading. What is the termination character? Wire a number to the VISA Configure Serial Port's termination character input that corresponds to the ASCII code of the termination character. If you do not know what the termination character is, look at the documentation for the SMC. It will tell you.

 

Common termination characters:

  • linefeed (value of decimal 10), 
  • carriage return (value of decimal 13)
0 Kudos
Message 15 of 25
(1,197 Views)

Hello,

Thank you for your message, I must confess that I am not very familiar with VISA, read and write, as originally I started posting my question on partially working read_write.vi that I got from Newport Corporation, it was only because I was not able to figure out the problem.

If you would know how to put the termination characher or related parameter, could you let me know how does it look like or what is the final code look like?

I got information from other vi that, the parameters are: Baud=57600, Data bits=8, Flow Cntr=Xon/Xoff, Parity=None, Stop bits=1.0, TermChar=13.

I hope I hear from you.

Regards

 

0 Kudos
Message 16 of 25
(1,188 Views)

Make sure you have context help turned on (Ctrl-H).  That gives a lot of information about whatever function you are hovering over.

 

Go to the Serial Config function.  Hover over each of the terminals.  Right click and create constant.  If you do that for Termination Character, you will see it comes up as 10, which is the default value, and is linefeed.  That is why you are getting the timeout, because your device is sending a carriage return (decimal 13) as the termination character.  So change the 10 to a 13.

 

Do that for the other inputs and change as necessary.  Batud rate and flow control are the two parameters I see that you definitely have to set because what you say they need to be does not match the default values for the Serial Config function which is what is used when nothing is wired to the terminals of the subVI.

0 Kudos
Message 17 of 25
(1,179 Views)

Hello Again,

Thank you for your message, This time, it worked, I was able to modify the read_write.vi without error.

But if I use it for the other subvi, I get another errors, for example if I use it in SimpleControlExample.vi (please see the attachment) I get an error says: "the controller is not in ready state" (The read_write.vi is inside of "tell controller status.vi")

Do I have to modify each individual subvi based on new modification in read_write.vi? if yes, how??

Could you please let me know?

Thanks

Best

0 Kudos
Message 18 of 25
(1,171 Views)

If you are going to be using this as a subVI within other parts of  your program, then I wouldn't put the serial configure and buffer setting in your subVI.  I would only do that once at the very beginning of your program.  And a VISA close at the very end of your program.

 

The error saying "the controller is not in ready state" is meaningless.  It is just a popup dialog that you programmed into your VI.  IT would be meaningful if you showed the actual error message coming out of your subVI.

 

But the problem is that your logic for checking the error coming out of your subVI is backwards.  It would actually be better if you just wired the error wire directly into the case selector of the case structure.  No need to unbundle the error status.  When you do that, the case structure shows up with Error and No Error cases in bright red or green which is a lot easier to understand than True vs. False.  In your situation, if the error status is true (which means there is an error) OR the timeout flag is True (which actually would already be an error on the error wire, so it is redundant), then the True case of that inner case structure runs.  But if the error status is False (no error) and the timeout flag is false, then your false case runs which is the one that pops up your user defined dialog box.

 

I'm not sure what you mean by modifying each individual subVI.  You have one subVI.  You just happen to use it twice.

 

I'd recommend replacing the stacked sequence structure with a flat sequence structure.  That stacked sequence structure just hides code unnecessarily.  And in your situation, isn't needed at all.  I would also turn on auto grow for our sequence structures and loops.  Leaving it off can hide code outside the borders of the structure.

 

See the attached VI where I modified your code.  I fixed the swapped the error cases and did a general cleanup.  Otherwise it should work the same as what you have.  What you will need to do is remove the serial configure and buffer setting from the subVI.

0 Kudos
Message 19 of 25
(1,167 Views)

Hello Ravens,

Thanks for your recommenations, I used the modified program that you provided, it worked for a while and then again I had the same error in read-write.vi. Please see the picture in below.

I must add that there are a lot of vi for controlling the instrument for different funtions, and all of them uses read_write.vi inside of them.

when I mentioned "modifying each individual subvi" I mean this instrument (SMC100) has many subvi for controlling different funtions, such going to home position, relative move, absolute move, reset, stop, and etc. I created another program to control two instruments at the same time, and I used many of these programs in different loops.

I tried it in many ways removing the serial configure and buffer from the subvi, it was worse, I had to keep the serial configure at read-write.vi, and use the modified SimpleControlExampleMOD.vi that you provided. This program is for telling to controller for waitinng till the move completes. There are other vi for controlling SMC100 for other functions, each of them uses the read_write.vi, and I am wondering if I should add VISA address and modification that you did or not.

Could you please let me know?

Thanks

0 Kudos
Message 20 of 25
(1,144 Views)