您好,登錄后才能下訂單哦!
首先講接線,要觸發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 接收數據(Receive) //3 TXD 發送數據(Transmit) //4 DTR 數據終端準備(Data Terminal Ready) //5 GND 地線(Ground) //6 DSR 數據準備好(Data Set Ready) //7 RTS 請求發送(Request To Send) //8 CTS 清除發送(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"); } }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。