Solved

Delphi, error message

Posted on 2008-06-12
20
326 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 37

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 37

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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

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 37

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 37

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 37

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
 

Author Comment

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

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 37

Expert Comment

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

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 37

Expert Comment

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

825 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