您的位置:首页 > 其它

WIFI 模块 串口 调试 助手

2009-06-13 21:57 239 查看
本人在调试wifi模块时,用delphi写了个wifi模块调试助手的程序,

串口采用mscomm,

开启mscomm

procedure TForm1.FormCreate(Sender: TObject);

begin
try
configinifile:=Tinifile.create('config/config.ini');
mscomm1.CommPort:=configinifile.readinteger('gsmmscomm','commport',2);
mscomm1.Settings:=configinifile.readString('gsmmscomm','settings','9600,n,8,1');
mscomm1.PortOpen:=true;
except
MessageBox(0,'请修改配置文件config.ini的端口号','串口端口号设置错误或者不存在此端口号!',MB_OK);
end;
edit2.Text:=inttostr(mscomm1.CommPort);
end;

mscomm接收事件处理程序:

procedure TForm1.MSComm1Comm(Sender: TObject);
var
inputCount:integer;
tmpStr:string;
tmpArray:array of byte;
i:integer;
begin
tmpStr:='';
case mscomm1.CommEvent of
comEvReceive:
begin
tmpStr:='';
inputCount:=mscomm1.InBufferCount;
// tmpReadCount:=inputCount;
setLength(tmpArray,inputcount);
tmpArray:=mscomm1.input;
// analizeData(tmpArray );
//-------------------------------------------------//
for i:=0 to inputCount -1 do
begin
if blnHex then
tmpStr:=tmpstr +' '+intTohex(tmpArray[i],2)
else
tmpStr:=tmpStr+chr(tmpArray[i]);
if (tmpArray[i-1]=13)and(tmpArray[i]=10) then
begin
memInfo.Text:=memInfo.Text+tmpStr+#13#10;
memInfo.SelStart:=length(memInfo.Text);
tmpStr:='';
end;
end;//end for
memInfo.Text:=memInfo.Text+tmpstr;
memInfo.SelStart:=length(memInfo.Text);
// memInfo.ScrollBars.
// sendmessage(memInfo.Handle,WM_VSCROLL,SB_BOTTOM,0);
//滚动条下滑
memInfo.SelStart:= getTextlen;
memInfo.SelLength:= Length(memInfo.text);
//-----------------------------------------------------//
end;
else;
end; //end case;
end;

模块和程序效果图如下:





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: