讀卡機送命令後沒反應 |
尚未結案
|
terrychen
尊榮會員 發表:90 回覆:794 積分:501 註冊:2003-05-01 發送簡訊給我 |
請教各位前輩
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, SPComm, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Comm1: TComm; Memo1: TMemo; Memo2: TMemo; Button2: TButton; Button3: TButton; Button4: TButton; procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; viewstring:string; i:integer; rbuf,sbuf:array[1..16] of byte; implementation {$R *.dfm} procedure senddata; var i:integer; commflg:boolean; begin viewstring:='' ; commflg:=true; Form1.comm1.writecommdata(Chr(16) 'T' '1' Chr(13),1); sleep(2); Form1.comm1.writecommdata(chr(19) '12' chr(13),1); sleep(2); Form1.comm1.writecommdata('?' Chr(13),1);//『?』為送卡和讀卡 ,不知為何沒反應 sleep(2); viewstring:= '發送' viewstring; Form1.Memo1.lines.add(viewstring); Form1.Memo1.lines.add(''); if not commflg then messagedlg('發送失敗 !' ,mterror,[mbyes],0); end; procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word); var i:integer; begin viewstring:='' ; move(buffer^,pchar(@rbuf)^,bufferlength); for i:=1 to bufferlength do viewstring:=viewstring inttohex(rbuf[i],bufferlength) '' ; viewstring:='接收' viewstring; memo2.lines.add(viewstring); memo2.lines.add(''); end; procedure TForm1.Button1Click(Sender: TObject); begin comm1.StopComm; comm1.StartComm; Memo1.Lines.Clear; Memo2.Lines.Clear; end; procedure TForm1.Button2Click(Sender: TObject); begin comm1.StopComm; end; procedure TForm1.Button3Click(Sender: TObject); begin senddata;//調用發送函數 end; end.//================補充一下元件設定 object Comm1: TComm CommName = 'COM1' BaudRate = 19200 ParityCheck = False Outx_CtsFlow = False Outx_DsrFlow = False DtrControl = DtrEnable DsrSensitivity = False TxContinueOnXoff = True Outx_XonXoffFlow = True Inx_XonXoffFlow = True ReplaceWhenParityError = False IgnoreNullChar = False RtsControl = RtsEnable XonLimit = 500 XoffLimit = 500 ByteSize = _7 Parity = None StopBits = _1 XonChar = #17 XoffChar = #19 ReplacedChar = #0 ReadIntervalTimeout = 100 ReadTotalTimeoutMultiplier = 0 ReadTotalTimeoutConstant = 0 WriteTotalTimeoutMultiplier = 0 WriteTotalTimeoutConstant = 0 OnReceiveData = Comm1ReceiveData Left = 392 Top = 8 end ~~應無所住而生其心~~ 發表人 - Terrychen 於 2004/07/14 18:22:40 |
roger128
初階會員 發表:27 回覆:45 積分:25 註冊:2002-08-29 發送簡訊給我 |
如果硬體介面沒問題ㄉ話,建議你從
1.commflg:=true;
Form1.comm1.writecommdata(Chr(16) + 'T' + '1' +Chr(13),1);
sleep(2);<--時間調長一點 0.002秒 有點短
Form1.comm1.writecommdata(chr(19)+'12'+chr(13),1);
sleep(2);
Form1.comm1.writecommdata('?'+Chr(13),1);//『?』為送卡和讀卡 ,不知為何沒反應
sleep(2);
2.PC 端與讀卡機ㄉ間溝通ㄉ協定 是不是有問題,一般CMD對ㄉ話 理論是是可以溝通ㄉ,怕ㄉ是DATA FORMATE 又要編碼過, 所以建議你在擬清PC與設備端ㄉ協定問題
|
terrychen
尊榮會員 發表:90 回覆:794 積分:501 註冊:2003-05-01 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |