Introduction
The"flow"mentionedhere,ofcourse,referstothedataflow.Whendataistransmittedbetweentwoserialports,datalossoftenoccurs,ortheprocessingspeedsofthetwocomputersaredifferent,suchasthecommunicationbetweenadesktopcomputerandasingle-chipcomputer,andthereceivingenddatabufferisfull,socontinuetosendatthistimeTheincomingdatawillbelost.Weusemodemsfordatatransmissiononthenetwork,andthisproblemisparticularlyprominent.Flowcontrolcansolvethisproblem.Whenthereceivingendcannotprocessthedata,itsendsa"nolongerreceiving"signal,andthesendingendstopssendinguntilitreceivesthe"cancontinuesending"signalbeforesendingdata.Therefore,flowcontrolcancontroltheprocessofdatatransmissionandpreventdataloss.TwocommonlyusedflowcontrolsinPCsarehardwareflowcontrol(includingrts/cts,dtr/dsr,etc.)andsoftwareflowcontrolxon/xoff(continue/stop).
Howitworks
Whenthedatabufferatthereceivingendisfullandthedatacannotbeprocessed,itsendsa"nolongerreceiving"signal,andthesendingendstopssendinguntilthesendingendSendthedataafterreceivingthe"cancontinuesending"signal.Twokindsofflowcontrolcommonlyusedincomputersarehardwareflowcontrol(RTS/CTS,DTR/DSR,etc.)andsoftwareflowcontrol(XON/XOFF).
Hardwareflowcontrol
Hardwareflowcontrolmustbeconnectedtothecorrespondingcable.Commonmethodsofhardwareflowcontrolare:RTS/CTS(requesttosend/cleartosend)flowcontrolandDTR/DSR(dataterminalready/datasetready)flowcontrol.
WhenusingRTS/CTSflowcontrol,theRTSandCTSlinesatbothendsofthecommunicationmustbeconnectedcorrespondingly,andthedataterminalequipment(suchasacomputer)usesRTStostartthedataflowofthemodemorotherdatacommunicationequipment.Datacommunicationequipment(suchasamodem)usesCTStostartandpausethedatastreamfromthecomputer.Theprocessofthishardwarehandshakemethodis:setahigh-orderflag(canbe75%ofthebuffersize)andalow-orderflag(canbe25%ofthebuffersize)forthereceivingendbuffersizethroughtheprogram.Whentheamountofdatareachesthehighlevel,thereceivingendsetstheCTSlinelow(sendslogic0).WhentheprogramatthetransmittingenddetectsthatCTSislow,itstopssendingdatauntilthedatavolumeinthebufferatthereceivingendislowerthanthelowlevel.SetCTShigh.RTSisusedtoindicatewhetherthereceivingdeviceisreadytoreceivedata.
TheworkingmodeofDTR/DSRflowcontrolissimilartothatofRTS/CTSflowcontrol,soIwillnotrepeatit.
Softwareflowcontrol
Duetocablelimitations,hardwareflowcontrolisgenerallynotusedinordinarycontrolcommunications,butsoftwareflowcontrolisused.SoftwareflowcontrolisoftenimplementedthroughXON/XOFF.Theprocessofthissoftwarehandshakemethodis:whentheamountofdataintheinputbufferofthereceivingendexceedsthesethigh,XOFFcharactersaresenttothedatasendingend(decimal19orControl-S,thedeviceprogrammingmanualwillexplainindetail),ThesendingendimmediatelystopssendingdataafterreceivingtheXOFFcharacter;whenthedatavolumeintheinputbufferofthereceivingendislowerthanthesetlow,itwillsendtheXONcharacter(decimal17orControl-Q)tothedatasendingendtosendAfterreceivingtheXONcharacter,theterminalimmediatelystartstosenddata.Generally,youcanfindoutwhatcharactersaresentfromthesourceprogramofthedevice.
Comparisonofthetwocontrolmethods
Whenbinarydataistransmittedthroughsoftwareflowcontrol,flagcharactersmayalsoappearinthedataflowandcausemisoperation.ThisissoftwareflowcontrolThedefectofhardwareflowcontrolwillnothavethisproblem.