Salus à tous ,

je viens vers vous car je suis confronter à un problème un peu bizaroid:

j'ai donc importer le composant puis installer ds un pck!

Donc il suffit de coller sur la fiche et ça roule ok , le constat et que si je met en veille le pc le timer est bien couper mais à la remise en route le Port com est occupé et obligé de debrancher le cable pour pouvoir etre reconnecté!

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
// Message from ShutDown Hibernate mode from PC
procedure TMainDlg.WMPowerBroadcast(var AMessage: TMessage);
const
       PBT_APMSUSPEND = 4;
  PBT_APMRESUMESUSPEND = 7;
begin
 
   case AMessage.WParam of
    PBT_APMSUSPEND:
    begin
      // save your DB stuff. NOTE: IIRC you are pretty limited in the time
      // you get to do this - 2 seconds ? may be the limit
        while  EKS_Busy do ;
        EKS_Scrutation.Enabled:=false;
        EKS1.Close;
        EKS1:=nil;
        SerialNumber:='000000000000000';
      //Timer1.Enabled:=false;
 
    end;
    PBT_APMRESUMESUSPEND:
    begin
     //EKS1.Open;
       EKS_Busy:=false;
       EKS_Scrutation.Enabled:=true;
      // restore your DB connection
    end;
  else
     // you're going to want to handle PBT_APMRESUMECRITICAL (XP and older systems) and PBT_APMRESUMEAUTOMATIC differently
     // IIRC you did not get notification of the suspend in this case
  end;
end;


Après pas mal de test j'ai testé directement sans passer par le composant visuel , donc par le EKSLib_TLB.pas
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
 
unit EKSLib_TLB;
 
// ************************************************************************ //
// AVERTISSEMENT
// -------
// Les types déclarés dans ce fichier ont été générés à partir de données lues
// depuis la bibliothèque de types. Si cette dernière (via une autre bibliothèque de types
// s'y référant) est explicitement ou indirectement ré-importée, ou la commande "Actualiser"
// de l'éditeur de bibliothèque de types est activée lors de la modification de la bibliothèque
// de types, le contenu de ce fichier sera régénéré et toutes les modifications
// manuellement apportées seront perdues.
// ************************************************************************ //
 
// $Rev: 52393 $
// Fichier généré le 28/02/2014 15:30:43 depuis la bibliothèque de types ci-dessous.
 
// ************************************************************************  //
// Biblio. types : C:\Program Files (x86)\Euchner\EKS_ActiveX_Module\x64\eks.ocx (1)
// LIBID : {62A51CD4-76C1-453D-B258-804D12988851}
// LCID : 0
// Fichier d'aide : 
// Chaîne d'aide : EUCHNER EKS ActiveX Module
// DepndLst : 
//   (1) v2.0 stdole, (C:\Windows\SysWOW64\stdole2.tlb)
// SYS_KIND: SYS_WIN32
// ************************************************************************ //
{$TYPEDADDRESS OFF} // L'unité doit être compilée sans pointeur à type contrôlé.  
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}
{$VARPROPSETTER ON}
{$ALIGN 4}
 
interface
 
uses Winapi.Windows, System.Classes, System.Variants, System.Win.StdVCL, Vcl.Graphics, Vcl.OleCtrls, Vcl.OleServer, Winapi.ActiveX;
 
 
// *********************************************************************//
// GUIDS déclarés dans la bibliothèque de types. Préfixes utilisés:        
//   Bibliothèques de types : LIBID_xxxx                                      
//   CoClasses              : CLASS_xxxx                                      
//   Interfaces DISP        : DIID_xxxx                                       
//   Interfaces Non-DISP    : IID_xxxx                                        
// *********************************************************************//
const
  // Versions mineure et majeure de la bibliothèque de types
  EKSLibMajorVersion = 1;
  EKSLibMinorVersion = 0;
 
  LIBID_EKSLib: TGUID = '{62A51CD4-76C1-453D-B258-804D12988851}';
 
  IID__IIntEKS: TGUID = '{53F17437-8943-4A11-90F6-A693C528C0E2}';
  DIID__IEKSEvents: TGUID = '{B7D0AAE7-6231-4B23-AA7C-9BB4E0019471}';
  IID_IEKS: TGUID = '{B03F0884-FF17-45D5-9F04-56207D7CAF5F}';
  CLASS_EKS: TGUID = '{64CAE8A8-3CB8-4929-A90F-57499A6E83F3}';
 
// *********************************************************************//
// Déclaration d'énumérations définies dans la bibliothèque de types                    
// *********************************************************************//
// Constantes pour enum Baudrate_def
type
  Baudrate_def = TOleEnum;
