Solved

Delphi, error message

Posted on 2008-06-12
20
317 Views
Last Modified: 2013-11-23
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.
0
Comment
Question by:thrust8
  • 10
  • 7
20 Comments
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 21767044
what is the code for creating the timer ?
and attaching the event
0
 

Author Comment

by:thrust8
ID: 21767098
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
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 21767220
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
 

Author Comment

by:thrust8
ID: 21767375
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
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 21767428
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
 

Author Comment

by:thrust8
ID: 21767504
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
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 21767613
what do you mean with hang.
Can you pause the process in delphi after hangup ?

0
 

Author Comment

by:thrust8
ID: 21767655
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
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 21767734
what does the stack show ?
use Ctrl-F3

it maybe in a initialization section of one of the units
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:thrust8
ID: 21767747
Shows  'process is not accessible'
0
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 21768378
lol, pause it first, then call stack
0
 
LVL 19

Accepted Solution

by:
MerijnB earned 250 total points
ID: 21768510
install eurekalog trial: www.eurekalog.com

It will provide a calltstack when the exception is thrown, you can post that here.
0
 

Author Comment

by:thrust8
ID: 21769895
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
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 21776806
does anything work if you change the routine delay to
use sleep(xxx) ?
0
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 21776826
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
 

Author Comment

by:thrust8
ID: 21776900
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
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 21777396
um, i think debugging on your machine would be the solution
0
 
LVL 36

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 250 total points
ID: 21810500
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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now