您好,登錄后才能下訂單哦!
首先講接線,要觸發(fā)CTS等引腳的事件,必須對CTS等引腳施加一個高電平。高電平的來源可以來自第四腳,同時必須在軟件中對第四腳置高電平。
C#部分代碼如下
mSP.PortName = "COM1"; mSP.BaudRate = 9600; mSP.DtrEnable = true; //這里是對DTR置高電平 mSP.RtsEnable = true; //這里是對RTS置高電平 mSP.Open(); mSP.PinChanged += mSP_PinChanged; int mSPPinCount = 0; StringBuilder mSB = new StringBuilder(); System.DateTime mDTPinLast = System.DateTime.Now; void mSP_PinChanged(object sender, System.IO.Ports.SerialPinChangedEventArgs e) { if (((System.TimeSpan)(System.DateTime.Now - mDTPinLast)).TotalMilliseconds < HealthyExamination.Common.BaseC.GlobeValues.LocalParas.CaptureSerialPortPinDelayMS) { return; } mDTPinLast = System.DateTime.Now; mSPPinCount++; //引腳 簡寫 功能說明 //1 CD 載波偵測(Carrier Detect) //2 RXD 接收數(shù)據(jù)(Receive) //3 TXD 發(fā)送數(shù)據(jù)(Transmit) //4 DTR 數(shù)據(jù)終端準(zhǔn)備(Data Terminal Ready) //5 GND 地線(Ground) //6 DSR 數(shù)據(jù)準(zhǔn)備好(Data Set Ready) //7 RTS 請求發(fā)送(Request To Send) //8 CTS 清除發(fā)送(Clear To Send) //9 RI 振鈴指示(Ring Indicator) if (e.EventType == System.IO.Ports.SerialPinChange.CtsChanged) //引腳8 { mSB.Insert(0, System.DateTime.Now.ToString("mm:ss:ffff") + "\t" + "CtsChanged mSPPinCount=" + mSPPinCount.ToString() + "\r\n"); } else if (e.EventType == System.IO.Ports.SerialPinChange.CDChanged) //引腳1? { mSB.Insert(0, System.DateTime.Now.ToString("mm:ss:ffff") + "\t" + "CDChanged mSPPinCount=" + mSPPinCount.ToString() + "\r\n"); } else if (e.EventType == System.IO.Ports.SerialPinChange.DsrChanged) //引腳6 { mSB.Insert(0, System.DateTime.Now.ToString("mm:ss:ffff") + "\t" + "DsrChanged mSPPinCount=" + mSPPinCount.ToString() + "\r\n"); } else if (e.EventType == System.IO.Ports.SerialPinChange.Ring) //引腳9 { mSB.Insert(0, System.DateTime.Now.ToString("mm:ss:ffff") + "\t" + "Ring mSPPinCount=" + mSPPinCount.ToString() + "\r\n"); } else if (e.EventType == System.IO.Ports.SerialPinChange.Break) //引腳 { mSB.Insert(0, System.DateTime.Now.ToString("mm:ss:ffff") + "\t" + "Break mSPPinCount=" + mSPPinCount.ToString() + "\r\n"); } else { mSB.Insert(0, System.DateTime.Now.ToString("mm:ss:ffff") + "\t" + "Others mSPPinCount=" + mSPPinCount.ToString() + "\r\n"); } }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。