const
  EKS_BAUD_9600 = $00002580;
  EKS_BAUD_28800 = $00007080;
 
// Constantes pour enum KeyType_def
type
  KeyType_def = TOleEnum;
const
  EKS_KEY_READWRITE = $00000001;
  EKS_KEY_READONLY = $00000008;
 
// Constantes pour enum KeyState_def
type
  KeyState_def = TOleEnum;
const
  EKS_KEY_IN = $00000001;
  EKS_KEY_OUT = $00000002;
  EKS_KEY_OTHER = $00000003;
 
type
 
// *********************************************************************//
// Déclaration Forward des types définis dans la bibliothèque de types                     
// *********************************************************************//
  _IIntEKS = interface;
  _IIntEKSDisp = dispinterface;
  _IEKSEvents = dispinterface;
  IEKS = interface;
  IEKSDisp = dispinterface;
 
// *********************************************************************//
// Déclaration de CoClasses définies dans la bibliothèque de types        
// (REMARQUE: On affecte chaque CoClasse à son Interface par défaut)      
// *********************************************************************//
  EKS = IEKS;
 
 
// *********************************************************************//
// Interface :   _IIntEKS
// Indicateurs : (4416) Dual OleAutomation Dispatchable
// GUID :        {53F17437-8943-4A11-90F6-A693C528C0E2}
// *********************************************************************//
  _IIntEKS = interface(IDispatch)
    ['{53F17437-8943-4A11-90F6-A693C528C0E2}']
    procedure Fire_OnKey; safecall;
    procedure Fire_OnRead; safecall;
    procedure Fire_OnWrite; safecall;
  end;
 
// *********************************************************************//
// DispIntf :    _IIntEKSDisp
// Indicateurs : (4416) Dual OleAutomation Dispatchable
// GUID :        {53F17437-8943-4A11-90F6-A693C528C0E2}
// *********************************************************************//
  _IIntEKSDisp = dispinterface
    ['{53F17437-8943-4A11-90F6-A693C528C0E2}']
    procedure Fire_OnKey; dispid 1;
    procedure Fire_OnRead; dispid 2;
    procedure Fire_OnWrite; dispid 3;
  end;
 
// *********************************************************************//
// DispIntf :    _IEKSEvents
// Indicateurs : (4096) Dispatchable
// GUID :        {B7D0AAE7-6231-4B23-AA7C-9BB4E0019471}
// *********************************************************************//
  _IEKSEvents = dispinterface
    ['{B7D0AAE7-6231-4B23-AA7C-9BB4E0019471}']
    function OnKey: HResult; dispid 1;
    function OnRead: HResult; dispid 2;
    function OnWrite: HResult; dispid 3;
  end;
 
// *********************************************************************//
// Interface :   IEKS
// Indicateurs : (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID :        {B03F0884-FF17-45D5-9F04-56207D7CAF5F}
// *********************************************************************//
  IEKS = interface(IDispatch)
    ['{B03F0884-FF17-45D5-9F04-56207D7CAF5F}']
    function Get_BaudRate: Baudrate_def; safecall;
    procedure Set_BaudRate(pVal: Baudrate_def); safecall;
    function Get_KeyType: KeyType_def; safecall;
    procedure Set_KeyType(pVal: KeyType_def); safecall;
    function Get_Port: WideString; safecall;
    procedure Set_Port(const pVal: WideString); safecall;
    function Get_PollingTime: Smallint; safecall;
    procedure Set_PollingTime(pVal: Smallint); safecall;
    function Get_StartAdress: Smallint; safecall;
    procedure Set_StartAdress(pVal: Smallint); safecall;
    function Get_CountData: Smallint; safecall;
    procedure Set_CountData(pVal: Smallint); safecall;
    function Get_BlockSize: Smallint; safecall;
    procedure Set_BlockSize(pVal: Smallint); safecall;
    function Get_LastState: Integer; safecall;
    function Get_Reading: WordBool; safecall;
    function Get_Writing: WordBool; safecall;
    function Get_Opening: WordBool; safecall;
    function Get_KeyState: KeyState_def; safecall;
    function Get_Data(index: Smallint): Smallint; safecall;
    procedure Set_Data(index: Smallint; pVal: Smallint); safecall;
    function Get_Version: WideString; safecall;
    procedure Set_Version(const pVal: WideString); safecall;
    function Get_Debug: WordBool; safecall;
    procedure Set_Debug(pVal: WordBool); safecall;
    function Open: WordBool; safecall;
    function Close: WordBool; safecall;
    function Read: WordBool; safecall;
    function Write: WordBool; safecall;
    function getData(index: Smallint): Smallint; safecall;
    procedure setData(index: Smallint; newVal: Smallint); safecall;
    property BaudRate: Baudrate_def read Get_BaudRate write Set_BaudRate;
    property KeyType: KeyType_def read Get_KeyType write Set_KeyType;
    property Port: WideString read Get_Port write Set_Port;
    property PollingTime: Smallint read Get_PollingTime write Set_PollingTime;
    property StartAdress: Smallint read Get_StartAdress write Set_StartAdress;
    property CountData: Smallint read Get_CountData write Set_CountData;
    property BlockSize: Smallint read Get_BlockSize write Set_BlockSize;
    property LastState: Integer read Get_LastState;
    property Reading: WordBool read Get_Reading;
    property Writing: WordBool read Get_Writing;
    property Opening: WordBool read Get_Opening;
    property KeyState: KeyState_def read Get_KeyState;
    property Data[index: Smallint]: Smallint read Get_Data write Set_Data;
    property Version: WideString read Get_Version write Set_Version;
    property Debug: WordBool read Get_Debug write Set_Debug;
  end;
 
