LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to define timeout for the process of a function

Hello all Labviewers:

I am designing a Labview software to scan and decode  QR codes. Used the NImax open and config functions out of a while loop and placed a QR function inside the while loop. Inside the while loop also there is a for loop embedded to process various ROIs. The only problem that I have faced is that while executing the program, the QR function looks for the QR code for about 1 to 2 seconds and this is impractical for my machine. There must be an adjustable timeout for the function to cut the process of the QR and send "NOT OK" as result instead of halting on the task. Are there any possibilities for me to make an adjustable timeout for this function or even any other function to cut the process on the task in the desired time ?

0 Kudos
Message 1 of 20
(4,603 Views)

I haven't used the specific IMAQ Read QR Code function that you are using, but I'm not surprised that it doesn't work "as you might expect" -- I think the code is doing "what you asked it to do", as opposed to "what you want it to do".

 

Let's ignore, for the time being, the For Loop that contains the Read QR Code function.  The rest of the code consists of displaying a continuous video image from a camera as some unspecified Frame Rate.  This While loop will run at the Frame Rate of the camera -- if the Camera is set for 10 FPS, each loop will last 100 msec before repeating.

 

Adding the For loop to Read QR Codes adds some additional processing, but doesn't affect the Camera's frame rate.  Let's say that once you establish the ROI for these video images, the time it takes to process however many ROIs you have configured takes 2 seconds.  Then the While loop will run every 2 seconds, and presumably you will be processing only a small subset of all of the Frames that your camera is acquiring.

 

Is this what you want to do?

 

Bob Schor

0 Kudos
Message 2 of 20
(4,566 Views)

Thanks a lot sir for giving my problem this time to answer. 

Actually in the nimax I have set the camera to trigger mode. It is waiting for my pulse to take a single frame. However the time between the frames vary and I have to be able to adjust the allowed time to process the qr to avoid interrupting the next frame. Mostly if the qr code is scannable, it takes about 30 milliseconds to scan and send the results. Thats why im looking for a solution to define a timeout for the FOR loop.

0 Kudos
Message 3 of 20
(4,554 Views)

@Lotfee wrote:

Actually in the nimax I have set the camera to trigger mode. It is waiting for my pulse to take a single frame. However the time between the frames vary and I have to be able to adjust the allowed time to process the qr to avoid interrupting the next frame. Mostly if the qr code is scannable, it takes about 30 milliseconds to scan and send the results.


One (minor) problem with setting attributes in MAX instead of in the Project or in the VI itself is that an examination of the code (meaning the VIs) does not reveal this "hidden" aspect.  Of course, you also didn't provide the code that showed how the trigger was being generated.

 

Your added comments, above, suggests that something may be mixed up in your logic.  I'm puzzled by the appearance of a For loop, which is looping through ROIs -- where do these ROIs come from, and why are there multiples of them?  You mention a trigger, but show no code where the trigger is defined or initiated.

 

Suppose you had a knowledgable colleague who could take a look at your problem.  Is this the only thing you would provide?  Wouldn't you also show her the rest of your program, perhaps provide some images from which you are trying to derive the QR codes, and explain how you defined the ROIs for your search?  So why are you "blindfolding" us?

 

Bob Schor
 

0 Kudos
Message 4 of 20
(4,540 Views)

Dear sir :

Its just about simplifying. Not blindfolding. Thanks for helps so far. The vi is a single vast chart which is not the point. I only have problem with the copied section. The trigger is mechanical. By a sensor on the machine. It causes the camera to grab a single frame. The grab is in while loop. Inside the while, for the number of ROIs , the for loop works. I will provide you also a screen shot of the front panel as soon as I got to the office. But as you see, we got far from the main issue which is how to define a timeout for a process.

0 Kudos
Message 5 of 20
(4,523 Views)

I don't understand the concept of a "timeout for the process of a function".  I think you have your "time" consideration backwards.  I'm not sure I understand how your Camera is set up to work, but this is what "makes sense" to me:

  1. You Snap a picture, and display it in an Image.
  2. You define an ROI on the Image.  When the ROI has been defined (and I'm not sure quite how you are defining the ROI, particularly if it is a multi-element ROI), you call the QR Read function.
  3. The QR Read posts its result, and you are now ready to repeat, going back to Step 1 unless you've terminated the Loop (a Stop button, so many images processed, so much time elapsed, an error occurred, some condition or conditions that you define.

The "TimeOut" is "as long as it takes" to do those three steps.  Because you (in principle) need to interact with every Image (to define ROI, read QR function, etc., i.e. Step 2), and you are not a robot, trying to "time" this human-dependent step seems silly (to me).

 

Bob Schor

0 Kudos
Message 6 of 20
(4,520 Views)

Good Day Sir,
Would you please confirm how were you able to verify that the Read QR function hangs for 1-2 seconds. What camera are you using and what is the current frame rate? I simulate the same function using a webcam with a little code modification to make the image a grayscale, define 12 ROIs and got no problem so far. I am able to have the whole run processed in less than a second.

0 Kudos
Message 7 of 20
(4,518 Views)

Sir, I need to define a time limit for the process of qr scanning function. As the function receives the image the time starts to count till my specified time such as 90 miliseconds. If the process of finding the qr were to take longer than 90 milliseconds, the qr functuin just skips the process to the next and sends zero instead of results.

0 Kudos
Message 8 of 20
(4,493 Views)

Thanks alot for spending time on my problem.

Actually as soon as I add the qr function to the loop it begins to halt. I have 4 of these loops simultaneously. That is why it begins to get slow. And if the rois have something like a qr in it, it starts to go slow.

By the way I also have used a time lapse and a shift register in the loop to calculate the time it takes. After inserting qr in the loop, time increased from 9 miliseconds to 1500.

The camera is an industrial one. Imaging source. 1280x960. 15fps. Y800. Monochrome.

0 Kudos
Message 9 of 20
(4,491 Views)

The industrial scanners have the option of timeout. After each scan we give the scanner the desired time limit like 200 miliseconds and if it could not find the code after 200miliseconds , the scanners sends a rejection command and gets ready for the next scan.

0 Kudos
Message 10 of 20
(4,488 Views)