IStreamResource.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. namespace NModbus.IO
  3. {
  4. /// <summary>
  5. /// Represents a serial resource.
  6. /// Implementor - http://en.wikipedia.org/wiki/Bridge_Pattern
  7. /// </summary>
  8. public interface IStreamResource : IDisposable
  9. {
  10. /// <summary>
  11. /// Indicates that no timeout should occur.
  12. /// </summary>
  13. int InfiniteTimeout { get; }
  14. /// <summary>
  15. /// Gets or sets the number of milliseconds before a timeout occurs when a read operation does not finish.
  16. /// </summary>
  17. int ReadTimeout { get; set; }
  18. /// <summary>
  19. /// Gets or sets the number of milliseconds before a timeout occurs when a write operation does not finish.
  20. /// </summary>
  21. int WriteTimeout { get; set; }
  22. /// <summary>
  23. /// Purges the receive buffer.
  24. /// </summary>
  25. void DiscardInBuffer();
  26. /// <summary>
  27. /// Reads a number of bytes from the input buffer and writes those bytes into a byte array at the specified offset.
  28. /// </summary>
  29. /// <param name="buffer">The byte array to write the input to.</param>
  30. /// <param name="offset">The offset in the buffer array to begin writing.</param>
  31. /// <param name="count">The number of bytes to read.</param>
  32. /// <returns>The number of bytes read.</returns>
  33. int Read(byte[] buffer, int offset, int count);
  34. /// <summary>
  35. /// Writes a specified number of bytes to the port from an output buffer, starting at the specified offset.
  36. /// </summary>
  37. /// <param name="buffer">The byte array that contains the data to write to the port.</param>
  38. /// <param name="offset">The offset in the buffer array to begin writing.</param>
  39. /// <param name="count">The number of bytes to write.</param>
  40. void Write(byte[] buffer, int offset, int count);
  41. }
  42. }