// *********************************************************************//
// DispIntf :    IEKSDisp
// Indicateurs : (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID :        {B03F0884-FF17-45D5-9F04-56207D7CAF5F}
// *********************************************************************//
  IEKSDisp = dispinterface
    ['{B03F0884-FF17-45D5-9F04-56207D7CAF5F}']
    property BaudRate: Baudrate_def dispid 1;
    property KeyType: KeyType_def dispid 2;
    property Port: WideString dispid 3;
    property PollingTime: Smallint dispid 4;
    property StartAdress: Smallint dispid 5;
    property CountData: Smallint dispid 6;
    property BlockSize: Smallint dispid 7;
    property LastState: Integer readonly dispid 8;
    property Reading: WordBool readonly dispid 9;
    property Writing: WordBool readonly dispid 10;
    property Opening: WordBool readonly dispid 11;
    property KeyState: KeyState_def readonly dispid 12;
    property Data[index: Smallint]: Smallint dispid 13;
    property Version: WideString dispid 14;
    property Debug: WordBool dispid 15;
    function Open: WordBool; dispid 16;
    function Close: WordBool; dispid 17;
    function Read: WordBool; dispid 18;
    function Write: WordBool; dispid 19;
    function getData(index: Smallint): Smallint; dispid 20;
    procedure setData(index: Smallint; newVal: Smallint); dispid 21;
  end;
 
 
// *********************************************************************//
// Déclaration de classe proxy de contrôle OLE
// Nom du contrôle      : TEKS
// Chaîne d'aide : EUCHNER EKS ActiveX Module
// Interface par défaut : IEKS
// DISP Int. Déf. ?     : No
// Interface événements : _IEKSEvents
// TypeFlags            : (2) CanCreate
// *********************************************************************//
  TEKS = class(TOleControl)
  private
    FOnKey: TNotifyEvent;
    FOnRead: TNotifyEvent;
    FOnWrite: TNotifyEvent;
    FIntf: IEKS;
    function  GetControlInterface: IEKS;
  protected
    procedure CreateControl;
    procedure InitControlData; override;
    function Get_Data(index: Smallint): Smallint;
    procedure Set_Data(index: Smallint; pVal: Smallint);
  public
    function Open: WordBool;
    function Close: WordBool;
    function Read: WordBool;
    function Write: WordBool;
    function getData(index: Smallint): Smallint;
    procedure setData(index: Smallint; newVal: Smallint);
    property  ControlInterface: IEKS read GetControlInterface;
    property  DefaultInterface: IEKS read GetControlInterface;
    property LastState: Integer index 8 read GetIntegerProp;
    property Reading: WordBool index 9 read GetWordBoolProp;
    property Writing: WordBool index 10 read GetWordBoolProp;
    property Opening: WordBool index 11 read GetWordBoolProp;
    property KeyState: TOleEnum index 12 read GetTOleEnumProp;
    property Data[index: Smallint]: Smallint read Get_Data write Set_Data;
  published
    property Anchors;
    property BaudRate: TOleEnum index 1 read GetTOleEnumProp write SetTOleEnumProp stored False;
    property KeyType: TOleEnum index 2 read GetTOleEnumProp write SetTOleEnumProp stored False;
    property Port: WideString index 3 read GetWideStringProp write SetWideStringProp stored False;
    property PollingTime: Smallint index 4 read GetSmallintProp write SetSmallintProp stored False;
    property StartAdress: Smallint index 5 read GetSmallintProp write SetSmallintProp stored False;
    property CountData: Smallint index 6 read GetSmallintProp write SetSmallintProp stored False;
    property BlockSize: Smallint index 7 read GetSmallintProp write SetSmallintProp stored False;
    property Version: WideString index 14 read GetWideStringProp write SetWideStringProp stored False;
    property Debug: WordBool index 15 read GetWordBoolProp write SetWordBoolProp stored False;
    property OnKey: TNotifyEvent read FOnKey write FOnKey;
    property OnRead: TNotifyEvent read FOnRead write FOnRead;
    property OnWrite: TNotifyEvent read FOnWrite write FOnWrite;
  end;
 
