Delphi, error message

hi all,

I encountered a problem While runing my program.  Namely program shows error message:'invalid driver handle failed' then hangs up.

In a brief. Program is supposed to send every 15 ms an impulse via digital output of advantech card (card im trying to communicate with). Impulse range is 1 to 2 ms. Basis of servo control.
Problem has something to do with Timer. when event is assigned to Timer -  problem occurs.
I cannot attach program files, guess i can send that only individually.


Thank you.
thrust8Asked:
Who is Participating?
 
MerijnBSr. Software EngineerCommented:
install eurekalog trial: www.eurekalog.com

It will provide a calltstack when the exception is thrown, you can post that here.
0
 
Geert GOracle dbaCommented:
what is the code for creating the timer ?
and attaching the event
0
 
thrust8Author Commented:
This is where you can download Main program (servo_new): http://www.megafileupload.com/en/file/69418/servo-new-zip.html
(wait 24 seconds to download)


And here is DO_SOFT program of howto communicate with advantech:
http://myfreefilehosting.com/f/8005f9598f_0.1MB

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Geert GOracle dbaCommented:
i don't have any time to look for a needle in a haystack ...

just paste the code where you are getting the error.
run in Delphi and check "Stop on Delphi exceptions"
0
 
thrust8Author Commented:
Truth be told, i dont know where im getting the error. Everythig compiles ok, right after running it shows the error.

this is Timer code:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if not update_running then updateservo;

end;

and this is updateservo procedure:

procedure TForm1.updateservo; {every 18 - 20 msec : see timer}
{var  myjoy: tjoyinfo; }
begin
if disableservocheck.checked then exit;
update_running := true;
{if stickbox1.checked then
begin

outvalue(1); {on}
delay(trackbar1.position*10);
outvalue(0);   {off}

outvalue(2); {on}
delay(trackbar2.position*10);
outvalue(0);   {off}

outvalue(4); {on}
delay(trackbar3.position*10);
outvalue(0);   {off}

outvalue(8); {on}
delay(trackbar4.position*10);
outvalue(0);   {off}

update_running := false;
end;

update_running is set as global variable
update_running: boolean;

how can i check 'stop on delphi exceptions'?
0
 
Geert GOracle dbaCommented:
menu Tools / Debugger options / Tab Language Exceptions

change the following :
this will make sure that when you do get an error in the routine,
update_running flag will be set correct

procedure TForm1.updateservo; {every 18 - 20 msec : see timer}
{var  myjoy: tjoyinfo; }
begin
  if disableservocheck.checked then exit;
  if not update_running then 
  begin
    update_running := true;
    try
      {if stickbox1.checked then
      begin
      ...
    finally
      update_running := false;
    end;
  end;
end;

Open in new window

0
 
thrust8Author Commented:
This is how i changed it:

procedure TForm1.updateservo; {every 18 - 20 msec : see timer}
{var  myjoy: tjoyinfo; }
begin
if disableservocheck.checked then exit;
if not update_running then
begin
update_running := true;
try

........

finally
update_running := false;
end;
end;
end;

and still nothing.
'Stop on delphi exceptions' was checked all the time.
0
 
Geert GOracle dbaCommented:
what do you mean with hang.
Can you pause the process in delphi after hangup ?

0
 
thrust8Author Commented:
Right after doubleclick on .exe file, the program shows that error message, and is idle, I cannot do anything with it, and need to close application outside Delphi.
I can pause it in delphi.
0
 
Geert GOracle dbaCommented:
what does the stack show ?
use Ctrl-F3

it maybe in a initialization section of one of the units
0
 
thrust8Author Commented:
Shows  'process is not accessible'
0
 
Geert GOracle dbaCommented:
lol, pause it first, then call stack
0
 
thrust8Author Commented:
my bad..

_RDTSC((2044583639, 10140))
_ReadTSC(???)
ReadTSC(???)
ReadCycles((4,3550977806e+13, 159, 4,3553012965e+13))
ReadSeconds((4,3550977806e+13, 159, 4,3553012965e+13))
delay(1470)
TForm1.updateservo
TForm1.Timer1Timer(???)
Servo
0
 
Geert GOracle dbaCommented:
does anything work if you change the routine delay to
use sleep(xxx) ?
0
 
Geert GOracle dbaCommented:
what i don't understand is, it looks like you want an accurate timer control
but you use 5 calls to accomplish this ?
you lose accuracy with each call ...

0
 
thrust8Author Commented:
sleep(xxx) changes nothing, tried that also.
5 calls, one for each servo. But I hope there is a better way to solve this. To update one servo at a time.

That program was originally designed to work with lpt. All i did was renewing HRTimer to todays standards and replaced outvalue procedure with the one i needed to communicate with advantech.
0
 
Geert GOracle dbaCommented:
um, i think debugging on your machine would be the solution
0
 
Geert GOracle dbaCommented:
What about creating a new application with just the code to send the impulse
and no fancy units like HRTimer ?

just simple procedure

you can then concentrate on justing getting this to work without bothering about all the rest.
Take it step by step

To narrow it down even more try and step through the code to see where it fails.
Maybe copy / paste the parts that work into another procedure ...
procedure TForm1.Button1Click(Sender: TObject);
begin
  // assuming a pulse is setting a bit high, wait ms and set it low again
  DoPulse(Device);
end;
 
procedure TForm1.DoPulse(Device: Handle; BitIndex: Integer);
begin
  OutValue(Device, BitIndex, 1);  // Set Bit high
  Sleep(100);
  OutValue(Device, BitIndex, 0);
end;

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.