Example #1
0
        public int Read(int Bytes2Read)
        {
            if (Bytes2Read == 0)
            {
                Bytes2Read = this.miBufferSize;
            }
            if (this.mhRS == -1)
            {
                throw new ApplicationException("Please initialize and open port before using this method");
            }
            int num1 = 0;

            try
            {
                if (this.meMode == Rs232.Mode.Overlapped)
                {
                    this.pHandleOverlappedRead(Bytes2Read);
                }
                else
                {
                    this.mabtRxBuf = new byte[checked (Bytes2Read - 1 + 1)];
                    int    mhRs                 = this.mhRS;
                    byte[] mabtRxBuf            = this.mabtRxBuf;
                    int    nNumberOfBytesToRead = Bytes2Read;
                    int    num2                 = 0;
                    // ISSUE: explicit reference operation
                    // ISSUE: variable of a reference type
                    int lpNumberOfBytesRead     = @num2;
                    Rs232.OVERLAPPED overlapped = (Rs232.OVERLAPPED)((object)null ?? Activator.CreateInstance(typeof(Rs232.OVERLAPPED)));
                    // ISSUE: explicit reference operation
                    // ISSUE: variable of a reference type
                    Rs232.OVERLAPPED lpOverlapped = @overlapped;
                    int num3 = Rs232.ReadFile(mhRs, mabtRxBuf, nNumberOfBytesToRead, ref lpNumberOfBytesRead, ref lpOverlapped);
                    if (num3 == 0)
                    {
                        throw new ApplicationException("ReadFile error " + num3.ToString());
                    }
                    if (num2 < Bytes2Read)
                    {
                        throw new Rs232.IOTimeoutException("Timeout error");
                    }
                    this.mbWaitOnRead = true;
                    num1 = num2;
                }
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception innerException = ex;
                throw new ApplicationException("Read Error: " + innerException.Message, innerException);
            }
            return(num1);
        }
Example #2
0
 public void Write(byte[] Buffer)
 {
     if (this.mhRS == -1)
     {
         throw new ApplicationException("Please initialize and open port before using this method");
     }
     try
     {
         if (this.meMode == Rs232.Mode.Overlapped)
         {
             if (this.pHandleOverlappedWrite(Buffer))
             {
                 throw new ApplicationException("Error in overllapped write");
             }
         }
         else
         {
             Rs232.PurgeComm(this.mhRS, 12);
             int    mhRs    = this.mhRS;
             byte[] Buffer1 = Buffer;
             int    length  = Buffer.Length;
             int    num     = 0;
             // ISSUE: explicit reference operation
             // ISSUE: variable of a reference type
             int lpNumberOfBytesWritten  = @num;
             Rs232.OVERLAPPED overlapped = (Rs232.OVERLAPPED)((object)null ?? Activator.CreateInstance(typeof(Rs232.OVERLAPPED)));
             // ISSUE: explicit reference operation
             // ISSUE: variable of a reference type
             Rs232.OVERLAPPED lpOverlapped = @overlapped;
             if (Rs232.WriteFile(mhRs, Buffer1, length, ref lpNumberOfBytesWritten, ref lpOverlapped) == 0)
             {
                 throw new ApplicationException("Write Error - Bytes Written " + num.ToString() + " of " + Buffer.Length.ToString());
             }
         }
     }
     catch (Exception ex)
     {
         ProjectData.SetProjectError(ex);
         throw;
     }
 }
Example #3
0
 private static extern int WriteFile(int hFile, byte[] Buffer, int nNumberOfBytesToWrite, ref int lpNumberOfBytesWritten, ref Rs232.OVERLAPPED lpOverlapped);
Example #4
0
 private static extern int WaitCommEvent(int hFile, ref Rs232.EventMasks Mask, ref Rs232.OVERLAPPED lpOverlap);
Example #5
0
 private static extern int ReadFile(int hFile, byte[] Buffer, int nNumberOfBytesToRead, ref int lpNumberOfBytesRead, ref Rs232.OVERLAPPED lpOverlapped);
Example #6
0
 private static extern int GetOverlappedResult(int hFile, ref Rs232.OVERLAPPED lpOverlapped, ref int lpNumberOfBytesTransferred, int bWait);