|
このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。 |
program Demo3RS232;
var bTmp,bFrmRS232:byte;
begin {main}
令状(LCD,255); {(疑いを)晴らすs LCD}
repeat
if RS232_New_Byte then begin
read(RS232,bFrmRS232);
令状(LCD,bFrmRS232);
end;
until 4=5;
end.
If only Windows programming was so straightforward! (You may want to visit my Pascalite tutorial if the above isn't (疑いを)晴らす to you.)
部隊 DD28;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, 支配(する)/統制するs, Forms, Dialogs, StdCtrls;
type
TDD28F1 = class(TForm)
Button1: TButton;
手続き Button1Click(Sender: TObject);
手続き SendChar(sToSend:string);(***** 1 *)
私的な
{ 私的な 宣言s }
public
{ Public 宣言s }
end;
var
DD28F1: TDD28F1;
NumberWritten:dword; (***** 2 *)
sPhraseToSend,CommPort:string; (***** 3 *)
hCommFile:THandle; (***** 3 *)
c1:byte; (***** 3 *)
実施
{$R *.DFM}
手続き TDD28F1.SendChar(sToSend:string);
begin
CommPort := 'COM1'; (***** 4 start *)
hCommFile := CreateFile(PChar(CommPort),
GENERIC_WRITE,
0,
nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
WriteFile(hCommFile,
PChar(sToSend)^,
Length(sToSend),
NumberWritten,
nil); (***** 4 end *)
CloseHandle(hCommFile); (***** 5 *)
end;
手続き TDD28F1.Button1Click(Sender: TObject);
begin
sPhraseToSend:='実験(する)ing 1 2 3'; (***** 6 start *)
for c1:=1 to length(sPhraseToSend) do begin
SendChar(copy(sPhraseToSend,c1,1));
使用/適用.processmessages; (***** 6 end *)
sleep(10); (***** 7 *)
end;
end;
end.
(I'll try to give you more in the way of comments another time. For now, two things to 公式文書,認める....
program Demo3RS232;
var bTmp,bFrmRS232:byte;
begin {main}
repeat
bFrmRS232:=255;
if RS232_New_Byte then begin
read(RS232,bFrmRS232);
end;
if bFrmRS232<255 then begin
{delay(200); see below}
if bFrmRS232=102 {102 is code for "f"}
then write(RS232,'I saw an f') {no ; here}
else write(RS232,'I saw something other than f');
end;{not 255}
until 4=5;
end.
The に引き続いて SHOULD work!! with the above... but it doesn't yet, sigh. It RUNS... but it doesn't seem to 選ぶ up the message coming 支援する from the Pascalite. The Pascalite is working 罰金 with Hyperterminal. (And yes, I did remember to disconnect the Hyperterminal 関係 before trying to run the above.) I tried putting in the 延期する(200) remmed out in the Pascalite code above in 事例/患者 the 返答 from the Pascalite was appearing before the main PC was looking... but it didn't help.
部隊 DD29u1;
(*DOESN'T WORK... but NEARLY does.... I think!*)
(*Yes! I know this could be more elegant! その上に, it is "不正に written"
in a number of 尊敬(する)・点s. In particular, it is not very 強健な and fails to
会社にする/組み込む sundry 利用できる error (犯罪,病気などの)発見 and 扱うing 準備/条項s of
Windows. 改善する it... without obscuring the basic things it is trying to
illustrate... and send me the 改善するd 見解/翻訳/版!!*)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, 支配(する)/統制するs, Forms, Dialogs,
StdCtrls;
type
TDD29F1 = class(TForm)
buSendf: TButton;
buSendx: TButton;
Label1: TLabel;
Label2: TLabel;
手続き buSendfClick(Sender: TObject);
手続き buSendxClick(Sender: TObject);
手続き SendChar(sToSend:string);
手続き EstablishHandle;
機能(する)/行事 ReadStringFrmRS232:string;
手続き FormCreate(Sender: TObject);
私的な
{ 私的な 宣言s }
public
{ Public 宣言s }
end;
var
DD29F1: TDD29F1;
sPhraseToSend:string;
hCommFile:THandle;
c1:byte;
const ver='18 Apr 03';
CommPort = 'COM1';
実施
{$R *.DFM}
機能(する)/行事 TDD29F1.ReadStringFrmRS232:string;
(*hCommFile must be valid before this is called*)
var sTmp:string;
c1:integer;
chBuffer:array[0..255] of char;
NumberOfBytesRead : dword;
begin
if hCommFile=INVALID_HANDLE_VALUE then 出口;
if not ReadFile (hCommFile, chBuffer, sizeof(chBuffer),
NumberOfBytesRead, Nil) then
showmessage('Problem with ReadStringFrmRS232')
{ Better: Raise an exception } ; { <- semicolon IS needed here!}
{The program will go off and watch the RS-232 data source
for 後継の data. It will continue to watch (and collect
data as it appears) for a time 決定するd by the CommTimeouts
settings... thus you dont need to know in 前進する how many
bytes will be coming, nor does the connected 装置 need
to send a 旗 場内取引員/株価 the last byte.... though that
議定書 could be 会社にする/組み込むd on 最高の,を越す of the other
準備/条項s for signalling the end of the data.}
label2.caption:='Bytes seen: '+inttostr(NumberOfBytesRead - 1);
for c1:= 0 to NumberOfBytesRead - 1 do
sTmp:= sTmp+chBuffer[c1];
result:=sTmp;
end;
手続き TDD29F1.SendChar(sToSend:string);
(*hCommFile must be valid before this is called*)
var NumberWritten:dword;
begin
if hCommFile = INVALID_HANDLE_VALUE then
showmessage('Problem with SendChar')
{Better: raise an exception } ; (* <- 半分 結腸 IS needed here*)
WriteFile(hCommFile,
PChar(sToSend)^,
Length(sToSend),
NumberWritten,
nil);
end;
手続き TDD29F1.EstablishHandle;
var CommTimeouts : TCommTimeouts;
begin
hCommFile := CreateFile(PChar(CommPort),
GENERIC_READ or GENERIC_WRITE,
0,
nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0); {Delphi 2 helpfile said use "NULL" here,
and program 収集するd, but raised error when
it was run. Two 言及/関連s said use 0}
{Ever been 失望させるd by something that would not work when it
"should"? I spent about an hour tinkering with this program
with "generic_write or generic_write" (WRITE twice instead of
one read, one 令状) in the parameters above.....
ARGHH!!, as Snoopy would say.}
with CommTimeouts do
begin
{put cursor on 'CommTimeouts', 圧力(をかける) f1 to learn
about what the に引き続いて 明示する. The numbers here
are 天然のまま, and need consideration.... though they
MAY work for yoyu in your 状況/情勢! The '権利'
numbers depend on many things, 含むing the settings
in the 装置 you are communicating with. If the
numbers are too small, the Delphi program will not
"see" the 大(公)使館員d 装置. If they are too large,
the program will appear to hang while communicating....
If too large, they may also 干渉する with Windows'
proper 機能(する)/行事ing.... but may not.}
ReadIntervalTimeout := 0;
ReadTotalTimeoutMultiplier := 0;
ReadTotalTimeoutConstant := 1500;
WriteTotalTimeoutMultiplier := 0;
WriteTotalTimeoutConstant := 500;
end; {with}
if not SetCommTimeouts(hCommFile, CommTimeouts) then
showmessage('Problem with SetCommTimeouts')
{ Better: raise an exception } ; (* <- 半分 結腸 IS needed here*)
end;
手続き TDD29F1.buSendfClick(Sender: TObject);
begin
sPhraseToSend:='f';
EstablishHandle;
for c1:=1 to length(sPhraseToSend) do begin
SendChar(copy(sPhraseToSend,c1,1));
使用/適用.processmessages;
sleep(10);
end;
label1.caption:='hardcoded f'{ReadStringFrmRS232};
CloseHandle(hCommFile);
end;
手続き TDD29F1.buSendxClick(Sender: TObject);
begin
sPhraseToSend:='x';
EstablishHandle;
for c1:=1 to length(sPhraseToSend) do begin
SendChar(copy(sPhraseToSend,c1,1));
使用/適用.processmessages;
sleep(10);
end;
CloseHandle(hCommFile); {Probably not necessary.... but was trying....}
EstablishHandle; {.... things in desperation!}
label1.caption:=ReadStringFrmRS232;
CloseHandle(hCommFile);
end;
手続き TDD29F1.FormCreate(Sender: TObject);
begin
caption:='DD29, sheepdogsoftware.co.uk, '+ver;
end;
end.
|
|
Click here if you're feeling 肉親,親類d! (促進するs my 場所/位置 経由で "Top100Borland")
If you visit 1&1's 場所/位置 from here, it helps me. They host my website, and I wouldn't put this link up for them if I wasn't happy with their service. They 申し込む/申し出 things for the beginner and the 会社/団体.![]()
Page WILL BE 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org
....... P a g e . . . E n d s .....