コード例 #1
0
        public void Clear()
        {
            // Zero all bytes
            Array.Clear(mIoBuffer, 0, mIoBuffer.Length);

            mIoStatus = SendReceiveStatus.IO_PENDING;
        }
コード例 #2
0
        //
        // Summary:
        //     Reads numBytes into the data buffer at the specified offset.
        //
        // Parameters:
        //   data:
        //     The input data buffer.
        //
        //   offset:
        //     The zero based offset in the data buffer to write the data read.
        //
        //   numBytes:
        //     The number of bytes to read.
        //
        // Returns:
        //     The receive status, IO_SUCCESS if all bytes were received
        //
        public SendReceiveStatus receiveBytes(byte[] data, int offset, int numBytes)
        {
            SendReceiveStatus status = SendReceiveStatus.IO_SUCCESS;
            int numRead   = 0;
            int numToRead = numBytes;

            try
            {
                //
                // Exceptions:
                //   System.ArgumentNullException:
                //     The buffer passed is null.
                //
                //   System.InvalidOperationException:
                //     The specified port is not open.
                //
                //   System.ArgumentOutOfRangeException:
                //     The offset or count parameters are outside a valid region of the buffer being
                //     passed. Either offset or count is less than zero.
                //
                //   System.ArgumentException:
                //     offset plus count is greater than the length of the buffer.
                //
                //   System.TimeoutException:
                //     No bytes were available to read.
                //
                do
                {
                    numRead  += Read(data, offset + numRead, numToRead);
                    numToRead = numBytes - numRead;
                } while (numRead < numBytes);
            }
            catch (System.ArgumentNullException)
            {
                status = SendReceiveStatus.IO_NULL_BUFFER;
            }
            catch (System.InvalidOperationException)
            {
                status = SendReceiveStatus.IO_PORT_ERROR;
            }
            catch (System.ArgumentOutOfRangeException)
            {
                status = SendReceiveStatus.IO_OUT_OF_RANGE;
            }
            catch (System.ArgumentException)
            {
                status = SendReceiveStatus.IO_OUT_OF_RANGE;
            }
            catch (System.TimeoutException)
            {
                status = SendReceiveStatus.IO_TIMEOUT;
            }
            catch (Exception)
            {
                status = SendReceiveStatus.IO_OTHER_EXCEPTION;
            }

            return(status);
        }
コード例 #3
0
ファイル: USBIO.cs プロジェクト: gstavrinos/seabreeze
        //----- ISendReceive Implementation -----

        //
        // Summary:
        //     Writes numBytes from the data buffer starting at the specified offset.
        //
        // Parameters:
        //   data:
        //     The output data buffer.
        //
        //   offset:
        //     The zero-based offset in the data buffer to start copying data.
        //
        //   numBytes:
        //     The number of bytes to be written.
        //
        // Returns:
        //     The send status, IO_SUCCESS if all bytes were sent
        //
        public SendReceiveStatus sendBytes(byte[] data, int offset, int numBytes)
        {
            SendReceiveStatus status = SendReceiveStatus.IO_SUCCESS;
            int numSent = 0;

            try
            {
                // Exceptions:
                //   System.ArgumentNullException:
                //     The buffer passed is null.
                //
                //   System.InvalidOperationException:
                //     The port is not open.
                //
                //   System.ArgumentOutOfRangeException:
                //     The offset or numBytes parameters are outside a valid region of the buffer being
                //     passed. Either offset or numBytes is less than zero.
                //
                //   System.ArgumentException:
                //     offset plus numBytes is greater than the length of the buffer.
                //
                //   System.ServiceProcess.TimeoutException:
                //     The operation did not complete before the time-out period ended.

                outPipe.Write(data, offset, numBytes);
                numSent = numBytes; // the entire numBytes is sent. If it cannot be sent an exception is thrown.
            }
            catch (System.ArgumentNullException)
            {
                status = SendReceiveStatus.IO_NULL_BUFFER;
            }
            catch (System.InvalidOperationException)
            {
                status = SendReceiveStatus.IO_PORT_ERROR;
            }
            catch (System.ArgumentOutOfRangeException)
            {
                status = SendReceiveStatus.IO_OUT_OF_RANGE;
            }
            catch (System.ArgumentException)
            {
                status = SendReceiveStatus.IO_OUT_OF_RANGE;
            }
            catch (System.TimeoutException)
            {
                status = SendReceiveStatus.IO_TIMEOUT;
            }
            catch (USBException)
            {
                status = SendReceiveStatus.IO_PIPE_ERROR;
            }
            catch (Exception)
            {
                status = SendReceiveStatus.IO_OTHER_EXCEPTION;
            }

            return(status);
        }
