Beispiel #1
0
 /// <summary>
 /// 清空缓冲区数据
 /// </summary>
 /// <param name="func">0清空输入,1清空输出,2清空输入输出</param>
 public void ClearBuffer(int func)
 {
     try
     {
         int result = PcommApi.sio_flush(PortIndex, func);
         GetErrorCode(result);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #2
0
 /// <summary>
 /// 设置端口的参数
 /// </summary>
 public void SetIoctl()
 {
     try
     {
         int result = PcommApi.sio_ioctl(PortIndex, (int)baudrate, (int)databit | (int)stopbit | (int)parity);
         GetErrorCode(result);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #3
0
 /// <summary>
 /// 写入缓冲的数据
 /// </summary>
 /// <param name="by">数组集合</param>
 /// <param name="len">写入的长度</param>
 public void Write(byte[] by, int len)
 {
     try
     {
         int result = PcommApi.sio_write(PortIndex, by, len);
         GetErrorCode(result);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #4
0
 /// <summary>
 /// 关闭端口
 /// </summary>
 public void Close()
 {
     try
     {
         if (PortIndex == -1)
         {
             return;
         }
         int result = PcommApi.sio_close(PortIndex);
         GetErrorCode(result);
         PortIndex = -1;
         _portname = string.Empty;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #5
0
 /// <summary>
 /// 打开端口
 /// </summary>
 public void Open()
 {
     try
     {
         if (PortIndex < 0 || PortIndex > 255)
         {
             throw new ArgumentOutOfRangeException("PortIndex");
         }
         int result = PcommApi.sio_open(PortIndex);
         GetErrorCode(result);
         SetIoctl();
         //result = WinApi.sio_SetWriteTimeouts(PortIndex, 100);
         //GetErrorCode(result);
         if (portdatareceived != null)
         {
             PcommApi.sio_cnt_irq(PortIndex, portdatareceived, 1);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #6
0
 /// <summary>
 /// 获取缓冲区数据的长度
 /// </summary>
 /// <returns></returns>
 public int GetBytesToRead()
 {
     return(PcommApi.sio_iqueue(PortIndex));
 }