The information contained here are property of DIGITAX Automotive Electronics Italy, and extremely confidential. Any disclosure, copying, distribution to third
party is strictly prohibited.
47
3.
AITP (Odometer)
This application shows how to use AITP to interact with the odometer. You can ask odometer status,
set the automatic odometer trigger and it shows the odometer data as these arrive from the AITP.
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.Odometer
{
//simple application that shows how to interact with the odometer using the aitp
public
partial
class
OdometerTest
:
Form
{
//aitp instance
Aitp.Wrapper41.
AitpCore
_aitp =
new
Aitp.Wrapper41.
AitpCore
();
//odometer object
Aitp.Wrapper41.AitpObjects.
OdometerData
_odom;
public
OdometerTest()
{
InitializeComponent();
this
.C=
new
CancelEventHandler
(OdometerTest_Closing);
//init aitp in MDT/MCU "COM4:" 19200 on ForceOne "COM3:" 38400
_aitp.AITPInit(
"COM3:"
, 38400);
_aitp.EvAITPOdometerT=
new
Aitp.Wrapper41.
AitpCore
.
delAITPActivateOdometerTrigger
(_aitp_EvAITPOdometerTrigger);
//init odometer callback
_aitp.AITPInitOdometer();
}
void
OdometerTest_Closing(
object
sender,
CancelEventArgs
e)
{
//release aitp
_aitp.AITPRelease();
}
void
_aitp_EvAITPOdometerTrigger(Aitp.Wrapper41.AitpObjects.
OdometerData
od)
{
_odom = od;
UpdForm();
}
private
delegate
void
delUpdForm
();
private
void
UpdForm()
{
if
(InvokeRequired)
{
this
.BeginInvoke(
new
delUpdForm
(UpdForm));
return
;
}
//update text
tbMeters.Text = _odom.MetersFromReset.ToString();
tbPulses.Text = _odom.PulsesFromReset.ToString();
tbSpeed.Text = _odom.RealTimeSpeed.ToString();
tbSeconds.Text = _odom.SecondsFromReset.ToString();
tbConst.Text = _odom.WheelCodePulsesKm.ToString();
}
private
void
btReadOdom_Click(
object
sender,
EventArgs
e)
{
_aitp.AITPAskOdometerData(cbReset.Checked);
}
private
void
cbAutoTrig_CheckStateChanged(
object
sender,
EventArgs
e)
{
if
(cbAutoTrig.Checked)
{
_aitp.AITPSetOdometerTriggerParams(3, cbReset.Checked);
}
else
{
_aitp.AITPSetOdometerTriggerParams(0, cbReset.Checked);
}
}
private
void
cbReset_CheckStateChanged(
object
sender,
EventArgs
e)
{
if
(cbAutoTrig.Checked)
{
_aitp.AITPSetOdometerTriggerParams(3, cbReset.Checked);
}
else
{
_aitp.AITPSetOdometerTriggerParams(0, cbReset.Checked);
}
}
}
}