今天在写一个关于RS232串口连接的程序,在发送指令时老是达不到要求 请问下谁有这相关的程式给我个 谢谢
[email protected]
[email protected]
解决方案 »
- 有没有简单的方法吧所有挂起的线程都唤起呢
- delphi调用crystal report问题
- 独爱互联
- ado的多表连接,单表更新问题?以高分增送
- 请问,我是应该学java还是.net
- Access Violation at address <一个不定地址> in modle 程序.exe
- 为什么我测到网卡的MAC号,天天都不同? 问题解决马上送分!!!很容易就可以拿到手了!!!
- 请问这个SQL语句怎么写?——50分求救!——在线30分钟等候!
- 一个很菜的问题!!!
- 如何防止程序二次执行and如何使程序连续执行
- dbf数据库中如何获取字符为空的字符串
- 请高手帮忙把这小段代码转成delphi的,谢谢
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SPComm, StdCtrls,cport;
type
TForm1 = class(TForm)
Comm1: TComm;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
CheckBox1: TCheckBox;
ComboBox1: TComboBox;
procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
// rbuf:array[0..500]of char;
implementation
{$R *.dfm}
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
type
ss=array[1..500]of char ;
var
str1:^ss;
i:integer;
s:array[0..15] of char ;
n:integer;
str:string;
begin
str1:=Buffer;
str:='';
//s[]=('0','1','2','3'...'E')
if form1.CheckBox1.Checked then
begin
for i:=0 to 9 do //转换成ASCLL码显示
s[i]:=chr(48+i);
for i:=10 to 15 do
s[i]:=chr(55+i);
for i:=1 to bufferlength do
begin
n:=ord(str1^[i]);
str:=str+' '+(s[n div 16]+s[n mod 16]);
end;
memo1.Lines.Add(str);//转换成ASCLL码显示
end
else
begin
str:=str1^;
delete(str,1,1);
memo1.Lines.Add(str);//以十六进制原样显示
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
comm1.StartComm;
form1.Caption:='处于接收数据中.....';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
comm1.StopComm;
form1.Caption:='串口已关闭';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
EnumComPorts(ComboBox1.Items);
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
comm1.StopComm;
comm1.CommName:=form1.ComboBox1.Text;
comm1.StartComm;
form1.Caption:=form1.ComboBox1.Text+'串口处于接收数据中....';
end;
end.
BufferLength: Word);
var
ibyte:array of byte;
iIndex,i:integer;
viewstring:string;
begin
if not gbSampling then exit;
try
SetLength(iByte,BufferLength);
iByte:=buffer;
if (iByte[0]=Byte('#')) then
begin
giReceiveDataLength:=0;
end;
iIndex:=giReceiveDataLength;
inc(giReceiveDataLength,bufferlength);
setLength(giReceiveData,giReceiveDataLength);
copyMemory(@giReceiveData[iIndex],buffer,BufferLength); for i:=1 to bufferlength do
viewstring:=viewstring+ inttohex(iByte[i],2)+' ' ;
viewstring:='接收'+ viewstring;
memo1.lines.add(viewstring);
memo1.lines.add('');
// if (iByte[bufferLength-2]=13) and (iByte[bufferLength-1]=10) then
//begin // DealWithReceiveData(@giReceiveData[0]);
//end;
// showmessage(viewstring);
finally
ibyte:=nil;
end; 我是这样写的 ,就是读取不到数据,设备都能连接上