日期:2014-05-17  浏览次数:20980 次

serialport 开发 rs232脚 COM1 接口程序,发信测试成功,但就是接收不到信息,请前辈出手相救!!万分感谢!!

Form1.cs


 public Form1()
        {
            InitializeComponent();
        }

      
        //初始化SerialPort对象方法.PortName为COM口名称,例如"COM1","COM2"等,注意是string类型
       public void InitCOM(string PortName)
         {
             serialPort1 = new SerialPort(PortName);
             serialPort1.BaudRate = 9600;//波特率
             serialPort1.Parity = Parity.None;//无奇偶校验位
             serialPort1.StopBits = StopBits.Two;//两个停止位
             serialPort1.Handshake = Handshake.RequestToSend;//控制协议
             serialPort1.ReceivedBytesThreshold = 4;//设置 DataReceived 事件发生前内部输入缓冲区中的字节数
           
        }

        
 
         //打开串口的方法
         public void OpenPort()
         {
             try
             {
                 serialPort1.Open();
             }
             catch { }
             if (serialPort1.IsOpen)
             {
                 Console.WriteLine("the port is opened!");
             }
             else
            {
                 Console.WriteLine("failure to open the port!");
             }
         }

         //关闭串口的方法
         public void ClosePort()
         {
             serialPort1.Close();
             if (!serialPort1.IsOpen)
            {
     &n