您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 微机串行通信协议研究
MSCommVB1MSCommMSCommMSCommWindowsWindows16MSCommCommPortSettingsPortOpenInputOutputInputMode01RthresholdRthreshold0OnCommRthreshold1MSCommOnCommSthreshold0OnCommSthreshold1MSCommOnCommMSComm(1)MSCommOnComm(2)CommEvent23InputMode=12.1Sthreshold=0outputRthreshold=1OnCommFormMSCommNmaxCommPortInStringNcountInStringMSCommOkTruePublicnCount(NmaxCommPort)AsLongPrivateSubForm_Load()DimiAsIntegerFori=0toNmaxCommPortComm(i).Settings=9600,n,8,1Comm(i).InputMode=0'Comm(i).Rthreshold=1'ReceiveComm(i).Sthreshold=0'SendNextICallMSCommOpenEndSubSubMScommOpen()OnErrorGoToErrHandlerDimiAsIntegerFori=0ToNmaxCommPort-1MSCommOk(i)=True(713800)VBMSCommMSCommVBStudyonProtocolofPersonalComputer'sSerialCommunicationLIWeizhongLEIYingjie(DepartmentofComputer,MissileInstitute,AirForceEngineeringUniversity,Sanyuan713800)AbstractThisPaperanalyzesthepropertiesofMSCommcontrolofVB,andgivesoutsomeprinciplesandskillstodesignserialcommunicationprotocolwithMSCommcontrol,relatedcodesarealsogiven.KewordsVBSerialcommunicationCommunicationprotocol274Vol.274ComputerEngineering20014April2001TP311.5210003428(2001)04018002A180nCount(i)=0Comm(i).PortOpen=TrueNextiDimNokAsIntegerNok=0Fori=0ToNmaxCommPort-1If(MSCommOk(i)=True)ThenNok=Nok+1NextiIf(Nok=0)ThenDimMsgAsString'DeclarevariableDimStyleAsString'DeclarevariableDimTitleAsString'DeclarevariableMsg=Chr$(13)+Space$(5)Msg=Msg+!+Space$(8)+Chr$(13)+Chr$(13)Msg=Msg+Space$(5)++Chr$(13)Style=vbOKOnly+vbCritical'DefinebuttonsMsgBoxMsg,Style,'DisplaymessageEndEndIfExitSubErrHandler:MSCommOk(i)=FalseResumeNextEndSubSubMScommClose()DimiAsIntegerOnErrorResumeNext'CloseMSCommsFori=0ToNmaxCommPort-1Comm(i).PortOpen=FalseNextiEndSubSubcomReceive(IndexAsInteger)DimRS$If(Comm(Index).InBufferCount=0)ThenExitSubComm(Index).InputLen=0'Default,RetrieveallavailabledataRS$=Comm(Index).Input'ReaddataInString(Index)=InString(Index)+RS$EndSub'InStringPrivateSubComm_OnComm(IndexAsInteger)SelectCaseComm(Index).CommEventCasecomEvReceive'ReceivedRThreshold#ofchars.CallcomReceive(Index)CasecomEvCD'ChangeintheCDlineCasecomEvCTS'ChangeintheCTSlineCasecomEvDSR'ChangeintheDSRlineCasecomEvRing'ChangeintheRingIndicatorCasecomEvSend'ThereareSThresholdnumberof'charactersinthetransmitbuffer.CasecomEvEOF'AnEOFcharaterwasfoundinCasecomBreak'ABreakwasreceivedCasecomCDTO'CD(RLSD)TimeoutCasecomCTSTO'CTSTimeoutCasecomDSRTO'DSRTimeou.CasecomFrame'FramingErrorCasecomOverrun'DataLostCasecomRxOver'ReceivebufferoverflowCasecomRxParity'ParityErrorCasecomTxFull'TransmitbufferfullEndSelectEndSubPrivateSubForm_QueryUnload(CancelAsInteger,UnloadModeAsInteger)Cancel=1EndSubPrivateSubForm_Unload(CancelAsInteger)CallMScommCloseEndSub2.2ASCIIChr(13)Chr(13)MSCommSend()GetMsgfromCom()TrueOptionExplicitPublicConstNmaxCommPort=16'PublicMSCommOk(NmaxCommPort)AsBoolean'PublicInString(NmaxCommPort)AsString'PublicnCount(NmaxCommPort)AsLong'PublicFunctionGetMsgfromCom(PortNumAsInteger,MsgStrAsString)AsBooleanDimiAsIntegerFori=0ToNmaxCommPort-1nCom=(nCom+1)ModNmaxCommPortIfMSCommOk(nCom)AndInString(nCom)ThenExitForNextiIf(i=NmaxCommPort)ThenGetMsgfromCom=False'ExitFunctionEndIfi=InStr(InString(nCom),Chr$(13))If(i=0)ThenGetMsgfromCom=False'If(Len(InString(nCom))600)ThenInString(nCom)=Right$(InString(nCom),600)ExitFunctionEndIf(187)18151MichaelH,HasanR.CohesioninEnglish.LongmanGroupLtd.,19762MillerGA,BeckwithR,FellbaumR,etal.FivePapersonWordNet.GSLReport43,CognitiveScienceLaboratory,PrincetonUniversity,19933Stairmand,MarkA.AComputationalAnalysisofLexicalCohesionwithApplicationsinInformationRetrieval[Ph.D.Thesis].CenterforComputationalLinguistics,UMIST,Manchester,1996(181)PortNum=nComIf(i1)Then',Chr$(13)MsgStr=Left$(InString(nCom),i-1)ElseMsgStr=EndIfIf(Len(InString(nCom))i)ThenInString(nCom)=Right$(InString(nCom),Len(InString(nCom))-i)ElseInString(nCom)=EndIfGetMsgfromCom=TrueEndFunctionPublicSubMSCommSend(PortAsInteger,SndStrAsString)SndStr=SndStr+Chr$(13)If(MSCommOk(Port)=True)ThenSio.Comm(Port).output=SndStrEndIfEndSub2.3ASCIIMSCommSend()GetMsgfromCom()PublicTypeMyMsg'Tr1AsSingleTr2AsSingleSd1AsIntegerSd2AsIntegerEndTypeSubSendMsg(portAsInteger,Msg1AsMyMsg)Dims1AsStrings1=Format$(Msg1.Tr1,00000.000)+Format$(Msg1.Tr2,00000.000)s1=s1+Format$(Msg1.Sd1,00000)+Format$(Msg1.Sd2,00000)CallMSCommSend(port,s1)EndSubFunctionGetMsg(portAsInteger,Msg1AsMyMsg)Dims1AsStringIf(GetMsgfromCom(port,s1)=FalseOrLen(s1)28)ThenGet_keys=FalseExitFunctionEndIfMsg1.Tr1=Mid$(s1,1,9)Msg1.Tr2=Mid$(s1,10,9)Msg1.Sd1=Mid$(s1,19,5)Msg1.Sd2=Mid$(s1,24,5)EndFunction3C3I21,.VisualBasicMSComm.1999,25(7):982.VBBinary.,1999(12)3SileB.VisualBasic6.,1999187
本文标题:微机串行通信协议研究
链接地址:https://www.777doc.com/doc-316296 .html