title: Request Weight Value from Scale through COM
body: <p>I've been trying to retrieve the weight value from two different scales using a COM Serial Port.</p>
  
  <p>The scales are a CAS ER Plus and a UWE AM-15K.</p>
  
  <p>I've already managed to create a small program to start the communication between a PC and the Scales but i'm running into a problem and I've been unable to find a solution.</p>
  
  <p>I can send an ENQ command and I receive the ACK sucessfully from both scales, but when I send the DC1 command to retrieve the weight, I always get various variations from the messages </p>
  
  <blockquote>
    <p>"Hex number must be smaller than 7fffffffffffffff"</p>
  </blockquote>
  
  <p>And</p>
  
  <blockquote>
    <p>"Hex Value Must be Maximum Length of 32 characters."</p>
  </blockquote>
  
  <p>My code to configure the COM Port is the following:</p>
  
  <pre><code>Try
          comport.PortName = "COM1"
          comport.BaudRate = 9600
          comport.Parity = Parity.None
          comport.DataBits = 8
          comport.StopBits = StopBits.One
          comport.Handshake = Handshake.XOnXOff
          If DTRCheck.Checked Then
              comport.DtrEnable = True
          End If
          If RTSCheck.Checked Then
              comport.RtsEnable = True
          End If
          'Dim encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("IBM860")
          Dim encoding As System.Text.Encoding = System.Text.Encoding.ASCII
          comport.Encoding = encoding
          comport.Open()
          erroCOM = False
      Catch ex As Exception
          erroCOM = True
      End Try
  </code></pre>
  
  <p>My code to send the commands:</p>
  
  <pre><code> If comport.IsOpen Then
          TxtValor.Clear()
          Try
              If EnqComBtn.Checked Then 'Verify if the scale is "listening"
                  ListBox1.Items.Add("PC: ENQ - &gt;")
                  comport.Write(New Byte() {&amp;H5}, 0, 1)
                  Thread.Sleep(20)
                  ListBox1.Items.Add("PC: DC1 - &gt;")
                  comport.Write(New Byte() {&amp;H11}, 0, 1)
              End If
              If DC1ComBtn.Checked Then 'Request weight value
                  ListBox1.Items.Add("PC: DC1 - &gt;")
                  comport.Write(New Byte() {&amp;H11}, 0, 1)
                  Thread.Sleep(20)
              End If
          Catch ex As Exception
  
          End Try
  
      End If
  </code></pre>
  
  <p>After sending the commands, I have the program reading the value received through the DataReceived event from the COM Serial Port and converting the Hex values to Decimal.</p>
  
  <p>EDIT:</p>
  
  <p>This is the code I use to read the Bytes received and convert them from Byte to Hex. I found this code on another post here on StackOverflow and edited out the spaces part.</p>
  
  <p>Private Sub comport_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles comport.DataReceived</p>
  
  <pre><code>    Dim RXByte As Byte
      Do
          RXCnt = 0
          Do
              RXByte = comport.ReadByte
              RXArray(RXCnt) = LookUpTable(RXByte &gt;&gt; 4) ' Convert each byte to two hexadecimal characters 
              RXCnt = RXCnt + 1
              RXArray(RXCnt) = LookUpTable(RXByte And 15)
              RXCnt = RXCnt + 1
          Loop Until (comport.BytesToRead = 0)
          '----- End of communication protocol handling ------------------------------------------------------------- 
  
          Me.Invoke(New MethodInvoker(AddressOf Display)) ' Start "Display" on the UI thread 
  
      Loop Until (comport.BytesToRead = 0)  ' Don't return if more bytes have become available in the meantime 
  
  End Sub
  </code></pre>
  
  <p>Has anyone found this problem before and if so, have you found a solution?
  Thanks!</p>