串口读写数据 (100分)

  • 主题发起人 主题发起人 jiweishan
  • 开始时间 开始时间
J

jiweishan

Unregistered / Unconfirmed
GUEST, unregistred user!
我用串口读16进制数据结果发出命令收不到数据啊,请问这是怎么回事啊,代码如下:<br>procedure TForm1.FormShow(Sender: TObject);<br>begin<br>&nbsp; MSComm1.CommPort := 1;<br>&nbsp; MSComm1.Settings := '19200,n,8,1';<br>&nbsp; MSComm1.InputLen := 0;<br>&nbsp; MSComm1.InputMode := comInputModeBinary;<br>&nbsp; MSComm1.RThreshold := 1;<br>&nbsp; MsComm1.PortOpen := True;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>Var Str : OleVariant;<br>&nbsp; &nbsp; &nbsp; i : iNTEGER;<br>&nbsp; &nbsp; &nbsp;AA : String;<br>begin<br>&nbsp; MSComm1.OutBufferCount := 0;<br>&nbsp; MSComm1.Output := IntToHex($1B,2);<br>&nbsp; Ab := $1B;<br>&nbsp; MSComm1.Output := IntToHex(Ab,2);<br>&nbsp; Ab := $49;<br>&nbsp; MSComm1.Output :=IntToHex(Ab,2);<br>&nbsp; Delay(100);<br>&nbsp; Str := MSComm1.Input;<br>&nbsp; Begin<br>&nbsp; &nbsp; For I := 1 To Length(Str) DO<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; AA := AA + Str;<br>&nbsp; &nbsp; End;<br>&nbsp; End;<br>&nbsp;ShowMessage(Str);<br><br>end;<br><br>procedure TForm1.MSComm1Comm(Sender: TObject);<br>&nbsp; Var<br>&nbsp; &nbsp;Xbyte : Word;<br>&nbsp; &nbsp; &nbsp; &nbsp;j : Word;<br>InByte :Byte;<br>inbyte2: Byte;<br>inData : String;<br>begin<br><br>&nbsp;Case MSComm1.CommEvent of <br>&nbsp; &nbsp;comEvReceive : <br>&nbsp; &nbsp;BEgin<br>&nbsp; &nbsp; &nbsp; &nbsp; InByte := MSComm1.Input;<br>&nbsp; &nbsp; &nbsp; &nbsp; ShowMessage(IntToStr(InByte));<br><br>&nbsp;End;<br>&nbsp;comEventRxOver<br>&nbsp; &nbsp;ShowMessage('Err');<br>&nbsp; End;<br><br>end;<br>
 

Similar threads

I
回复
0
查看
550
import
I
I
回复
0
查看
788
import
I
I
回复
0
查看
733
import
I
I
回复
0
查看
650
import
I
后退
顶部