LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial port monitoring loop

Hi,
 
     I working on a monitoring system that uses a serial port. So far what I have done is create a state machine which is just a case statement in a while loop. I added VISA Read and VISA Write in the state machine. Is it okay to use shift registers for the VISA resource name and error in?
0 Kudos
Message 1 of 6
(3,417 Views)

 Are you initializing the serial port out side of the main loop?  If you are you don't need the shift registar.

Don't forget to close your port when your loop stops.

As for the error handling, it all depends on how you using the error to stop your loop.

Good Luck

Message Edited by arvin labrat on 12-13-2006 10:57 AM

0 Kudos
Message 2 of 6
(3,410 Views)
Arvin,
 
     I do initialize the serial port outside of my state machine. I can read in the first entry. However, it keeps timing out afterwards. I tried playing with the values but no luck. Is there another way?
0 Kudos
Message 3 of 6
(3,398 Views)

Use the Bytes at Port function to see if there is something to read before you attempt to read.  You can put this function in a while loop.  Exit the loop on any of 3 conditions:  bytes at port reports more than 0 bytes, an error occured, or the iteration terminal got larger than a certain number (timeout).  Don't forget to put a small delay in the loop so that the CPU doesn't get tied up.  If you get timeouts, then your serial port is not receiving anything.  Check what you are sending to ensure it is the right command to cause a response.

Also, I usually wire the error wires to a shift register in the main while loop of a state machine.  This way, errors get propogated to the next state.  You have to put code to handle the errors, and perhaps exit the loop upon error.

- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 6
(3,385 Views)

What kind of instrument are you connected to and how is your state machine set up? Do you do a write before every read or is the instrument set up to constantly write without getting a request? How are you determining the number of bytes to read?

If you could post the VI you've written and the make and model of instrument, that would help someone diagnose your problem.

0 Kudos
Message 5 of 6
(3,385 Views)
Tbob,
 
       I will try it your way. If that doesn't work, I will post the code up.
 
Thanks
0 Kudos
Message 6 of 6
(3,369 Views)