LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA&USB and separate window display


@ennng wrote:
Hello Blokk,
Thank you for your advice, I will keep learning and if any one have comment please do so.
The code works fine for me and received data successfully, just I need to add more functionality.

Most of us have probably never used the "low-level" VISA functions that you are using in your code, as we are already using "normal" VISA devices.  Kudos to you for venturing into Unknown Territory and getting some success.

 

However, Blokk is certainly correct that you would benefit greatly from spending the time with the LabVIEW Tutorials and learning some basic concepts, including the Big One, the idea of Data Flow.  Let's consider your Loop and see if it makes sense from a Data-Flow perspective:

  • Before entering the loop, you open VISA and get a Session Identifier that you bring into the loop after enabling notification of USB Interrupt Events.
  • Inside the loop, you wait for an Event, process it, get out an Analog value and a bunch of bits (which you break out as 8 separate Boolean Indicators, instead of the more-compact Array of Booleans).
  • You then close the VISA Session, stopping the loop if there is an Error.  Let's assume there is no Error, and the loop ends.
  • You then do it again, but now the Session Identifier (however that is represented) should be indicating a Session that you just closed!  I would expect this to give an immediate error.

In LabVIEW, there is a Data Flow paradigm of Initialize, Utilize, and Finalize (I'm making up cute-sounding names for mnemonic reasons).  Initialize refers to the steps you perform to get ready to do a repetitive task, such as acquiring data (plural).  Utilize are those steps where you actually acquire (or process), typically done in a loop multiple times until some Stop condition is reached, and Finalize are the "cleanup" steps that you perform to close and put away anything you created during Initialize.

 

There are two common ways of programming this paradigm -- "Straight-Forward" and "State Machine".  The first is similar to your code, but with Finalize moved outside the loop, like this:

Straight-Forward.png,

while the State Machine uses an Enum holding the States (here I named them Initialize, Utilize, and Finalize), a single State Machine Loop, variables passed from State to State via Shift Registers, and a Case Statement, also wired to a Shift Register and "fed" by the Enum designating the "next" state, controlling What Gets Done:

State-Machine.png.

Note that in this "view", you don't see the other States, but the Initialize State runs the Initialize sub-VI and puts Utilize on the "Next State" shift register, and Finalize funs the Finalize sub-VI and wires a True constant to the "Stop" tunnel (instead of wiring False for all the other States, I'm using "Use Default if Unwired" to do the same thing).

 

For this simple example, the State Machine may look "too complicated", but many situations have 5 or more "States", and this paradigm works really well.  One example is where you may have a complex Initializion (or Utilization) process that can be simplified by breaking up into several steps (or "States").

 

So if you spend some time and master some of the Basics, I have no doubt you'll be able to pull off this interesting (and, to my mind, ambitious) Project.

 

Bob Schor

 

P.S. -- the last word I wrote reminds me -- do you know about LabVIEW Project and the Project Explorer?  If not, look it up, as you should be using it.

0 Kudos
Message 11 of 21
(1,999 Views)

 

Thank you very much for you both Bob Schor and Bolkk, I hope we all achieve our goals and every one.

 

Kind Regards

ennng 

0 Kudos
Message 12 of 21
(1,986 Views)

Hello Blokk and every one,

 

I learnt something and pick good idea!

 

This is my VI design and as you suggested if I stuck in something I have to post the design to get some help!

 

Firstly, the design of VI detects the USB and open it, and then the VI send request to the USB as "TEMP1" if the VI receive the response message  "TEMP1" that mean we are in the right USB that we desire for, and then the USB send the actual data to the VI in order to display as seen in the second loop.
I have an error that I cannot figure out! please any help or suggestions I really appreciate it.

 

Regards

ennng

 

 

 

 

Download All
0 Kudos
Message 13 of 21
(1,953 Views)

You have a missing wire going into the compound arithmetic node.

 

Fixing that, and disconnecting the broken wire going into the VISA resource name out terminal fixed the broken run arrow.

 

(It does not look like your flat sequence structure is effectively doing anything with dataflow that the wires aren't already doing and should probably be eliminated.)

0 Kudos
Message 14 of 21
(1,946 Views)

Thank you Knight of NI,

 

I fixed the compound arithmetic node as you suggested but the VISA resource name out terminal is still broken and gave error that I don't know how to fix it.

The idea of the flat sequence structure is that to open the USB and wait for response from USB, if the right message received then this is the correct port and save this resource name out to the next stage of dataflow.

 

please see snippet figure.

 

 

0 Kudos
Message 15 of 21
(1,926 Views)

use a state machine with some timing. No need for sequence structure.

0 Kudos
Message 16 of 21
(1,923 Views)

 

Any example for my project please!

 

Kind Regards

ennng 

0 Kudos
Message 17 of 21
(1,919 Views)

At this point you do not need a state machine, neither a Sequence structure. You try to do it in a wrong way (that outer while loop is just silly). Why do not you implement my example I already gave you?? http://forums.ni.com/t5/LabVIEW/VISA-amp-USB-and-separate-window-display/m-p/3317630/highlight/true#...

 

You have a broken wire because you try to connect a Raw USB class ref to a VISA ref. Just right click on the wire coming out, and "Create indicator" will gave you the proper class.

 

edit: if you want more features and higher flexibility, you need to learn about State Machines and implement one. Google for it...and also learn LV from your available sources (online self-paced learning videos Core 1-2??).

0 Kudos
Message 18 of 21
(1,917 Views)

Hi Blokk,

 

Yes, I tried your code before and end up with the same error!

 

What confuse me about your code is that TEST DEV A which I knew is subVI and I guess in this one you opened the port and wait for  ID request or taken a measurement ? that part what I really need ( I need the LabView send "TEMP1" and wait for response from USB "TEMP1" if LabView got this message then this is the correct USB and then received dataflow from USB. 

 

Please Blokk don't use harsh word like silly! I am a sensitive person and just biggner and just keep learning 🙂 

 

 

Kind Regards

ennng

 

 

0 Kudos
Message 19 of 21
(1,910 Views)

Since I do not have your hardware, I cannot create the subVI for you. You should know how to program your hardware, and create that subVI which executed an ID request or test measurement to see whether the HW is present or not.

 

edit: instead of that subVI just try to open the actual port and make a read command, if an error comes back, handle it accordingly.

0 Kudos
Message 20 of 21
(1,906 Views)