Interpret Mettler Toledo results

gopalv
gopalv used Ask the Experts™
on
Hi,
   I am trying to read data from a Mettler Toledo weighing scale using a C# application. The scale is connect to my laptop via a USB cable. See attached the code I am using to read the data from the scale. The code works fine (i think) and am able to get data from the scale. My problem is i do not know how to interpret this data and how it can be used in final weight calculation so that the user can see it. I dont see any element in the data returned that corresponds directly to the final weight i see on the scale itself. I tried weighing several items and recording the data returned by the scale in an attempt to "figure" out the logic but without luck. Here are the details:

1. I consistently get back 6 data elements.
2.  Details of the weight record and data returned by scale for 6 different wights:

 Wt: 2.85    Data returned: 4  4  12  254  29  1
 Wt: 4.05    Data returned: 3  4  12  254  149  1
 Wt: 4.90    Data returned: 3  4  12  254  234  1
 Wt: 0.85    Data returned: 4  4  12  254  85   0
 Wt: 8.35    Data returned: 3  4  12  254  67  1

What do these 6 data elements represent? How can I use those numbers to display the weight of the package to the user?  Any help you can provide is appreciated.
private void MyUSB_READThreadMethod() 
		{
            try
            {
                // int data = 0;
                int i = 0;
                string dataText = "";
                // int myPtrToPreparsedData = -1;
                if (myUSB.CT_HidD_GetPreparsedData(myUSB.HidHandle, ref myPtrToPreparsedData) != 0)
                {
                    int code = myUSB.CT_HidP_GetCaps(myPtrToPreparsedData);
                    //textBox2.Text = textBox2.Text + ("Waiting for data" + "\r\n");
                    while (true)
                    {

                        i = i + 1;
                        byte[] myRead = myUSB.CT_ReadFile(myUSB.myHIDP_CAPS.InputReportByteLength);


                        if (myRead != null)
                        {
                            for (int ii = 0; ii < myRead.Length; ii++)
                            {
                                dataText += myRead[ii].ToString() + "  ";

                            }

                            textBox2.AppendText("Read:  " + i.ToString() + "-  " + dataText + "\r\n");
                            dataText = "";
                        }
                        // Keep the size of the text limited to a max size
                        if (textBox2.TextLength >= 30000)
                        {
                            //	textBox2.Text = "";
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

			//
			//
		}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
The last two byte values seem to be 16 bit integers that represent the weights in fixed decimal point.  The attached code snippet produces the following output:
***Found Match for 285
***Found Match for 405
***Found Match for 490
***Found Match for 85
Expected 835 Actual 323

The only mismatch is the last value I am hoping is just an error.

Have you searched the companies web site for documentation?

static void Main()
{
            int ofs = 4;
            int[] expectedValues = new int[] {
                285,
                405,
                490,
                085,
                835
            };
            byte[][] byteValues = new byte[][] {
                    new byte[] {4, 4, 12, 254, 29, 1 },
                    new byte[] {3, 4, 12, 254, 149, 1 },
                    new byte[] {3, 4, 12, 254, 234, 1 },
                    new byte[] {4, 4, 12, 254, 85,  0 },
                    new byte[] {3, 4, 12, 254, 67, 1 }
                    };
            for (int i = 0; i < byteValues.Length; i++) 
            {
                Int16 value = BitConverter.ToInt16(byteValues[i], ofs);
                if (value == expectedValues[i])
                    System.Console.WriteLine("***Found Match for " + value);
                else
                    System.Console.WriteLine("Expected {0} Actual {1}", expectedValues[i], value);
            }
}

Open in new window

Author

Commented:
U the man!! I tested it with several measurements and that works fine. Thanks a lot! I did try looking at their site but could not find any docs that have this.  I am sure it is there somewhere but its not easy to find.  

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial