I was able to read (and decode) the USB stream from the DYMO M10 scale using Gambas and a couple shell commands. During this exercise I've learned the dymo scales uses a raw stream to output an array of 6 elements. After finding a Perl script that allowed me to see what the actual output was, it was just a matter of replicating it in Gambas. This turned out much easier than I had originally thought it would be. Below is the final code showing exactly how easy it was. Thanks to cogier for posting his example that I was able to build off of.
Starting with cogier's code, I move the hProc from the Form_Open() sub to a buttonStart_Click() sub so I could restart the process whenever the scales went into auto-off.
Next I needed to make sure I was using the correct HID device so I grep'd a single line in dmesg for "DYMO M10" and took it's output and pulled the correct HID device from it, plugging that into the hProc command.
Reading the stream output as Byte correctly displayed the stream which allowed each element to be added to an array (iData[0-5]).
The 6 elements are:
- The 1st element is unknown. It could be an error state with '3' being normal operation.
The 2nd element indicates the state the scale is in. (values: 2, 4, 5, 6) '2' = zero weight, '4' = positive weight, '5' = negative weight, '6' = over max weight
The 3rd element (either 2 or 11) is what the unit of weight mode the scale is in (ounces/kilograms).
The 4th element is for calculating the scaling factor while the scale is in ounce mode. (values: 0, 254, 255)
The 5th and 6th elements are used for calculating the weight.
A Timer can be used to continuously check for when the scales come on-line.
Hopefully someone can use this as a starting point to read other scales (or usb/hidraw devices).
Code: Select all
' Gambas class file Public hProc As Process Public Sub Form_Open() Label1.Text = "Make sure power is on, then press the start button." End Public Sub buttonStart_Click() Dim sOutput As String Shell "dmesg | grep \"DYMO M10\" | head -n 1" To sOutput sOutput = Mid$(sOutput, InStr(sOutput, "hidraw"), 7) hProc = Exec ["sudo", "cat", "/dev/" & sOutput] For Read As "plugin" Label1.Text = "Ready to weigh." End Public Sub plugin_Kill() TextBox1.Text = Null TextBox2.Text = Null TextBox3.Text = Null TextBox4.Text = Null TextBox5.Text = Null TextBox6.Text = Null Label1.Text = "Scales is off-line." End Public Sub plugin_Read() Dim iTemp As Integer Dim iData As New Integer Dim i As Integer For i = 0 To 5 iTemp = Read #Last As Byte iData.Add(iTemp, i) Next TextBox1.Text = iData TextBox2.Text = iData TextBox3.Text = iData TextBox4.Text = iData TextBox5.Text = iData TextBox6.Text = iData End Public Sub Form_Close() Try hProc.Kill End Public Sub ButtonExit_Click() Try hProc.Kill Me.Close End
[edit: corrected/updated element list.]