procedure Register;
 
resourcestring
  dtlServerPage = 'Mes Composants';
 
  dtlOcxPage = 'Mes Composants';
 
implementation
 
uses System.Win.ComObj;
 
procedure TEKS.InitControlData;
const
  CEventDispIDs: array [0..2] of DWORD = (
    $00000001, $00000002, $00000003);
  CControlData: TControlData2 = (
    ClassID:      '{64CAE8A8-3CB8-4929-A90F-57499A6E83F3}';
    EventIID:     '{B7D0AAE7-6231-4B23-AA7C-9BB4E0019471}';
    EventCount:   3;
    EventDispIDs: @CEventDispIDs;
    LicenseKey:   nil (*HR:$80004002*);
    Flags:        $00000000;
    Version:      500);
begin
  ControlData := @CControlData;
  TControlData2(CControlData).FirstEventOfs := UIntPtr(@@FOnKey) - UIntPtr(Self);
end;
 
procedure TEKS.CreateControl;
 
  procedure DoCreate;
  begin
    FIntf := IUnknown(OleObject) as IEKS;
  end;
 
begin
  if FIntf = nil then DoCreate;
end;
 
function TEKS.GetControlInterface: IEKS;
begin
  CreateControl;
  Result := FIntf;
end;
 
function TEKS.Get_Data(index: Smallint): Smallint;
begin
  Result := DefaultInterface.Data[index];
end;
 
procedure TEKS.Set_Data(index: Smallint; pVal: Smallint);
begin
  DefaultInterface.Data[index] := pVal;
end;
 
function TEKS.Open: WordBool;
begin
  Result := DefaultInterface.Open;
end;
 
function TEKS.Close: WordBool;
begin
  Result := DefaultInterface.Close;
end;
 
function TEKS.Read: WordBool;
begin
  Result := DefaultInterface.Read;
end;
 
function TEKS.Write: WordBool;
begin
  Result := DefaultInterface.Write;
end;
 
function TEKS.getData(index: Smallint): Smallint;
begin
  Result := DefaultInterface.getData(index);
end;
 
procedure TEKS.setData(index: Smallint; newVal: Smallint);
begin
  DefaultInterface.setData(index, newVal);
end;
 
procedure Register;
begin
  RegisterComponents(dtlOcxPage, [TEKS]);
end;
 
end.
Puis dans mon Appli

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
type
 
  LPTEKS_Euchner = class
   class function Create:   IEKS;
   class function CreateRemote(const MachineName: string): IEKS;
  end;
 
  TMainDlg = class(TForm)
    Panel3: TPanel;
 
var
  MainDlg: TMainDlg;
   EKS1: IEKS;
implementation
 
{$R *.DFM}
 
uses uEKS_sheet, uTrayIconDesign,ComObj;
 
class function LPTEKS_Euchner.Create: IEKS;
const
 monGuid:string='{64CAE8A8-3CB8-4929-A90F-57499A6E83F3}';
begin
Result := CreateComObject(StringToGuid(monGuid)) as IEKS ;
end;
 
class function LPTEKS_Euchner.CreateRemote(const MachineName: string): IEKS;
const
 monGuid:string='{64CAE8A8-3CB8-4929-A90F-57499A6E83F3}';
begin
  Result := CreateRemoteComObject(MachineName, StringToGuid(monGuid)) as IEKS;
end;

En passant direct par le TLB plus de problème de port occupé quand le pc redemarre il a bien été close et il se reouvre , le pourquoi j'en ai aucune idée !




Ce pourquoi je poste c'est surtout que sans composant visuel je n'arrive pas à instancier l'evenement "Onkey" de la TEKS = class(TOleControl) ligne 231
J'ai accés uniquement à "IEKS = interface(IDispatch)" ligne 141

J'ai essayé pas mal de chose pour integrer cette event dans mon code mais sans succés peut-etre n'est pas posible depuis IEKS
Est-ce faisable au moins? est la question que je me pose, Si quelqu'un pourrait me le confirmer , ou si c'est faisable me donner un petit coup de pouce.
Merci d'avance
@+
Nicolas