-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShutterCD.pas
134 lines (102 loc) · 3.38 KB
/
ShutterCD.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
unit ShutterCD;
{
Optical shutter using old CDROM drive
ShutterCD unit
Version 11.09.2022
(c) Serhiy Kobyakov
}
interface
uses
Classes, SysUtils, dialogs, StdCtrls, Controls, Forms,
IniFiles,
// strutils,
addfunc,
ArduinoDevice;
type
{ ShutterCD_device }
ShutterCD_device = Object (_ArduinoDevice)
private
public
constructor Init(_ComPort: string);
destructor Done;
procedure Open;
procedure Close;
end;
implementation
constructor ShutterCD_device.Init(_ComPort: string);
var
MyForm: TForm;
MyLabel: TLabel;
// AppIni: TIniFile;
// iniFile: string;
UpperInitStr: string;
begin
// -----------------------------------------------------------------------------
// the device ID string with which it responds to '?'
theDeviceID := 'ShutterCD';
// -----------------------------------------------------------------------------
{
iniFile := Application.Location + theDeviceID + '.ini';
If not FileExists(iniFile) then
begin
showmessage('File ' + LineEnding + iniFile + LineEnding +
'procedure ''' + {$I %CURRENTROUTINE%} + ''' failed!' + LineEnding +
'File ' + iniFile + 'has not been found!' + LineEnding +
'Please fix it');
halt(0);
end;
}
// make a splash screen
// which shows initialization process
MyForm := TForm.Create(nil);
with MyForm do begin
SetBounds(0, 0, 450, 90); Position:=poDesktopCenter; BorderStyle := bsNone;
MyForm.Color := $00EEEEEE; end;
MyLabel := TLabel.Create(MyForm);
with MyLabel do begin
Autosize := True; Align := alNone; Alignment := taCenter; Parent := MyForm;
Visible := True; AnchorVerticalCenterTo(MyForm);
AnchorHorizontalCenterTo(MyForm); end;
MyForm.Show; MyForm.BringToFront;
UpperInitStr := 'Initializing ' + theDeviceID + ':' + LineEnding;
MyLabel.Caption:= UpperInitStr + 'Reading ' + theDeviceID + '.ini...';
sleepFor(50); // refresh the Label to see the change
// -----------------------------------------------------------------------------
// Read the device variables from ini file:
// AppIni := TInifile.Create(iniFile);
// device-specific paremeters:
// AppIni.Free;
// -----------------------------------------------------------------------------
// Use basic device initialization
MyLabel.Caption:= UpperInitStr + 'Connecting to ' + _ComPort + '...';
sleepFor(200); // refresh the Label to see the change
Inherited Init(_ComPort);
// Set the shutter into the start position as a last step of initialization
MyLabel.Caption:= UpperInitStr + 'Going to starting position...';
sleepFor(50); // small delay to refresh the Label
SendAndGetAnswer('i');
MyLabel.Caption:= UpperInitStr + 'Done!';
sleepFor(500); // refresh the Label just to see "Done"
MyForm.Close;
FreeAndNil(MyForm);
end;
destructor ShutterCD_device.Done;
begin
// I don't use the device answer here to improve reliability
// but SendAndGetAnswer returns '0' after 'o' if everything is OK
SendCharAndGetAnswer('o');
Inherited Done;
end;
procedure ShutterCD_device.Open;
begin
// I don't use the device answer here to improve reliability
// but SendAndGetAnswer returns '0' after 'o' if everything is OK
SendCharAndGetAnswer('o');
end;
procedure ShutterCD_device.Close;
begin
// I don't use the device answer here to improve reliability
// but SendAndGetAnswer returns '0' after 'c' if everything is OK
SendCharAndGetAnswer('c');
end;
end.