I hope you are OK with me posting here. We use Rad Studio (Delphi) as a
programming language but connect to the phidgets.NET.dll as we are uplifting
our code to Phidget22. We are currently on version 1.1.0.30 but have also
tested on 1.1.0.32. The 1045 Temperature phidget is plugged directly into
a pc
I'm having difficulty getting the on change event for the 1045. When we set
everything up we get one on change event fired off but no changes thereafter.
I've put an iteration count on the form as well as breakpoints inside the
event handler but still only the one initial event.
Our minimum reproduceable code is:-
Code: Select all
procedure TForm1.btnTempClick(Sender: TObject);
begin
Try
//Zero the iteration count
iter:=0;
//Create and connect our 1045 object
phTemp:=TTemperatureSensor.Create();
phTemp.TemperatureChange:=Self.phTempTemperatureChange;
phTemp.Attach:=Self.phTemperatureAttach;
phTemp.DeviceSerialNumber:=424905;
phTemp.IsLocal:=True;
phTemp.IsRemote:=False;
phTemp.Open(250);
if phTemp.Attached = True then
lblAttach.Caption:='Attached';
Except
On e:Exception do
ShowMessage(e.Message);
End; {Try}
end; {btnTempClick}
{*}
procedure TForm1.phTemperatureAttach(sender: IClrBaseObject; e: IAttachEventArgs);
begin
//Enable our timer to update the display
tTemp.Enabled:=True;
phTemp.TemperatureChangeTrigger:=0;
phTemp.DataInterval:=phTemp.MinDataInterval;
end;
procedure TForm1.phTempTemperatureChange(sender: IClrBaseObject; e: ITemperatureSensorTemperatureChangeEventArgs);
begin
Try
//Set our variable depending on the channel
If (Sender as TTemperatureSensor).Channel = 1 Then
Self.dAmbient:=(Sender as TTemperatureSensor).Temperature
Else
Self.dIRTemp:=(Sender as TTemperatureSensor).Temperature;
//Increment count so we can see how many change events happened
inc(iter);
Except
On e:Exception do
Begin
ShowMessage(e.Message);
tTemp.Enabled:=False;
End;
End; {Try}
end; {phTempTemperatureChange]
{*}
procedure TForm1.tTempTimer(Sender: TObject);
begin
tTemp.Enabled:=False;
lbl1.Caption:='Direct: ' + FloatToStr(self.dIRTemp);
lbl2.Caption:='Ambient: ' + FloatToStr(self.dAmbient);
lblIteration.Caption:='Iterations: ' + IntToStr(iter);
tTemp.Enabled:=True;
end; {tTempTimer}
Many thanks,
Mark.