LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write data to serial port every two minutes

Hi,
   I use VISA-Write to write data to serial port. I want to write a byte every two minutes. What should I do?
  Thanks!
0 Kudos
Message 1 of 8
(3,374 Views)
You've got a palette full of time functions. There's the Elapsed Time function with a Boolean output called Time Has Elapsed. You could put your VISA code inside a case statement wired to this. You could use Tick Count or Get Date/Time in Seconds. Subtract current from start and when greater or equal to target time, do the write. If you have an event structure, you could use the timeout event.
0 Kudos
Message 2 of 8
(3,362 Views)
Since you are working with serial interface and have cycletimes of two minutes, softwaretiming (timing a loop which repeatedly calls the VISA-write) should be sufficient.
The next question you have to answer is: where do i get the data to write from and can the source of the data be used within the very same loop as the writing?

hope this helps,
Norbert B.
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 3 of 8
(3,362 Views)

Thank you! Here is my VI. Following is my anticipant result:

(1)write "A" (for example)to serial port at the beginning, then read serial port

(2)write "B"(for example)to serial port after 10 sec , then read serial port

(3) go to the step 1

PS: I need labview to do 3 steps automatically, do not need someone to click the button

0 Kudos
Message 4 of 8
(3,339 Views)
hengfo,

the problem you are running into is that you are closing the VISA-session inside of the loop. So your serial communication will work once, but not a second loop-iteration.

You should change your VI in a way like in the example you can find here.

hope this helps,
Norbert
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 5 of 8
(3,327 Views)

Thank you very much, Norbert! ?

Now my loop is in gear. But I still don't know how to write "A" first then write "B" after 10 sec. Any suggestion for me?

0 Kudos
Message 6 of 8
(3,318 Views)
hengfo,

that question is not connected to LV nor to VISA. Its more a systematic question....

So let's view at this a bit more abstract:
You want to "toogle" between two different messages sent to your interface. So you have to know:
- What was the last state i sent?
- When do i have top send the new state?
Even more abstract:
- How can i switch between the states?

Since the states are known before your program is executed, you can insert them into an array. Next, you have to read out the appropriate index from the array which contains your new state. Send the state and go to the next state. Propably you want to change timing, but that's easy too.

See attached screenshot for a possible solution:



hope this helps,
Norbert

Message Edited by Norbert B on 09-11-2007 07:57 AM

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 7 of 8
(3,307 Views)
Thank you, Norbert! Your train of thoughts is perfect.  You have been very helpful. I have realized my results.
0 Kudos
Message 8 of 8
(3,280 Views)