📄 75146.htm
字号:
RecvBuffInit:=False;<BR>
PurgeComm(hCommDev,PURGE_RXCLEAR );
//清空接收缓冲区<BR>
end<BR> end;<BR>
////////////////<BR> SetEvent(postRecvEvent);
//置接收事件句柄为有信号状态,以便接收新字符</P>
<P>end;</P>
<P>function ConInfo :String;<BR>begin<BR>
if SendCommandSuccess =True then<BR>
begin<BR>
Result := '切换器联机监测成功!';<BR>
end<BR> else<BR>
begin<BR>
Result := '切换器联机监测失败!';<BR> end;<BR>end;</P>
<P>{<BR>procedure CommSendNotify;<BR>begin<BR>
SetEvent(postSendEvent);//置发送事件未有信号状态,以便进行下一次发送<BR>end;</P>
<P>///接收到字符处理函数<BR>{procedure
CommRecvNotify;<BR>var<BR>
RxCount,dwReadByte:DWORD;<BR> inData
:Byte;<BR>begin<BR>
ClearCommError(hCommDev,dwErrorFlag,@ComStat);<BR>
RxCount:=ComStat.cbInQue; //获取接收缓冲区的字符个数<BR>
if RxCount>0 then<BR>
begin<BR> if not RecvBuffInit
then<BR>
begin<BR>
StrCopy(RecvBuff,'');<BR>
RecvBuffInit:=True;<BR>
end;<BR>
StrCopy(TempBuff,'');<BR>
ReadFile(hCommDev,Byte(TempBuff^),RxCount,dwReadByte,@read_os);//读字符存入<BR>
//ReadFile(hCommDev,Byte(TempBuff^),RxCount,dwReadByte,@read_os);//读字符存入<BR>
//临时缓冲区中<BR>
iRecvLen:=iRecvLen+dwReadByte;
//接收到字符个数统计<BR>
{<BR> if iRecvLen<13
then<BR>
begin<BR>
strcat(Recvbuff,TempBuff);
//若接收到的切换台状态字符小于13个,<BR>
//将临时缓冲区中的字符拷贝到接收命令缓冲区,准备继续读<BR>
end<BR>
else<BR>
begin<BR>
strcat(Recvbuff,TempBuff);<BR>
RecvCommand:=RecvBuff;<BR>
//若接收到13个切换台状态字符进行如下处理<BR>
if
(RecvCommand[7]='P')<BR>
and(RecvCommand[8]=SendCommand[7])
//比较读入的切换台端口状态<BR>
and (RecvCommand[9]=SendCommand[8])
//是否与切换指令中切换的端口<BR>
and (RecvCommand[10]=SendCommand[9])
//一致<BR>
and (RecvCommand[11]=SendCommand[10]) then</P>
<P>
begin<BR>
SendCommandSuccess:=True;
//如果状态一致,则置该标志为真,标志切换成功<BR>
end<BR>
else<BR>
begin<BR>
SendCommandSuccess:=False;//否则,置该标志为假,表示切换失败<BR>
end;<BR>
iRecvLen:=0;<BR>
StrCopy(RecvBuff,'');<BR>
RecvBuffInit:=False;<BR>
PurgeComm(hCommDev,PURGE_RXCLEAR );
//清空接收缓冲区<BR>
end;<BR>
}<BR>
{<BR> if iRecvLen >=1
then<BR>
begin<BR>
inData :=
Byte(TempBuff^);<BR>
if inData = $D9
then<BR>
begin<BR>
SendCommandSuccess:=True; //如果状态一致,则置该标志为真,标志切换成功</P>
<P>
end<BR>
else<BR>
begin<BR>
SendCommandSuccess:=False;//否则,置该标志为假,表示切换失败<BR>
end;</P>
<P>
iRecvLen:=0;<BR>
StrCopy(RecvBuff,'');<BR>
RecvBuffInit:=False;<BR>
PurgeComm(hCommDev,PURGE_RXCLEAR );
//清空接收缓冲区<BR>
end<BR> end;<BR>
////////////////<BR> SetEvent(postRecvEvent);
//置接收事件句柄为有信号状态,以便接收新字符</P>
<P>end;<BR>}</P>
<P>initialization<BR>
RecvBuff:=StrAlloc(50*sizeof(Char));<BR>
TempBuff:=StrAlloc(50*sizeof(Char));<BR>Finalization<BR>
StrDispose(RecvBuff);<BR>
StrDispose(TempBuff);<BR>
CloseHandle(PostRecvEvent);<BR>
CloseHandle(read_os.hEvent);<BR>
CloseHandle(PostSendEvent);<BR>
CloseHandle(write_os.hEvent);<BR>end.<BR></P></SPAN><BR>
<DIV
style="FONT-SIZE: 14px; LINE-HEIGHT: 25px"><STRONG>作者Blog:</STRONG><A
id=ArticleContent1_ArticleContent1_AuthorBlogLink
href="http://blog.csdn.net/qiyingdai/"
target=_blank>http://blog.csdn.net/qiyingdai/</A></DIV>
<DIV
style="FONT-SIZE: 14px; COLOR: #900; LINE-HEIGHT: 25px"><STRONG>相关文章</STRONG></DIV>
<TABLE id=ArticleContent1_ArticleContent1_RelatedArticles
cellSpacing=0 border=0>
<TBODY>
<TR>
<TD><A
href="http://dev.csdn.net/article/75/75146.shtm">RS232串口通讯模块</A>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><A name=#Comment></A>
<TABLE cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center
bgColor=#006699 border=0>
<TBODY>
<TR bgColor=#006699>
<TD id=white align=middle width=556 bgColor=#006699><FONT
color=#ffffff>对该文的评论</FONT> </TD></TR></TBODY></TABLE>
<TABLE cellSpacing=1 cellPadding=2 width="100%" align=center
bgColor=#666666 border=0>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN
style="COLOR: #990000"><IMG height=16 hspace=1 src=""
width=16> </SPAN><SPAN
id=CommnetList1_CommnetList1_rpCommentList__ctl0_lblUserName>CSDN
网友</SPAN> <I>( <SPAN
id=CommnetList1_CommnetList1_rpCommentList__ctl0_lblPostTime>2006-04-05</SPAN>)</I>
</TD></TR>
<TR>
<TD width=532 bgColor=#ffffff colSpan=3><SPAN
id=CommnetList1_CommnetList1_rpCommentList__ctl0_lblContent>布尔变量非True即False,不存在布尔变量=True(Or False)的比较。假定Something为一布尔型变量,文中大量出现 if Something = True(Or False)的语句,多此一举,其实只需 if Something 即可(这样才是规范的代码)。</SPAN>
</TD></TR></TBODY></TABLE>
<DIV align=right><A id=CommnetList1_CommnetList1_Morelink
href="http://comment.csdn.net/Comment.aspx?c=2&s=75146">【评论】</A>
<A id=CommnetList1_CommnetList1_Hyperlink1
href="javascript:window.close();">【关闭】</A> <A
href="mailto:webmaster@csdn.net">【报告bug】</A>
</DIV><BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM><!-- 版权 -->
<DIV align=center>
<SCRIPT language=JavaScript src="75146.files/footer_gb.js"
type=text/javascript></SCRIPT>
</DIV><!-- /版权 -->
<SCRIPT>
document.write("<img src=http://count.csdn.net/count/pageview1.asp?columnid=4&itemid=11 border=0 width=0 height=0>");
</SCRIPT>
<SCRIPT>document.write("<img src=http://counter.csdn.net/pv.aspx?id=37 border=0 width=0 height=0>");</SCRIPT>
<SCRIPT language=JavaScript src=""></SCRIPT>
</BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -