uMainForm.pas
上传用户:wang_niyan
上传日期:2022-05-07
资源大小:313k
文件大小:2k
- unit uMainForm;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ExtCtrls, StdCtrls, IniFiles, MPlayer, GIFImg;
- type
- TfrmMainForm = class(TForm)
- Timer: TTimer;
- Image1: TImage;
- procedure FormCreate(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure TimerTimer(Sender: TObject);
- private
- { Private declarations }
- Port: HWND;
- Configuration: TIniFile;
- public
- { Public declarations }
- end;
- var
- frmMainForm: TfrmMainForm;
- implementation
- uses sndkey32;
- function OpenSerialPort(APort: Byte;
- ABaudRate: DWORD;
- ADataSize, AParity, AStopBits: Byte): HWND; external 'Serial.dll';
- function ReadFromSerial(AHWND: HWND; ATimeOut: Cardinal): AnsiChar; external 'Serial.dll';
- procedure WriteToSerial(AHWND: HWND; C: Char; ATimeOut: Cardinal); external 'Serial.dll';
- {$R *.dfm}
- procedure TfrmMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- CloseHandle(Port);
- end;
- procedure TfrmMainForm.FormCreate(Sender: TObject);
- begin
- Randomize;
- Configuration := TIniFile.Create(Application.ExeName + '.ini');
- Port := OpenSerialPort(Configuration.ReadInteger('COM', 'Port', 1),
- Configuration.ReadInteger('COM', 'Baud', 9600),
- Configuration.ReadInteger('COM', 'DataSize', 8),
- Configuration.ReadInteger('COM', 'Parity', 0),
- Configuration.ReadInteger('COM', 'StopBit', 0));
- Timer.Enabled := True;
- end;
- procedure TfrmMainForm.TimerTimer(Sender: TObject);
- var
- c: AnsiChar;
- S: String;
- begin
- c := ReadFromSerial(Port, Timer.Interval);
- while c <> #0 do
- begin
- S := c;
- SendKeys(PChar(S), False);
- c := ReadFromSerial(Port, Timer.Interval);
- end;
- end;
- end.