SPComm元件使用問題 |
答題得分者是:cmf
|
nick
一般會員 發表:4 回覆:3 積分:1 註冊:2002-03-13 發送簡訊給我 |
請問各位先進:
小弟對於SPComm這個元件的使用並不是很了解,要如何透過com2 port
接收對方的資料。在Comm1Receivedata下要如何把接收的資料塞到Memo中。
請各位先進指點。感激不盡。 procedure TForm1.FormCreate(Sender: TObject);
begin
Comm1.StartComm;
end; procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Comm1.StopComm;
end; procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
begin
end;
| ||||
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word); var i: integer; s: string; begin s := ''; for i := 1 to BufferLength do s := s Buffer^[i]; Memo1.Lines.Add(s); // 如果是一些 16 進位字元的話, 就要另外處理了! // Memo1.Lines.Add(ShowCode(s)); end; procedure ShowCode(ACode: string); Var sShow, sCatch: string; i: integer; begin sShow := ''; for i := 1 to Length(ACode) do begin sCatch := Format('%X', [Ord(ACode[i])]); if Length(sCatch) = 1 then sCatch := '0' sCatch; sShow := sShow sCatch ' '; end; Delete(sShow, Length(sShow), 1); Memo1.Lines.Add(sShow); end;-- Everything I say is a lie. |
||||
cmf
尊榮會員 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
引言: 請問各位先進: 小弟對於SPComm這個元件的使用並不是很了解,要如何透過com2 port 接收對方的資料。在Comm1Receivedata下要如何把接收的資料塞到Memo中。 請各位先進指點。感激不盡。 procedure TForm1.FormCreate(Sender: TObject); begin Comm1.StartComm; end; procedure TForm1.BitBtn1Click(Sender: TObject); begin Comm1.StopComm; end; procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word); begin end;procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word); var s:string; begin s:=Copy(Buffer,0,BufferLength) Memo1.Lines.Add(s); end;
------
︿︿ |
||||
nick
一般會員 發表:4 回覆:3 積分:1 註冊:2002-03-13 發送簡訊給我 |
引言:請問先進: 為何在compiler的時候,s:= s Buffer^[i];這一行都會出現 Array type required,順便在請教一個問題,就是讀取完Buffer這一段data 之後,要如何把Buffer清空,謝謝。procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word); var i: integer; s: string; begin s := ''; for i := 1 to BufferLength do s := s Buffer^[i]; Memo1.Lines.Add(s); // 如果是一些 16 進位字元的話, 就要另外處理了! // Memo1.Lines.Add(ShowCode(s)); end;procedure ShowCode(ACode: string); Var sShow, sCatch: string; i: integer; begin sShow := ''; for i := 1 to Length(ACode) do begin sCatch := Format('%X', [Ord(ACode[i])]); if Length(sCatch) = 1 then sCatch := '0' sCatch; sShow := sShow sCatch ' '; end; Delete(sShow, Length(sShow), 1); Memo1.Lines.Add(sShow); end;-- Everything I say is a lie. |
||||
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
|||||
cmf
尊榮會員 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
|||||
dllee
站務副站長 發表:321 回覆:2519 積分:1711 註冊:2002-04-15 發送簡訊給我 |
引言: 順便在請教一個問題,就是讀取完Buffer這一段data 之後,要如何把Buffer清空,謝謝。不需要清空它, SPComm 是在收到資料後,將資料放到它內部的 buf, 在一定量或是 TIMEOUT 後,才會將內部資料以 OnReceiveData 一次傳給你, 而它自己內部的 buf 在用 OnReceiveData 傳給你時, 就已清空, 準備接之後的資料了,所以說, 不必清它。 沒空更新的網頁...
------
http://www.ViewMove.com |
||||
david Lin
一般會員 發表:7 回覆:13 積分:4 註冊:2002-04-06 發送簡訊給我 |
|||||
jim1247
一般會員 發表:8 回覆:20 積分:5 註冊:2003-01-30 發送簡訊給我 |
|||||
cmf
尊榮會員 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
|||||
jim1247
一般會員 發表:8 回覆:20 積分:5 註冊:2003-01-30 發送簡訊給我 |
|||||
cmf
尊榮會員 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
我的 help 是這樣ㄚ @@ Returns a substring of a string or a segment of a dynamic array. Unit System Category string handling routines function Copy(S; Index, Count: Integer): string;
function Copy(S; Index, Count: Integer): array; Description S is an expression of a string or dynamic-array type. Index and Count are integer-type expressions. Copy returns a substring or sub array containing Count characters or elements starting at S[Index]. If Index is larger than the length of S, Copy returns an empty string or array. If Count specifies more characters or array elements than are available, only the characters or elements from S[Index] to the end of S are returned. Note: When S is a dynamic array, Copy can only be used as a parameter in a call to a procedure or function that expects an array parameter. That is, it acts like the Slice function when working with dynamic arrays. 發表人 - cmf 於 2003/05/16 12:15:03
------
︿︿ |
||||
jim1247
一般會員 發表:8 回覆:20 積分:5 註冊:2003-01-30 發送簡訊給我 |
引言: 我的 help 是這樣ㄚ @@ Returns a substring of a string or a segment of a dynamic array. Unit System Category string handling routines function Copy(S; Index, Count: Integer): string; function Copy(S; Index, Count: Integer): array; Description S is an expression of a string or dynamic-array type. Index and Count are integer-type expressions. Copy returns a substring or sub array containing Count characters or elements starting at S[Index]. If Index is larger than the length of S, Copy returns an empty string or array. If Count specifies more characters or array elements than are available, only the characters or elements from S[Index] to the end of S are returned. Note: When S is a dynamic array, Copy can only be used as a parameter in a call to a procedure or function that expects an array parameter. That is, it acts like the Slice function when working with dynamic arrays. 發表人 - cmf 於 2003/05/16 12:15:03可是在compiler時一直說這行有問題?? 不知cmf大大可以試一下嗎? |
||||
cmf
尊榮會員 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
|||||
jim1247
一般會員 發表:8 回覆:20 積分:5 註冊:2003-01-30 發送簡訊給我 |
引言: 你的程式貼上來 我看看 註: 我的程式就是這樣寫ㄚ@@var tmpS, inbuff: String; procedure TfrmOutput.btnUpClick(Sender: TObject); begin tmpS := 'ASK10' Chr(13); Comm1.CommName := 'Com1'; Comm1.StartComm; Comm1.WriteCommData(@tmpS, Length(tmpS)); //傳出'ASK10'的字串 Comm1.StopComm; end; procedure TfrmOutput.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;BufferLength: Word); begin inbuff := Copy(Buffer, 0, BufferLength); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //回傳'OVER'的字串 end; compiler一直出現Incompatible Types的錯誤訊息 |
||||
cmf
尊榮會員 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
|||||
jim1247
一般會員 發表:8 回覆:20 積分:5 註冊:2003-01-30 發送簡訊給我 |
|||||
jeachen
一般會員 發表:12 回覆:6 積分:3 註冊:2003-03-19 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |