02-07-2011 04:35 AM
Hi,
Straight away to problem that i am using serial communication in labview with microcntroller. Any how, whenever i connect the USB then Labview detects the port and do the communication. But in the mean process if i press the RESET (USB lost) button on microcontroller then Serial visa block get the error and program continues to generate final error with code. By the way when ever this happens i want confirm the user that either USB is disconnected or RESET is pressed. Also if the user reconnect the USB back then program should work as usually. Even i tried with error display VI's in programming menu but i hope thats wrong way. At last I want to rectify two things 1) if the RESET is pressed in midway then it should display an user noticable message. 2) If USb disconnected by unknown person then what can i do in that situation.
I am using LABVIEW 2009. Please help me.
Solved! Go to Solution.
02-07-2011 10:11 AM
If I understand this correctly... You have a hardware reset button that is tied to you microcontroller, right?
If you reset the microcontroller during communication I'd expect you'll get an error because VISA won't be able to communicate with it anymore. In that way, pressing the reset button and USB being disconnected aren't that different, correct?
As far as what you want to rectify:
1. If you press the reset button when this VI is running don't you get get an error message with your existing code? When I use a USB to serial device I have with this VI I get an error message when I disconnect SUB. I know that's not quite the same as pressing the reset button (pin) but I don't have access to that at the moment. Whenever you loose communication your error handler VI should pop up a message. Is there something different happening that is preventing you from getting an error code?
2. If someone disconnects the USB then your program will pop an error up. I'd image it will be up to the person running your code to exit, plug the USB back in, and restart your program. Do you want something different to happen?
Additionally, you should work on your pogram flow. The top level VI quit when there was an error, but the overall program did not exit because it was waiting for your parallel event structure to execute. A few things about your program flow:
1. Is there a reason you are repeatedly opening and closing your serial communication? I'd strongly recommend doing both of these operations only once. Initialize the port at start up and close the port when you quit.
2. You should have a way to make your parallel loop with the event structure quit when the top level lop quits. Otherwise, your program will do nothing unless someone presses exit or regulated. This could get confusing as your program grows. You should look into using a state machine for better program flow and scalability. Read about state machines at http://zone.ni.com/devzone/cda/tut/p/id/3024.
Hope this helps!
02-07-2011 12:13 PM - edited 02-07-2011 12:15 PM
your expectation is correct and i know that error handler will pop up the message whenever error enter into that Vi. Even though I tried to generate an user message in error handler but that VI poping up the message everytime even thoug if the error is not coming in.
I want to display only a user message written by me not the labview generated error message with error code. How can i do that. Any way you understand my problem very well and hope for this help.
I studied that state machine article what you given but as i am new to labview and programming, so that i feel dificult and not understand well. can you give me a material that having clear explanation about state machines. I am eagerly waiting for that.
Thank you.
02-07-2011 12:24 PM
You could try something like the following. However, I'd recommend against it because I have found the LabVIEW generated errors are very useful for troubleshooting. Often times your own errors mask problems that will be easy to understand if you have the LabVIEW error code/message.