Autor Beitrag
Ice
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114



BeitragVerfasst: Mo 24.06.02 15:55 
Hallo !
mit folgender Unit versuche ich die Com -Schnittstellen (RS232) einzustellen.
Ich kann die werte im Programm ändern, sie werden aber nicht an die Schnittstellen weitergegeben.
Kann mir jemand helfen?
Danke schonmal im voraus.
Marco
ausblenden volle Höhe Quelltext
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:
unit COM_EInstellungen;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,registry;

type
  TCOM_Dialog = class(TForm)
    COMbox: TGroupBox;
    COM1Button: TRadioButton;
    COM2Button: TRadioButton;
    Com3Button: TRadioButton;
    COM4Button: TRadioButton;
    EinstellungenBox: TGroupBox;
    BaudBox: TComboBox;
    DatenBox: TComboBox;
    ParitaetBox: TComboBox;
    StopBox: TComboBox;
    ProtBox: TComboBox;
    Baudrate: TLabel;
    Datenbits: TLabel;
    Paritaet: TLabel;
    Stopbits: TLabel;
    Protokoll: TLabel;
    OK: TButton;
    Abbrechen: TButton;
    Uebern: TButton;
    procedure COM1ButtonClick(Sender: TObject);
    procedure COM2ButtonClick(Sender: TObject);
    procedure Com3ButtonClick(Sender: TObject);
    procedure COM4ButtonClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure UebernClick(Sender: TObject);
    procedure OKClick(Sender: TObject);
    procedure AbbrechenClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  COM_Dialog: TCOM_Dialog;
  regist : Tregistry;
  Cport,b,d : integer;
  s : single;
  p,o   : string;
  x : pchar;

implementation

{$R *.dfm}

procedure TCOM_Dialog.COM1ButtonClick(Sender: TObject);
begin
 Cport := 1;
 X := 'COM1';
end;

procedure TCOM_Dialog.COM2ButtonClick(Sender: TObject);
begin
 Cport := 2;
 X := 'COM2';
end;

procedure TCOM_Dialog.Com3ButtonClick(Sender: TObject);
begin
 Cport := 3;
 X := 'COM3';
end;

procedure TCOM_Dialog.COM4ButtonClick(Sender: TObject);
begin
 Cport := 4;
 X := 'COM4';
end;

procedure TCOM_Dialog.FormActivate(Sender: TObject);
begin
 regist:=TRegistry.Create;
 regist.RootKey:=HKEY_CLASSES_ROOT;
 regist.Openkey('Delphin\Einstellungen',true);
 Cport := regist.ReadInteger('Comport');
 b := regist.ReadInteger('Baudrate');
 s := regist.ReadFloat('Stopbit');
 d := regist.ReadInteger('Datenbits');
 p := regist.ReadString('Parität');
 o := regist.ReadString('Protokoll');
 Baudbox.Text := inttostr(b);
 Stopbox.Text := floattostr(s);
 DatenBox.Text := inttostr(d);
 ParitaetBox.Text := p;
 ProtBox.Text := O;
 regist.Destroy;
 if cport = 1 then
  com1button.Checked := true;
 if cport = 2 then
  com2button.Checked := true;
 if cport = 3 then
  com3button.Checked := true;
 if cport = 4 then
  com4button.Checked := true;

end;

procedure TCOM_Dialog.UebernClick(Sender: TObject);
var Handle :THandle;
    dcb : TDCB;
    s1 : byte;
    OSVersion : TOSVersionInfo;
    cc : TCommConfig;
    hComm : hFile;
begin
 b := strtoint(Baudbox.Text);
 s := strtofloat(StopBox.Text);
 d := strtoint(Datenbox.Text);
 P := Paritaetbox.Text;
 O := ProtBox.Text;
 regist:=TRegistry.Create;
 regist.RootKey:=HKEY_CLASSES_ROOT;
 regist.Openkey('Delphin\Einstellungen',true);
 regist.WriteInteger('Comport',cport);
 regist.WriteInteger('Baudrate',b);
 regist.WriteFloat('Stopbit',s);
 regist.WriteInteger('Datenbits',D);
 regist.WriteString('Parität',P);
 regist.WriteString('Protokoll',O);
 regist.Destroy;
 Handle := CreateFile(X,GENERIC_READ OR GENERIC_WRITE,
                      0,
                      nil,
                      OPEN_EXISTING,
                      FILE_ATTRIBUTE_NORMAL OR FILE_FLAG_OVERLAPPED,
                      0);
 if s = 1 then s1 := 0;
 if (s = 1.5) then s1 := 1;
 if s = 2 then s1 := 2;
 OSVersion.dwOSVersionInfoSize:= SizeOf(OSVersion);
 FillMemory(@CC,SizeOf(CC),0);
 CC.dwSize:= SizeOf(cc);
 GetVersionEx(OSVersion);
 if (OSVersion.dwPlatformId=VER_PLATFORM_WIN32_NT) and (OSVersion.dwMajorVersion < 4) then
  BuildCommDCB('baud=9600 parity=N Data=8 stop=1',DCB)
 else
 begin
  GetDefaultCommConfig(x,cc,cc.dwsize);
  DCB :=CC.DCB;
 end;
 GETCOMMSTATE(handle,DCB);
 with DCB do
  begin
   BaudRate := B;
   ByteSize := D;
   Parity :=  p1;
   StopBits := s1;
  end;
 SETCommState(handle,DCB);


