線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2547
推到 Plurk!
推到 Facebook!

SPComm元件使用問題

答題得分者是:cmf
nick
一般會員


發表:4
回覆:3
積分:1
註冊:2002-03-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-11-21 16:40:45 IP:203.66.xxx.xxx 未訂閱
請問各位先進: 小弟對於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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-11-21 19:14:24 IP:211.21.xxx.xxx 未訂閱
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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-11-22 12:23:59 IP:61.218.xxx.xxx 未訂閱
引言: 請問各位先進: 小弟對於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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2002-11-22 13:21:57 IP:203.66.xxx.xxx 未訂閱
引言:
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.
請問先進: 為何在compiler的時候,s:= s Buffer^[i];這一行都會出現 Array type required,順便在請教一個問題,就是讀取完Buffer這一段data 之後,要如何把Buffer清空,謝謝。
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#5 引用回覆 回覆 發表時間:2002-11-22 20:21:43 IP:202.39.xxx.xxx 未訂閱
引言: 請問先進: 為何在compiler的時候,s:= s Buffer^[i];這一行都會出現 Array type required,順便在請教一個問題,就是讀取完Buffer這一段data 之後,要如何把Buffer清空,謝謝。
原來小弟這樣寫是錯的, 那就用 cmf 兄的寫法。 -- Everything I say is a lie.
cmf
尊榮會員


發表:84
回覆:918
積分:1032
註冊:2002-06-26

發送簡訊給我
#6 引用回覆 回覆 發表時間:2002-11-26 12:58:53 IP:61.218.xxx.xxx 未訂閱
引言: 請問先進: 為何在compiler的時候,s:= s Buffer^[i];這一行都會出現 Array type required,順便在請教一個問題,就是讀取完Buffer這一段data 之後,要如何把Buffer清空,謝謝。
Buffer清空 FillChar(Buffer,BufferLength,#0);
------
︿︿
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#7 引用回覆 回覆 發表時間:2002-12-01 13:12:22 IP:203.204.xxx.xxx 未訂閱
引言: 順便在請教一個問題,就是讀取完Buffer這一段data 之後,要如何把Buffer清空,謝謝。
不需要清空它, SPComm 是在收到資料後,將資料放到它內部的 buf, 在一定量或是 TIMEOUT 後,才會將內部資料以 OnReceiveData 一次傳給你, 而它自己內部的 buf 在用 OnReceiveData 傳給你時, 就已清空, 準備接之後的資料了,所以說, 不必清它。 沒空更新的網頁...
C及指標教學,計算機概論,資訊管理導論... http://coolsite.to/dllee 介紹Shells,LiteStep,GeoShell.... http://coolsite.to/ushells
------
http://www.ViewMove.com
david Lin
一般會員


發表:7
回覆:13
積分:4
註冊:2002-04-06

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-05-13 16:07:03 IP:61.220.xxx.xxx 未訂閱
請問各位先進, SPComm這個元件是否只能使用於 COM1~9之通信埠,為什麼無法開啟COM10以上之通信埠? 謝謝 !
jim1247
一般會員


發表:8
回覆:20
積分:5
註冊:2003-01-30

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-05-16 11:06:01 IP:211.76.xxx.xxx 未訂閱
請問一下 我使用了cmf大大的方法 可是在compiler會出現型態錯誤的訊息耶 Pointer型態可以直接轉成String型態嗎?
cmf
尊榮會員


發表:84
回覆:918
積分:1032
註冊:2002-06-26

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-05-16 11:28:43 IP:61.218.xxx.xxx 未訂閱
jim1247 您是說哪一段 @@
------
︿︿
jim1247
一般會員


發表:8
回覆:20
積分:5
註冊:2003-01-30

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-05-16 11:35:08 IP:211.76.xxx.xxx 未訂閱
sorry 忘了說明^^" s:=Copy(Buffer,0,BufferLength) ^^^^^^ 在compiler會出現型態錯訊的訊息 因為Buffer變數是Pointer型態 而Copy函式要放String or 陣列才行 PS:我是新手..問題太笨請見諒QQ
cmf
尊榮會員


發表:84
回覆:918
積分:1032
註冊:2002-06-26

發送簡訊給我
#12 引用回覆 回覆 發表時間:2003-05-16 12:13:15 IP:61.218.xxx.xxx 未訂閱
我的 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

發送簡訊給我
#13 引用回覆 回覆 發表時間:2003-05-16 13:54:21 IP:211.76.xxx.xxx 未訂閱
引言: 我的 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

發送簡訊給我
#14 引用回覆 回覆 發表時間:2003-05-16 14:31:40 IP:61.218.xxx.xxx 未訂閱
你的程式貼上來 我看看 註: 我的程式就是這樣寫ㄚ@@
------
︿︿
jim1247
一般會員


發表:8
回覆:20
積分:5
註冊:2003-01-30

發送簡訊給我
#15 引用回覆 回覆 發表時間:2003-05-19 15:31:13 IP:211.76.xxx.xxx 未訂閱
引言: 你的程式貼上來 我看看 註: 我的程式就是這樣寫ㄚ@@
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

發送簡訊給我
#16 引用回覆 回覆 發表時間:2003-05-19 15:45:38 IP:61.70.xxx.xxx 未訂閱
難道是版本不同嗎 =.=" , 再試試吧 ! inbuff := Copy(Buffer, 0, integer(BufferLength));
------
︿︿
jim1247
一般會員


發表:8
回覆:20
積分:5
註冊:2003-01-30

發送簡訊給我
#17 引用回覆 回覆 發表時間:2003-05-22 10:16:03 IP:211.76.xxx.xxx 未訂閱
引言: 難道是版本不同嗎 =.=" , 再試試吧 ! inbuff := Copy(Buffer, 0, integer(BufferLength));
經過不斷的嘗試後...還是不行@@ 我再想辦法好了....>"< PS:我是用delphi5.0版
jeachen
一般會員


發表:12
回覆:6
積分:3
註冊:2003-03-19

發送簡訊給我
#18 引用回覆 回覆 發表時間:2003-05-22 11:11:47 IP:61.218.xxx.xxx 未訂閱
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word); var s:string; begin SetLength(S, BufferLength); Move(Buffer^, PChar(S)^, BufferLength); Memo1.Lines.Add(S); end;
系統時間:2024-05-17 4:01:38
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!