Re: Is polling within an INPUT statement possible?
Posted in 1996
I don't think the solution given below by Richard Spitz helps. His question was: : The problem is that :I need to be able to trap keystrokes to allow the user to change :the box type, product code ... Does anyone know how to do this? :My knowledge of C is rather limited so I would prefer an Informix :solution if possible. This would be while the scale_polling_function() is executing. You basically have two options: 1. Write a C function that will only poll to check if there is a weight and return immediately. Make a loop in 4GL that keeps calling this function until there is a weight returned. Test for int_flag inside this loop so the user can interrupt it with the interrupt key, enter any extra data and go into the loop again when done (or use any allready returned weight if possible). This is not a good solution as it would eat CPU time continously in the loop. You may put a sleep 1 inside the loop to help some. The C function may however be reasonably simple. 2. Extend your C function to handle the interrupt. This is the good way to do it, but requires someone to help you that knows C programming well. I don't know of a way to do this in 4GL without a C function. There is no "input from devicename" statement or function in 4GL. spitz@GANS2X.ana.med.uni-muenchen.de (Richard Spitz) wrote: :Peter B. Olson (pbolson@intergate.bc.ca) wrote: :: I am using Informix 5.0SE on an RS-6000 to develop an application :: that automatically weights boxes put on a scale. The program :: calls a C function to poll a weight scale until the :: motion sensor says that the box weight has settled. The weight :: is then returned to the Informix program which then updates a table :: and then returns to scale the next box. :I see no reason why this shouldn't work. You do have to write a C function :that does the polling of the scale and returns the weight value. Then :from within your INPUT statement (I assume you mean 4GL), you could :do the following: :INPUT ..... : ... : ON KEY (F10) ### OR ANY OTHER KEYSTROKE YOU WANT : IF infield(weight_field) : CALL scale_polling_function() RETURNING weight_value : IF weight_value < 0 THEN ### RETURN NEG. VALUE AS ERRORCODE : ERROR "A WEIGHING ERROR HAS OCCURED" : ELSE : DISPLAY weight_value TO weight_field : END IF : END IF : ... :END INPUT :Of course, you could also call scale_polling_function inside a BEFORE :FIELD section or something else, whatever suits your needs best. :As for the calling conventions for C functions inside 4GL programs, look :up the 4GL reference manual, they are explained there in great detail. :Hope this helps, :Richard :-- :+----------------------------+-------------------------------------------+ :| Dr. Richard Spitz | INTERNET: spitz@ana.med.uni-muenchen.de | :| EDV-Gruppe Anaesthesie | Tel : +49-89-7095-3413 | :| Klinikum Grosshadern | FAX : +49-89-7095-8886 | :| 81366 Munich, Germany | | :+----------------------------+-------------------------------------------+ Nils.Myklebust@ccmail.telemax.no NM Data AS, P.O.Box 9090 Gronland, N-0133 Oslo, Norway My opinions are those of my company