LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing with VISA while reading.

Solved!
Go to solution

Hi, I am working with some ADAM-4000 series module and I am trying to write some commands while I am reading the values on one of the modules. I think the solution can be simple, but I don't have very much experience in LV and maybe I am missing it.

I am using VISA read and write for this operation and everything works well. The value that I am reading constantly will be a temperature sensor for the final purposes of this project. This temperature will be displayed on a graph and maybe saved to a file also. My problem is that if I want to send another command to control something else (on the same COM port but different module) I can't read the temperature while the command is sent and executed. This is creating a portion of the graph(possible 0's in the file) that I don't want. Is there a way, to save the last value before the 0 and faking the read in the graph while the extra command is sent? Or maybe is something that can use delays or time loops that may work?

 

In the attachment, the main command is #051 that will be sent continues and from the dial, I am creating a string with the next command. When the "OK" button is pressed, the case structure will switch from the initial command to the one created by the dial.  

 

I am sure that is something small that can be changed or a different approach regarding how the extra commands may be sent while still reading from the module.

 

Thank you in advance and feel free to ask anything that is not clear from my description.

0 Kudos
Message 1 of 26
(3,616 Views)
Solution
Accepted by topic author DDragos

Why can't you just do the reading of your measurement every iteration of the loop?  You perform the temperature read and then use the case structure to decide whether or not you need to perform the other command as well.

 

Some other general notes:

1. DO NOT USE THE BYTES AT PORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (This has slowly turned into my #1 pet peeve).  Your instrument obviously uses an ASCII protocol with a termination character.  So use that to your advantage.  When you configure the serial port (VISA Configure Serial Port), there is a couple of inputs on the top to enable the termination character and to set what the termination character is.  Leave the Boolean at its default (TRUE) and change the termination character to be 13 (0xD, Carriage Return).  Now when you use the VISA Read, just tell it to read more characters than you ever expect back from a message.  The VISA Read will stop when it reads the number of bytes you told it or it reads the termination character, whichever happens first.  So by telling the VISA Read to read more bytes than a message will ever be, you are ensuring you get all of your data instead of partial messages.  This is likely what is causing the issue you are encountering.

 

2. If you have the same code inside every case of a case structure, it should probably be moved to be out of the case structure.  This reduces complexity, makes it easier to debug, and easier to correct when you do find an issue.  In this particular case, you should have used a Select function to choose which string is being sent.  No case structure necessary.  But if you follow my initial advice, this comment is moot.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 26
(3,606 Views)

Wow, thank you for the very detailed answer. I was not using the Configured Block for VISA because I made the communication work with the "bytes at port". Also, the configured block can be used just once at the beginning of the program right? In case that I want to write something, I can just use the "VISA resource name" from the configuration block and use that as many times I want.

 

I think also that my explication was not so clear. I don't have a problem with partial messages. It was just a display problem, because when I send the command to(just as an example) set the voltage to 5V the answer from the module is blank. That was creating a downward spike in the graph. I fixed that problem just by checking if the value is 0, then I don't send the data to the graph.

 

About the point number 2, can you be more specific regarding what part of my VI you are speaking about?

 

Also because I don't wish to start another topic, do you have any advice regarding the PID block from LV? I want to use it to keep the temperature at a certain point by controlling a heater and a vent with simple 0-10V input. Thanks in advance. 

 

Message 3 of 26
(3,589 Views)

Please start another topic about your PID question.  The purpose of the Forum is to not only help you, but to help other Forum readers who have a similar question ("VISA", "PID Control", etc.) and who rely on searches of the Subject to find relevant topics.  The place for a wide-ranging discussion is with your personal LabVIEW Guru who can mentor you as your and her time permit.

 

Bob "Curmudgeon" Schor

Message 4 of 26
(3,582 Views)

@DDragos wrote:

Also, the configured block can be used just once at the beginning of the program right?


The VISA Configure Serial Port should be used once at the beginning of your application.  You can then use the VISA Resource wire to VISA Write and VISA Read all you want.  Also, do make sure you are closing your port at the end.

 


@DDragos wrote:

I fixed that problem just by checking if the value is 0, then I don't send the data to the graph.


That is not a good solution.  What if your instrument actually did measure a 0?  That would be valuable data that was lost.  I go back to my initial recommendation: always do the reading of the temperature and then conditionally do the other command.

 


@DDragos wrote: About the point number 2, can you be more specific regarding what part of my VI you are speaking about?

Well, there is only 1 case structure in your VI.  And both cases of that case structure are identical except which command is actually to be sent.  So you could save yourself a lot of time and future effort by moving everything except the parts that are different (the determination of the command) to be outside of the case structure.  And since you are just switching between two string values, you could just use the Select function to make it even more clear what is happening.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 26
(3,573 Views)

 @

 

 

 

0 Kudos
Message 6 of 26
(3,546 Views)

You are not serializing properly: this way the 'read' command and the 'set' command may be executed in parallel. Instead, wire the VISA Resource out of the Read function to the Write functions of the 'set' command.

Furthermore, I believe that the module will give an acknowledge answer: you must catch this answer (and check that all went OK), otherwise during the next loop you will read this answer instead of the temperature.

Last, if you move the read buffer indicator inside the loop, you will be able to see all answers from the module.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 7 of 26
(3,537 Views)

I did the suggested changes, but even before this, when I am trying on the hardware, I get an error every time I am using the configuration VISA block. My first version of this VI without the configuration and the ugly case structures is still working perfect and responsive. I remember I had the same problem with the configuration block when I first tried to use VISA for communication and that is the way I didn't have it in my initial VI. The close block is there so I have no idea what I am doing wrong when I am using the configuration block.

 

Acknowledge answer? For the set command I think the only response is a ">" character.  You have a good point because I think that response was making the graph go to 0 when I was using the 'set' function.

 

I know that is correct to use the configuration block, but for me is just making things worse.

 

 

P.S. after a bit of testing, the problem with the graph dropping to 0 when i am using the 'set' command is still there.

Download All
0 Kudos
Message 8 of 26
(3,533 Views)

I cannot understand why the configuration vi is not working. You may try the following.

If you right-click on the vi, you will have the possibility to show the Polimorphic VI Selector (check it in Visible Items).

Change the selection to Serial Instr instead of simple Instr. You will need to recreate the VISA resource name control, though, because the wire will be broken.

To be honest, I never understood what's exactly the difference between the two versions, apart of the Class name of the input VISA control.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 9 of 26
(3,510 Views)

No change, the system reacts the same way, with the error( -1073807253 ) starting from the READ block of VISA. Also when I try to send the 'set' command, everything brakes and is not working anymore.

 

Also it looks like when I am using the Highlight Execution, everything works fine. Maybe a delay is necessary somewhere or something like that. I implemented a small delay of 35ms in my original VI so the system has time to read the data before sending the command again.

0 Kudos
Message 10 of 26
(3,507 Views)