Autor Beitrag
Arne
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 29.07.10 16:40 
Servus zusammen,

ich habe eine singlethreaded Anwendung, die sich mit einem embedded Device per RS232 unterhält.
Die periodische Abfrage lasse ich mit einer TTimer Komponente laufen, d.h. per Button initiiere ich Login, damit wird der TTimer gestartet und fragt ab dann ständig Werte per RS232 ab. Das Protokoll ist PingPong, d.h das embedded Device reagiert nur auf Anfrage durch das Delphi-Prg. mit einer Antwort:
1.Kommando - 1.Antwort - 2.Kommando - 2.Antwort - 3.Kommando - 3.Antwort...
Ich bin bisher davon ausgegangen, dass der Timer meine Delphi-Anwendung solange unterbricht, bis die Timerroutine fertig ist.
Also wie bei einer ISR.
Ein Logout iniitiere ich ebenfalls per Button.
Es kommt nun recht häufig vor, dass die Timerroutine ein Kommando absetzt und bevor die Antwort vollständig eintraf durch einen Druck auf den Logout-Button ein Logout-Kommando abgesetzt wurde. In dem Moment ist das PingPong hinüber: n.Kommando - n+1.Kommando - Müllantwort.
Somit habe ich ein Sychronisationsproblem. TCriticalSection funktioniert wohl nicht, da Hauptapp. und TTimer auf demselben Thread arbeiten.
Hat jemand eine Idee, wie ich das synchronisiert bekomme?

Thanx, Arne
platzwart
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1054
Erhaltene Danke: 78

Win 7, Ubuntu 9.10
Delphi 2007 Pro, C++, Qt
BeitragVerfasst: Do 29.07.10 16:56 
Pseudocode:

OnTimer:
begin
// Deaktivieren
Timer.Enabled:= False;
ButtonLogout.Enabled:= False;

// PingPong
PingPong durchführen und auf Antwort warten

// Aktivieren
Timer.Enabled:= True;
ButtonLogout.Enabled:= True;
end;


Oder habe ich das Problem falsch verstanden?

_________________
Wissenschaft schafft Wissenschaft, denn Wissenschaft ist Wissenschaft, die mit Wissen und Schaffen Wissen schafft. (myself)
Arne Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 29.07.10 17:20 
Dann flattert der Button ja ständig an/aus/an/aus... :wink:
Es wird alle 100ms ein Kommando abgesetzt und auf die Antwort gewartet.

Abgesehen davon: was bringt es in der OnTimer Routine den Timer ein-/auszuschalten?

ciao, Arne
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 29.07.10 17:39 
Das dürfte kein Timer/Thread-Problem sein, sondern ein Fehler in der Verwendung des Protokolls, oder? user profile iconNarses hat ein paar Tutorials zu Netzwerken geschrieben, in denen afaik bei den Grundlagen auch die Ursachen für Probleme geschildert werden, wie sie bei dir hier auftreten.

_________________
We are, we were and will not be.
platzwart
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1054
Erhaltene Danke: 78

Win 7, Ubuntu 9.10
Delphi 2007 Pro, C++, Qt
BeitragVerfasst: Do 29.07.10 17:42 
OnButtonLogoutClick:
begin
Logout:= True;
end;

OnTimer:
begin
PingPong;

if(Logout)then
begin
Timer.Enabled:= False;
Logout:= False;
end;
end;

_________________
Wissenschaft schafft Wissenschaft, denn Wissenschaft ist Wissenschaft, die mit Wissen und Schaffen Wissen schafft. (myself)