Ejemplo n.º 1
0
        public int Write(byte[] WriteBytes)
        {
            int result = 0;

            if (this.hComm != -1)
            {
                try
                {
                    SerialPort.OVERLAPPED oVERLAPPED = default(SerialPort.OVERLAPPED);
                    SerialPort.WriteFile(this.hComm, WriteBytes, WriteBytes.Length, ref result, ref oVERLAPPED);
                }
                catch
                {
                    LogMSG.AddInfo("串口写入错误!", 2);
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
 public byte[] Read(int NumBytes)
 {
     byte[] array  = new byte[NumBytes];
     byte[] array2 = new byte[0];
     if (this.hComm != -1)
     {
         try
         {
             SerialPort.OVERLAPPED oVERLAPPED = default(SerialPort.OVERLAPPED);
             int num = 0;
             SerialPort.ReadFile(this.hComm, array, NumBytes, ref num, ref oVERLAPPED);
             array2 = new byte[num];
             Array.Copy(array, array2, num);
         }
         catch
         {
             LogMSG.AddInfo("串口读数据错误!", 2);
         }
     }
     return(array2);
 }
Ejemplo n.º 3
0
 private static extern int WriteFile(int hFile, byte[] lpBuffer, int nNumberOfBytesToWrite, ref int lpNumberOfBytesWritten, ref SerialPort.OVERLAPPED lpOverlapped);
Ejemplo n.º 4
0
 private static extern int ReadFile(int hFile, byte[] lpBuffer, int nNumberOfBytesToRead, ref int lpNumberOfBytesRead, ref SerialPort.OVERLAPPED lpOverlapped);