LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how can I use interupts in Labview

void main() {
while(1) { // the program wil work forever
if( button_Send == true) // the program wil execute send if the 'send button' is true
send();
else // if the button is false the program will read
read();
}
}

void serial() {
blabla...
}

void read() {
wait for character...
blabla...
}



this is what I made but as you might understand the program will hang in the read loop if theire is no character
to receive. this is what I had in mind but how can I do this in LV? I read something about vi prioreties...



anable interupt at serial port: // enable interupt
if( RXADRESS /= 0 ) { // chack if read buffer is not empty
void read(); // then read.
}

void main() {
while(1) { // the program wil work forever
if( button_Send == true) // the program wil execute send if the 'send button' is true
send();
else // if the button is false the program will wait for the
// send button or the interupt to accure
nothing..
}
}

void serial() {
wait for serial line to clear...
send char...
}

void read() {
if( RXADRESS /= 0 )
wait for character... // check if the read buffer is not empty
else
return.
}
0 Kudos
Message 1 of 5
(2,873 Views)
Hmmm I actualy fixed it by using polling... not as nice but useble.
a have another question though.

if you press the lightbold the process slows down a lot. in my program some values won't get through good enough in the fast way but do in the slow way... how is this possible?
0 Kudos
Message 2 of 5
(2,865 Views)
Hi Memmo,

I assume when you say "Lightbold", you mean the highlighting tool in the LAbVIEW development environment.....

I also don't know if you have now implemented the serial communication in LAbVIEW or some other language, but I'll assume you've implemented it in LAbVIEW.

A typical reason for code working in "slow-mode" and not at full speed is some kind of timing problem within the code.

One suggestion I have is to first check the serial receive buffer before reading from the serial port. You can do this using the "Bytes at serial port" property of the VISA connection (I strongly advse using VISA if you're not already doing this). By wiring the "number of bytes" in the buffer to the read function, you only actually read what's already there. This way you skip the endless serial reads when nothing is there to read.

Since you are now looping a serial buffer query instead of getting stuck in a serial read dead-end, you can incorporate a stop criteria in your read loop (Either a stop button or a timeout). This should solve the problem of your program becoming non-responsive in the case of no data being sent to the serial port.

As to why exactly you are not always receiving the correct text, without code to look at, it's kind of impossible to guess where the problem might be. If you could post a picture of your block diagram, I'm sure someone can help pretty quickly.

Hope this helps

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 3 of 5
(2,856 Views)
I'll post a picture once it's less of a mess. I'm having a hard time seeing it myself so ...
I get your point about the stuck at reading and sort of did something allike. about the timing, I think I'll try adding a wait.
0 Kudos
Message 4 of 5
(2,849 Views)
hmmm this timing error is harder then I thought... It's quite anoying that sometimes my program works fine and sometimes it doesn't with no real reason.
0 Kudos
Message 5 of 5
(2,839 Views)