脚踏编程及接线方法
首先讲接线,要触发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"); } }
网页标题:脚踏编程及接线方法
文章链接:http://myzitong.com/article/gogosi.html