Beispiel #1
0
        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];
        }
Beispiel #2
0
        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("?");
            }
        }
Beispiel #3
0
        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;
        }
Beispiel #4
0
 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 "?";
     }
 }
Beispiel #5
0
        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;
        }
Beispiel #6
0
        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];
        }