コード例 #4
0
ファイル: TcpIpIO.cs プロジェクト: AlexanderHickey/PHYS581
        //----- ISendReceive Implementation -----

        //
        // Summary:
        //     Writes numBytes from the data buffer starting at the specified offset.
        //
        // Parameters:
        //   data:
        //     The output data buffer.
        //
        //   offset:
        //     The zero-based offset in the data buffer to start copying data.
        //
        //   numBytes:
        //     The number of bytes to be written.
        //
        // Returns:
        //     The send status, IO_SUCCESS if all bytes were sent
        //
        public SendReceiveStatus sendBytes(byte[] data, int offset, int numBytes)
        {
            SendReceiveStatus status = SendReceiveStatus.IO_SUCCESS;
            int numSent = 0;

            try
            {
                // Exceptions:
                //   System.ArgumentNullException:
                //     buffer is null.
                //
                //   System.ArgumentOutOfRangeException:
                //     offset is less than 0.-or- offset is greater than the length of buffer.-or-
                //     size is less than 0.-or- size is greater than the length of buffer minus
                //     the value of the offset parameter.
                //
                //   System.Net.Sockets.SocketException:
                //     socketFlags is not a valid combination of values.-or- An operating system
                //     error occurs while accessing the System.Net.Sockets.Socket. See the Remarks
                //     section for more information.
                //
                //   System.ObjectDisposedException:
                //     The System.Net.Sockets.Socket has been closed.
                numSent = Send(data, offset, numBytes, SocketFlags.None);
                if (numSent != numBytes)
                {
                    status = SendReceiveStatus.IO_INSUFFICIENT_DATA;
                }
            }
            catch (System.ArgumentNullException)
            {
                status = SendReceiveStatus.IO_NULL_BUFFER;
            }
            catch (System.ObjectDisposedException)
            {
                status = SendReceiveStatus.IO_PORT_ERROR;
            }
            catch (System.ArgumentOutOfRangeException)
            {
                status = SendReceiveStatus.IO_OUT_OF_RANGE;
            }
            catch (System.Net.Sockets.SocketException)
            {
                status = SendReceiveStatus.IO_PORT_ERROR;
            }
            catch (System.TimeoutException)
            {
                status = SendReceiveStatus.IO_TIMEOUT;
            }
            catch (Exception)
            {
                status = SendReceiveStatus.IO_OTHER_EXCEPTION;
            }

            return(status);
        }
コード例 #5
0
        //----- Initialization Helpers -----

        public void Init()
        {
            // Zero all bytes
            Array.Clear(mIoBuffer, 0, mIoBuffer.Length);

            StartByte0 = 0xC1;
            StartByte1 = 0xC0;

            ProtocolVersion = 0x1100;
            BytesRemaining  = 20;
            SetFooter();

            mIoStatus = SendReceiveStatus.IO_PENDING;
        }
コード例 #6
0
 public SendReceiveResult(SendReceiveStatus status, IEnumerable<string> lines)
 {
     Status = status;
     Lines = lines;
 }
コード例 #7
0
 internal NoteSendReceiveStatusChangedEventArgs(SendReceiveStatus newStatus, SendReceiveStatus oldStatus)
 {
     _NewStatus = newStatus;
     _OldStatus = oldStatus;
 }
コード例 #8
0
 public OBPBuffer(OBPBuffer aBufferToClone)
 {
     mIoStatus = aBufferToClone.mIoStatus;
     mIoBuffer = new byte[aBufferToClone.mIoBuffer.Length];
     aBufferToClone.mIoBuffer.CopyTo(this.mIoBuffer, 0);
 }
コード例 #9
0
ファイル: PNEvents.cs プロジェクト: hyrmedia/PNotes.NET
 internal NoteSendReceiveStatusChangedEventArgs(SendReceiveStatus newStatus, SendReceiveStatus oldStatus)
 {
     _NewStatus = newStatus;
     _OldStatus = oldStatus;
 }