为什么我用SPCOMM读写$11为什么不行???(50分)

W

wmmwang

Unregistered / Unconfirmed
GUEST, unregistred user!
我用SPCOMM发11给单片机,然后再读出来,为什么读出来什么都没有?
代码如下:
var
SetFlag:Boolean;//设置时间标志
GetFlag:Boolean;//读取时间标志
Ack2:Byte; //握手信号
time:Array[1..8] Of Byte;//定义个时间数组,用于接收时间,其中time[1]为握手信号

Year:Integer; //年
Month:Integer; //月
Day:Integer; //日
Hour:Integer; //时
Minute:Integer; //分
Second:Integer; //秒
Week:Integer; //星期



//****读取时间处理***//
if GetFlag=True Then
begin
GetFlag:=False;
move(buffer^,pchar(@time)^,8);
if time[1]=$30 then //time[1]为握手信号
begin
Edit6.Text:=IntToHex(time[2],2); //秒
Edit5.Text:=IntToHex(time[3],2); //分
Edit4.Text:=IntToHex(time[4],2); //时
Edit3.Text:=IntToHex(time[5],2); //日
Edit2.Text:=IntToHex(time[6],2); //月
Edit7.Text:=IntToStr(time[7]); //星期
Edit1.Text:='20'+IntToHex(time[8],2); //年
ShowMessage('成功接收时间');
end
else
showmessage('读取时间失败!');
end;

//****设置时间处理***//
if SetFlag=True Then
begin
SetFlag:=False;
move(buffer^,Ack2,1);
if Ack2<>$20 Then
showmessage('设置时间失败!')
else
begin
ReadDateTime;
ChangeBcd;
Comm1.WriteCommData(@second,1); //发送时间
Comm1.WriteCommData(@minute,1);
Comm1.WriteCommData(@hour,1);
Comm1.WriteCommData(@day,1);
Comm1.WriteCommData(@month,1);
Comm1.WriteCommData(@week,1);
Comm1.WriteCommData(@year,1);
ShowMessage('设置时间成功');
end;
end;


{************************读取系统时间*******************************}
procedure ReadDateTime;
var
DateTime:TdateTime;
begin
DateTime:=Now;
Year:=YearOf(DateTime);
Month:=MonthOf(DateTime);
Day:=DayOf(DateTime);
Hour:=HourOf(DateTime);
Minute:=MinuteOf(DateTime);
Second:=SecondOf(DateTime);
Week:=DayOfWeek(DateTime);
end;


{************************整型换成BCD码*******************************}
procedure ChangeBcd;
begin
year:=year mod 100; //取年的后面两位
year:=(year div 10)*16+year mod 10;
month:=(month div 10)*16+month mod 10;
day:=(day div 10)*16+day mod 10;
hour:=(hour div 10)*16+hour mod 10;
minute:=(minute div 10)*16+minute mod 10;
second:=(second div 10)*16+second mod 10;
end;

注意:我要发送11,是转成BCD发送的,即发送$11。
发送时间的秒、分、时、年、月、日任何其中的几个为11,读出来就没有11了,或者是乱码,但是10、12都很正常。
应该是发送出了问题,因为我用串口调试助手发送、读取11,都很正常。
 
问题简化了,但是还看不出在什么地方。。
我就单发$11,单片机什么都不做,收到什么发什么,这里收到$11,那就是还是发$11,结果还是一样,什么都没有。代码如下:
procedure TForm1.Button1Click(Sender: TObject);
var
i:Byte;
begin
i:=$11;
comm1.WriteCommData(@i,1);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
comm1.startcomm;
end;

procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
i:Byte;
begin
move(buffer^,i,1);
edit2.text:=inttohex(i,2);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
comm1.StopComm;
end;


哪位高手解决下啊???帮帮忙……
 
把“流控”功能关闭就可以了
 
请教LS这个“流控”功能是哪个,也就是它的英文名字是哪个?我初学DELPHI,不太清楚,谢谢了
 
Inx_XonXoffFlow:=false;,Outx_XonXoffFlow:=false;
 
CommLP.ParityCheck :=False;
CommLP.Inx_XonXoffFlow :=False;
CommLP.Outx_XonXoffFlow :=False;
 
可以了。谢谢楼上了。
 
接受答案了.
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
顶部