欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實現(xiàn)把指定數(shù)據(jù)寫入串口

 更新時間:2015年06月16日 11:34:37   投稿:junjie  
這篇文章主要介紹了C#實現(xiàn)把指定數(shù)據(jù)寫入串口,直接給出示例代碼,需要的朋友可以參考下
    public static bool WriteToSerialPort(byte[]byteArr)
    {
      SerialPort Com = newSerialPort();
      try
      {
        Com.ReadTimeout = 5000;
        Com.WriteTimeout = 5000;
        Com.PortName = "Com1";
        Com.BaudRate = 9600;
        Com.StopBits = StopBits.One;
        Com.Parity = Parity.None;
        Com.Open();
        Com.Write(byteArr, 0,byteArr.Length);
        return true;
      }
      catch(Exception ex)
      {
        return false;
      }
      finally
      {
        Com.Close();
      }      
    }

本例使用的是方法Write(Byte[]buffer, Int32 offset, Int32 count)。該方法使用緩沖區(qū)的數(shù)據(jù)將指定數(shù)量的字節(jié)寫入串行端口。buffer為緩沖區(qū),offset表示從此處開始將字節(jié)復(fù)制到端口,count表示要寫入的字節(jié)數(shù)。

相關(guān)文章

最新評論