First, we will talk about wiring. To trigger events on CTS and other pins, a high level must be applied to the CTS and other pins. The source of the high level can come from the fourth foot, and the fourth foot must be set to a high level in the software.
C # Some code is as follows:
MSP. portName = "COM1"; mSP. baudRate = 9600; mSP. dtrEnable = true; // This is the advanced mSP for DTR. rtsEnable = true; // This is the high-level mSP for RTS. 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 Detection Carrier Detect) // 2 RXD receives data Receive) // 3 TXD sends data Transmit) // 4 prepare Data Terminal Ready for DTR Data Terminal) // 5 GND Ground) // 6 DSR Data prepare Data Set Ready) // 7 Send a Request To Send a RTS Request) // 8 CTS Clear Send Clear To Send) // 9 RI Ring Indicator) if (e. eventType = System. IO. ports. serialPinChange. ctsChanged) // pin 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) // Pin 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) // Pin 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) // pin 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) // pin {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 ");}}
This article is from the "cnming" blog, please be sure to keep this source http://cnming.blog.51cto.com/324450/1267091