public void ParseSample(byte[] buffer, int offset, out int value, out int exponent, out DymoScaleUnit unit, out DymoScaleStatus status) { value = 0; exponent = 0; unit = 0; status = 0; if (buffer == null) { throw new ArgumentNullException("buffer"); } if (offset < 0 || buffer.Length - offset < ReportLength) { throw new ArgumentException("Not enough bytes.", "offset"); } if (buffer[offset + 0] != ReportID) { throw new IOException("Unexpected report ID."); } value = (int)(buffer[offset + 4] | buffer[offset + 5] << 8); status = (DymoScaleStatus)buffer[offset + 1]; if (status == DymoScaleStatus.StableUnderZero) { value = -value; } unit = (DymoScaleUnit)buffer[offset + 2]; exponent = (sbyte)buffer[offset + 3]; }
public static string GetNameFromUnit(DymoScaleUnit unit) { switch (unit) { case DymoScaleUnit.Milligram: return("mg"); case DymoScaleUnit.Gram: return("g"); case DymoScaleUnit.Kilogram: return("kg"); case DymoScaleUnit.Ounce: return("oz"); case DymoScaleUnit.Pound: return("lb"); default: return("?"); } }
public void ReadSample(out int value, out int exponent, out DymoScaleUnit unit, out DymoScaleStatus status, out bool buffered) { if (Stream == null) { throw new InvalidOperationException("Stream not set."); } buffered = true; while (_offset < ReportLength) { buffered = false; int count = Stream.Read(_buffer, _offset, _buffer.Length - _offset); _offset += count; } ParseSample(_buffer, 0, out value, out exponent, out unit, out status); Array.Copy(_buffer, ReportLength, _buffer, 0, _offset - ReportLength); _offset -= ReportLength; }
public static string GetNameFromUnit(DymoScaleUnit unit) { switch (unit) { case DymoScaleUnit.Milligram: return "mg"; case DymoScaleUnit.Gram: return "g"; case DymoScaleUnit.Kilogram: return "kg"; case DymoScaleUnit.Ounce: return "oz"; case DymoScaleUnit.Pound: return "lb"; default: return "?"; } }