有否人會用DELPHI 透過rs232 接收16進位字元的資料 |
尚未結案
|
cohost
一般會員 發表:2 回覆:6 積分:1 註冊:2005-08-24 發送簡訊給我 |
|
wyndog
資深會員 發表:7 回覆:362 積分:348 註冊:2004-10-12 發送簡訊給我 |
|
cohost
一般會員 發表:2 回覆:6 積分:1 註冊:2005-08-24 發送簡訊給我 |
|
cohost
一般會員 發表:2 回覆:6 積分:1 註冊:2005-08-24 發送簡訊給我 |
http://www.nahua.com.tw/download/rs232/ 在這個用vb寫出的測試程式, 可以看到ic卡所讀出的 16進位碼 第一張卡, 3 66 69 F2 F1 C 0 0
第二張卡, 3 6 3D F3 F1 39 0 0 而我所寫的delphi 讀出的顯示出為 一( fi襙)(DEBUG (#3'fi襙'#$C)) 二( =鵨9) (DEBUG (#3#6'=鵨9'))
而 debug 出的 ascii 一(#3 f i 空 空 #$c 空 空) 二(#3 #6 3d 空 空 9 空 空) 我所寫的程式如下
procedure TForm1.CommPortDriverReceivePacket(Sender: TObject;
Packet: Pointer; DataSize: Cardinal);
var
sStr, sStr2, sStr3: string;
pStr: pchar;
bUsed : Boolean;
iCount : integer;
begin
bUsed:=false;
if DataSize > 0 then
begin
sStr := '';
pStr := Packet;
edit1.text := pStr; edit2.text := pStr^; sStr2 :=edit2.text;
if sStr2=#1 then edit2.text := '#1';
if sStr2=#2 then edit2.text := '#2';
if sStr2=#3 then edit2.text := '#3'; // #3
if sStr2=#4 then edit2.text := '#4';
if sStr2=#5 then edit2.text := '#5';
if sStr2=#6 then edit2.text := '#6';
if sStr2=#7 then edit2.text := '#7';
if sStr2=#8 then edit2.text := '#8';
if sStr2=#9 then edit2.text := '#9'; dec(DataSize);
inc(pStr); edit3.text := pStr^;
iArray[1]:= pStr^;
sStr2 :=edit3.text;
if sStr2=#1 then edit3.text := '#1';
if sStr2=#2 then edit3.text := '#2';
if sStr2=#3 then edit3.text := '#3';
if sStr2=#4 then edit3.text := '#4';
if sStr2=#5 then edit3.text := '#5';
if sStr2=#6 then edit3.text := '#6';
if sStr2=#7 then edit3.text := '#7';
if sStr2=#8 then edit3.text := '#8';
if sStr2=#9 then edit3.text := '#9';
if sStr2=f then edit3.text := 'f'; //F
dec(DataSize);
inc(pStr);
.
.
.
end 還盼請各位高手請教
|
cohost
一般會員 發表:2 回覆:6 積分:1 註冊:2005-08-24 發送簡訊給我 |
我找到了 版主所寫的一份 function CRC(Code: string): Byte;
var i: Integer; b: Byte;
begin
Result := $00; for i := 1 to Length(Code) do
Result := Result xor Byte(Code[i]); // 或 Result := Result and Byte(Code[i]);
end; 透過這 function 轉換所傳入的字元 就自動轉成10進位的整數了 還是很感謝 reptile 兄的幫忙
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |