大家好!!!
有没有开发过在Delphi 中利用MSComm控件通讯的问题???? 代码如下:
var
Form1: TForm1;
senddata:array[1..10] of char;
reData:array of oleVariant;
sendstr:string;
restr:string;
i,j:longint;
w :integer ;implementation{$R *.dfm}
procedure tform1.sendhex(s:string);
var
s2,s3:string ;
bufl:array[0..50000] of byte;
i:integer;
begin
s2 := '';
s3 := '';
for i:=1 to length(s) do
begin
if ((copy(s,i,1)>='0') and (copy(s,i,1)<='9')) or ((copy(s,i,1)>='a') and (copy(s,i,1)<='f')) or ((copy(s,i,1)>='A') and (copy(s,i,1)<='F')) then
begin
s2 := s2 +copy(s,i,1);
end;
end ;
for i:= 0 to (length(s2) div 2-1) do
begin
bufl[i]:=strtoint('$'+copy(s2,i*2+1,2));
s3 := s3 +char(bufl[i]);
end ;
mscomm1.Output := s3 ;
end ;procedure TForm1.FormCreate(Sender: TObject);
begin
sendstr:='';
w:= 0 ;
mscomm1.CommPort := 1; //指定端口
mscomm1.Settings := '9600,N,8,1'; //其它参数
mscomm1.InBufferSize := 1024; //接收缓冲区
mscomm1.OutBufferSize := 1024; //发送缓冲区
mscomm1.InputMode := comInputModeBinary; //接收模式
mscomm1.InputLen := 0; //一次读取所有数据
mscomm1.SThreshold := 0; //一次发送所有数据
mscomm1.InBufferCount := 0; //清空读取缓冲区
mscomm1.OutBufferCount := 0; //清空发送缓冲区
MSComm1.RThreshold := 1; //设置接收多少字节开产生oncomm事件
mscomm1.PortOpen:=true; //打开端口end;procedure TForm1.Button2Click(Sender: TObject);
begin
sendhex('8800');
end;
我的问题是:为什么发8800时,只能发出去00呢?????????????????????????????????????????????
发5500时却都能发出去!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!我的是十六进制接发送数据的!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!请高手指点或给个列子
有没有开发过在Delphi 中利用MSComm控件通讯的问题???? 代码如下:
var
Form1: TForm1;
senddata:array[1..10] of char;
reData:array of oleVariant;
sendstr:string;
restr:string;
i,j:longint;
w :integer ;implementation{$R *.dfm}
procedure tform1.sendhex(s:string);
var
s2,s3:string ;
bufl:array[0..50000] of byte;
i:integer;
begin
s2 := '';
s3 := '';
for i:=1 to length(s) do
begin
if ((copy(s,i,1)>='0') and (copy(s,i,1)<='9')) or ((copy(s,i,1)>='a') and (copy(s,i,1)<='f')) or ((copy(s,i,1)>='A') and (copy(s,i,1)<='F')) then
begin
s2 := s2 +copy(s,i,1);
end;
end ;
for i:= 0 to (length(s2) div 2-1) do
begin
bufl[i]:=strtoint('$'+copy(s2,i*2+1,2));
s3 := s3 +char(bufl[i]);
end ;
mscomm1.Output := s3 ;
end ;procedure TForm1.FormCreate(Sender: TObject);
begin
sendstr:='';
w:= 0 ;
mscomm1.CommPort := 1; //指定端口
mscomm1.Settings := '9600,N,8,1'; //其它参数
mscomm1.InBufferSize := 1024; //接收缓冲区
mscomm1.OutBufferSize := 1024; //发送缓冲区
mscomm1.InputMode := comInputModeBinary; //接收模式
mscomm1.InputLen := 0; //一次读取所有数据
mscomm1.SThreshold := 0; //一次发送所有数据
mscomm1.InBufferCount := 0; //清空读取缓冲区
mscomm1.OutBufferCount := 0; //清空发送缓冲区
MSComm1.RThreshold := 1; //设置接收多少字节开产生oncomm事件
mscomm1.PortOpen:=true; //打开端口end;procedure TForm1.Button2Click(Sender: TObject);
begin
sendhex('8800');
end;
我的问题是:为什么发8800时,只能发出去00呢?????????????????????????????????????????????
发5500时却都能发出去!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!我的是十六进制接发送数据的!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!请高手指点或给个列子
解决方案 »
- 关于工程文件的疑问
- 听说是小小这个妮子的生日,祝他生日快乐吧 哇哈哈哈
- 如何做一个循环,进行异或运算 03 Xor B0 Xor 00 Xor 04 Xor 80 Xor 4F .... 急急急急
- 可不可封装基于TForm的组件,使它可以接受参数?
- ◆◆◆◆◆◆DELHI8 无法正常编译程序~请高人指教◆◆◆◆◆◆
- 大侠帮忙:Fastreport控件实现分组后如何再分页打印?
- 你们用什么报表控件?
- 还是blob 的奇怪问题!!高手请进!!
- 怎样设计评卷(试卷含WORD文档)软件
- ?精简版delphi?
- 海南的Delphi朋友有吗?我在海口,有空交流交流
- Query1: CommandText does not return a result set 是什么意思啊!!
var
bufl:array of byte;
i,j:integer;
begin
{此段代码只是将传递的字符串ASCII
码转换成16进制数后
通过串口发送出去
不包括数据正确性验证。
假设传递参数S是一串16进制数的ASCII码
比如‘8800’,表示$88 $00}
i:=Length(s) div 2;
SetLength(Bufl,i);
for j:=0 to i-1 do begin
Bufl[j]:=strtoint('$'+copy(S,2*j+1,2))
end;
mscomm1.Output :=bufl ;
end ;