
The information contained here are property of DIGITAX Automotive Electronics Italy, and extremely confidential. Any disclosure, copying, distribution to third
party is strictly prohibited.
53
7.
Digital I/O (IPreShut)
This application shows how to use the Digital I/O library to monitor the IPreShut (digital value) that
becomes high (true) when Windows is shutting down. This feature is very important because makes
possible, for an application, to make a safe closure.
Sample code:
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
namespace
Digitax.Sample.DigitalIOTest
{
// simple application that cheks the Ipreshut digital value
public
partial
class
DigitalIOTest
:
Form
{
//DigitalIO Wrapper Instance
DigitalIO.Wrapper41.
DigitalIO
_digitalIO =
new
DigitalIO.Wrapper41.
DigitalIO
();
//ipreshut check tread
System.Threading.
Thread
ipreshutThread;
bool
stopExecuting =
false
;
public
DigitalIOTest()
{
InitializeComponent();
this
.C=
new
CancelEventHandler
(DigitalIOTest_Closing);
ipreshutThread =
new
System.Threading.
Thread
(
new
System.Threading.
ThreadStart
(CheckiPreShut));
ipreshutThread.Start();
}
void
DigitalIOTest_Closing(
object
sender,
CancelEventArgs
e)
{
stopExecuting =
false
;
if
(!ipreshutThread.Join(3000))
{
ipreshutThread.Abort();
}
}
private
void
CheckiPreShut()
{
bool
shuttingDown =
false
;
//check ipreshut every second
while
(!stopExecuting)
{
shuttingDown = _digitalIO.DGRead(DigitalIO.Wrapper41.
DGIndex
.IPRESHUT);
if
(shuttingDown)
{
UpdForm();
//safe exit from the thread
break
;
}
System.Threading.
Thread
.Sleep(1000);
}
}
private
delegate
void
delUpdForm
();
private
void
UpdForm()
{
if
(InvokeRequired)
{
this
.BeginInvoke(
new
delUpdForm
(UpdForm));
return
;
}
lblShutDownDetected.Visible =
true
;
}
}
}
Содержание Force One MDT
Страница 1: ...Force One MDT Technical Manual V 1 6...