CBDCBBaudRateStrToI
tComboBox2TextDCBByteSizeStrToI
tComboBox3TextDCBParityComboBox4ItemI
dexDCBStopBitsComboBox5ItemI
dexCo
ectedSetCommStateCommHa
dleDCB
f关系串口的读事件if
otSetCommMaskCommHa
dleEV_RXCHARthe
begi
MessageBox0SetCommMaskErrorNoticeMB_OKExite
d
ifCo
ectedthe
begi
bt
Ope
ComE
abledFalsee
delsebegi
CloseHa
dleCommHa
dleStatusBar1SimpleText设置串口失败e
de
d
procedureTForm1FormCreateSe
derTObjectbegi
Co
ectedFalseComboBox1ItemI
dex0ComboBox2ItemI
dex0ComboBox3ItemI
dex4ComboBox4ItemI
dex0ComboBox5ItemI
dex0e
d
procedureTForm1bt
CloseComClickSe
derTObjectbegi
if
otCo
ectedthe
fbegi
StatusBar1SimpleText未打开串口Exite
dReceiveFalse取消事件监视,此时监视线程中的WaitCommEve
t将返回SetCommMaskCommHa
dle0等待监视线程结束WaitForSi
gleObjectPostEve
tINFINITE关闭事件句柄CloseHa
dlePostEve
t停止发送和接收数据,并清除发送和接收缓冲区PurgeCommCommHa
dlePURGE_TXABORTPURGE_TXCLEARorPURGE_RXCLEAR关闭其他的句柄CloseHa
dleReadOshEve
tCloseHa
dleCommHa
dlebt
Ope
ComE
abledTrueCo
ectedFalseStatusBar1SimpleText串口已经关闭e
dorPURGE_RXABORTor
procedureTForm1bt
Se
dDataClickSe
derTObjectvarStrStri
giI
tegerwriteoverlappedTOverlappedByteToWriteBytesWritte
AllBytesWritte
DWORDErrorCodeErrorFlagDWORDCommStatCOMSTAT
fbegi
if
otCo
ectedthe
begi
StatusBar1SimpleText未打开串口Exite
d
ifMemo1GetTextLe
0the
begi
StatusBar1SimpleText缓冲区为空Exite
d
AllBytesWritte
0fori0tomemo1Li
esCou
t1dobegi
Strmemo1Li
esiByteToWritele
gthStriftryStatusBar1SimpleText正在发送数据初始化一步读写结构FillCharwriteoverlappedSizeofwriteoverlapped0避免贡献资源冲突writeoverlappedhEve
tCreateEve
t
ilTrueFalse
il发送数据ifWriteFileCommha
dleStr1ByteToWriteBytesWritte
writeoverlappedthe
begi
otByteToWrite0the
co
ti
ue
fErrorCodeGetLastErrorifErrorCode0the
begi
ifErrorCodeERROR_IO_PENDINGthe
begi
StatusBar1SimpleText端口忙,正在等待whileGetOverlappedResultCommha
dlewriteoverlappedBytesWritte
Truedobegi
ErrorCodeGetLastErrorifErrorCodeERROR_IO_PENDINGthe
co
ti
ueelsebegi
ot
ClearCommErrorCommha
dleErrorFlagCommStatshowmessage发送数据出错CloseHa
dleWriteOverlappedhEve
tCloseHa
dleCommha
dlebt
Ope
ComE
abledTrueExite
de
dAllBytesWritte
AllBytesWritte
BytesWritte
e
delsebegi
ClearCommErrorCommha
dleErrorFlagCommStatshowmessage发送数据出错CloseHa
dleWriteOverlappedhEve
tReceiveFalseCloseHa
dleCommha
dle
fCloseHa
dlePostEve
tr