end;

procedure TCOM_Dialog.OKClick(Sender: TObject);
begin
 close;
end;

procedure TCOM_Dialog.AbbrechenClick(Sender: TObject);
begin
 close;
end;

end.


Code-Tags hinzugefügt. Tino
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mo 24.06.02 16:23 
Hi! :)

Versuchs doch einfach mal mit der TCommportDriver-Komponente, die gibts glaube ich bei Torry.

Cu,
Udontknow
Ice Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114



BeitragVerfasst: Mo 24.06.02 16:29 
Danke für den tip , aber wer oder was ist Torry und wo finde ich den/das?
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mo 24.06.02 16:38 
Oh... :oops:

Ist eine ziemlich bekannte Delphi-Seite mit vielen Komponenten:
Torry´s Delphi Pages: [url]www.torry.net[/url]

cu,
Udontknow
Ice Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114



BeitragVerfasst: Mo 24.06.02 16:47 
alles klar. Nochmals vielen dank.

Marco :P
Astraios
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 25



BeitragVerfasst: Mo 24.06.02 16:59 
Titel: zu Torry
Tach,

kurz zu Torry.net:

Kann es sein, dass die Seite abartig lahm ist? Ich komm da nie drauf...
Ice Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114



BeitragVerfasst: Mo 24.06.02 17:12 
:( Ja ich habe dasselbe Problem, ich versuche jetzt schon ne viertel stunde auf die seite zu kommen, sie hat sich aber immernoch nicht aufgebaut.
Torsten
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 160



BeitragVerfasst: Mo 24.06.02 17:18 
Moinsen!

Noch mal zu Deinem Code.
Meiner Meinung hach wird damit lediglich eine Diagnose der COM-Schnittstelle durchgeführt.

Ein ähnliches Beispiel ist in einem Buch von Andreas Kosch vorhanden.
Wenn Du Interesse hast, dann schicke ich Dir das gerne mal zu.

Grüße

Torsten
Ice Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114



BeitragVerfasst: Mo 24.06.02 17:21 
Ja das wäre nett, ich bin nämlich schon ziemlich verzweifelt.

meine E-Mail adresse:
Marco.Dennstedt@stud.tu-ilmenau.de
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Mo 24.06.02 17:23 
Titel: Re: zu Torry
Astraios hat folgendes geschrieben:
kurz zu Torry.net:
Kann es sein, dass die Seite abartig lahm ist? Ich komm da nie drauf...


Das ist der Hauptgrund aus dem ich sie so gut wie nie nutze. Leider ist mir auch kein Mirror bekannt.
Deshalb schlage ich dir als Alternative die DELPHI SUPER PAGE vor. Wegen der geschwindigkeit nehme ich immer den Mirror Aachen. Ob exakt diese Komponente drauf ist musst du gucken.

Gruß
Klabautermann
Ice Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114



BeitragVerfasst: Mo 24.06.02 17:31 
:DDanke Klabautermann ! funktioniert super. Genau diese komponenete ist nicht drauf habe aber einige andere gefunden die mir weiterhelfen könnten.
Marco
Alfons-G
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 307

Win XP Prof, Linux, Win 7
D5 Prof, D7 Architect, D2005 Architect, D2007 Architect
BeitragVerfasst: Di 25.06.02 00:03 
@Klabautermann:
Versuch's mal über [url=homepages.borland.com/torry/]Borland[/url] - da ist ein schneller Mirror.

Dann gibt es noch [url=www.delphipages.com]Delphi-Pages[/url] und [url=www.vclcomponents.com]VCL Components[/url]. Damit deckst Du einen guten Teil des Shareware- und Freewareangebotes für Delphi ab.

:idea:

_________________
Alfons Grünewald
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Di 25.06.02 00:10 
Hi Alfons-G,

danke für die URLs. Werde ich in meine Bookmarks aufnehmen. Abe probleme geeignete Komponenten zu finden habe ich selten. Besonders da ich mich mit dem Einsatz von fremtkomponenten zurückhalte. Was nicht bedeuten soll, dass ich keine nutze. Ich überlege vorher nur mehrmals ob sie wirklich sinvoll sind oder bloß Schnickschnack.

Gruß
Klabautermann