LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with serial transmission

Hi - I'm trying to do something very simple, but my lack of knowledge regarding LabVIEW is holding me back. I have a while loop that is listening to the serial port, waiting for some specific data. It checks for a new byte every thousandth of a second. This all works very well.
 
Now I want to make a seperate while loop for sending data over the serial port. Specifically, I want to read in data from a joystick, format it into a string, and send that formatted string twice per second. So I made a while loop outside of the receive while loop, and put my code in there. Problem is, it only runs when the rx loop exits. The code seemed to work just fine from within the rx loop, but it was sending much too quickly. So I guess I'm not sure about how to do this. Somehow I need to have two loops running simultaneously - two threads, if you will.
 
Can anybody tell me how to do this? I've attached my block diagram as well as the vi.
 
Thanks!

Message Edited by mnoone on 03-08-2007 02:49 PM

Download All
0 Kudos
Message 1 of 6
(3,163 Views)
LabVIEW is a dataflow programming language. You don't have two separate while loops. Your second while loop is connected by data (the VISA Resource and the error cluster) from the first loop to the second. Because the data has to be present before a function will start, your second loop will not start until the first loop finishes and passes the data to the second loop. You also wire the stop button to the conditional terminal in the second loop and what happens is the true condition to stop the first loop is passed to the second loop so it only will iterate one time and then stop. Make them truly independent by not having any wires between them.
0 Kudos
Message 2 of 6
(3,150 Views)
Hi - Thanks for the quick response! I guess I'm not sure about a couple things though. So do I have a seperate "configure serial port" vi for the tx loop, or do I wire the two together? Similarly, how would I wire the VISA close vi? Lastly - is it possible to have a single stop button that shuts off both loops, or is that not possible?
 
Thanks!
 
-Mike

Message Edited by mnoone on 03-08-2007 03:18 PM

0 Kudos
Message 3 of 6
(3,145 Views)

No, you would only have a single configure serial port just like you have now. You just wire the output of that to the separate while loops. You can pick which ever loop you want to have the VISA Close. Again, you only need one. Yes, you can stop both loops with a single button. There are actually several ways do do it. A simple way in your case is to have a local variable of the stop button in the second loop. You can't create a loca from a Boolean that is set to a latch action, so set the front panel Stop to Switch Until Released for example.

Message Edited by Dennis Knutson on 03-08-2007 02:38 PM

0 Kudos
Message 4 of 6
(3,137 Views)

Hi Dennis - I have just tried to implement your method, and it seems to *mostly* work. Specifically, I have a string comming in once every second from the serial port. That is a constant. Like I said earlier, I'm attempting to send out a command twice per second over the serial port. Every time this command is received the device at the other end of the serial port sends back a simple "OK". So by looking at how many "OK"s I get compared to how many full strings are sent I can see what percentage of the commands are getting through. Unfortunately, it seems that only about 50% of the messages are getting through. I'm looking into whether it could potentially be an error at the other end, but I don't think that's likely as I've never run into this problem before. Do you see anything that could be causing a problem like this?

 

Thanks!

 

-Mike

Download All
0 Kudos
Message 5 of 6
(3,125 Views)
You are looking for the 'OK' in the first loop where you are doing all of the parsing? Or did you add a read to the second loop? If it's the first case, then you could try setting the VISA Read and Write for Synchronous operation. You can do that by just right clicking on the functions.
0 Kudos
Message 6 of 6
(3,116 Views)