Reading a USB stream from a DYMO M10 scales

User avatar
Got2BeFree
Posts: 15
Joined: Saturday 26th November 2016 2:52am

Reading a USB stream from a DYMO M10 scales

Post by Got2BeFree » Saturday 26th November 2016 4:13am

Hi all.

Anyone have any experience reading usb hid streams? This is new territory for me and I might not be doing this correctly, so any help is greatly appreciated.

I have a Dymo M10 scale that I would like to read the output stream, along trying to decode it. My first issues is an "access forbidden" error...

Code: Select all

hFile = Open "/dev/hidraw3" For Read Watch
Any ideas (short of running as root) to get around access permission? Changing access permissions only work until the scale goes into auto power-off. The hidraw file is recreated once the scale is powered on again and permissions are reset.

I'm not 100% sure what type of data type to use. When changing access permission on hidraw3, and running, this...

Code: Select all

Public Sub File_Read()

    Dim iByte As Byte

    Read #hFile, iByte
    Print "Got one byte: "; iByte

End
just outputs a steady stream of "3"'s. Using other data types just give me different output numbers.

From what I can find on the 'net, there should be a data packet of 6 elements. If I'm able to get this worked out, I'd like to tie the scale into the inventory system I wrote this past week.


If this output from dmesg is of any help...

Code: Select all

[1221565.175330] usb 2-8: USB disconnect, device number 34
[1221626.550068] usb 2-8: new low-speed USB device number 35 using ohci-pci
[1221626.744476] usb 2-8: New USB device found, idVendor=0922, idProduct=8003
[1221626.744489] usb 2-8: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[1221626.744496] usb 2-8: Product: M10 10 lb Digital Postal Scale
[1221626.744501] usb 2-8: Manufacturer: DYMO
[1221626.744506] usb 2-8: SerialNumber: 0071431044934
[1221626.772802] hid-generic 0003:0922:8003.0026: hiddev0,hidraw3: USB HID v1.01 Device [DYMO M10 10 lb Digital Postal Scale] on usb-0000:00:02.0-8/input0
Thanks!
Last edited by Got2BeFree on Saturday 24th December 2016 2:47am, edited 1 time in total.

User avatar
jornmo
Site Admin
Posts: 127
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Reading a hiddev stream

Post by jornmo » Monday 28th November 2016 10:00am

This is a hard question that would demand a bit of research on my part in order to answer :) Perhaps you must direct the question to the mailing list? If you find a solution, we will be happy to hear how you solved it :)

Have a great day!

User avatar
cogier
Site Admin
Posts: 115
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Reading a hiddev stream

Post by cogier » Monday 28th November 2016 12:56pm

I am interested in reading a USB port and have tried various ideas but I'd like to know which Distro you are using. Ialso need to sort out closing a process, see another post.

User avatar
cogier
Site Admin
Posts: 115
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Reading a hiddev stream

Post by cogier » Monday 28th November 2016 5:45pm

OK I have got a result. I have not been able to avoid the need for root permissions and as I don't have your scales so I experimented with a USB bar-code gun. I use Linux Mint which is based on the Ubuntu family so there may be other issues to deal with.

I have used 'gksu' to get root access. The output is full of all-sorts but I was able to get what I wanted. The bar-code I used is correctly displayed above the 'Convert' button.
ReadUSB.png
ReadUSB.png (12.89 KiB) Viewed 874 times
Hopefully you can pick something out of this: -
ReadUSB.tar
(34.5 KiB) Downloaded 22 times

User avatar
Got2BeFree
Posts: 15
Joined: Saturday 26th November 2016 2:52am

Re: Reading a hiddev stream

Post by Got2BeFree » Thursday 15th December 2016 5:16am

Sorry for the late reply, been side-tracked on other things for a few weeks and I've set this project aside for awhile.

I've tried your project, cogier, but without any success. I do know the stream coming from the scale is binary. I've found a couple python scripts for the scale that I'll try to get working (and/or try to convert over to Gambas). I know nothing about python so it's going to take awhile once I pick up my project again.

Thanks everyone for your help. I'll post again once I'm working on this again.
I'm wondering around lost in the future, not knowing where the present is, not knowing where the past disappeared to...

User avatar
Got2BeFree
Posts: 15
Joined: Saturday 26th November 2016 2:52am

Re: Reading a hiddev stream

Post by Got2BeFree » Friday 23rd December 2016 5:57am

I've picked this up again. I found a perl script tonight that got me pointed in the right direction. Now to get the scales working with Gambas...

I made 2 changes to cogier's code (marked as comment in the code):

Code: Select all

Public Sub Form_Open()

hProc = Exec ["sudo", "cat", "/dev/hidraw3"] For Read As "plugin" 
' used 'sudo'. changed to '/dev/hidraw3'

End
The above changes are for obvious reasons. ;)

Code: Select all

Public Sub plugin_read() 
Dim sTemp As String 

sTemp = Read #Last As Byte   ' changed '#Last, -255' to '#Last As Byte'
TextArea1.text &= sTemp 

End
This change allowed the binary stream to display correctly without any extra code:
341125536034112553603411255360341125536034112553603411255360341125536034112553603411255360341125536034112553603411255360341125536034112553603411255360341125536034112553603411255360341125536034112553603411255360341125536034112553603
The above is a 6-element array repeated constantly, but with different values depending the state of the scales (ie: weight, unit of weight [ounces/kilograms], if weight has stabilized, etc). So now that brings me to the actual bits needed...
3411255360
This can be broken down into the individual elements of the array...
3 4 11 255 36 0
My current goal is to get this stream into an array so I can easily read each element. Any advice/suggestions?
I'm wondering around lost in the future, not knowing where the present is, not knowing where the past disappeared to...

User avatar
Got2BeFree
Posts: 15
Joined: Saturday 26th November 2016 2:52am

Re: Reading a hiddev stream

Post by Got2BeFree » Friday 23rd December 2016 9:07am

Putting the stream into an array was much easier than I was expecting.

Since the scale has an auto-off after 3 minutes idle time, I need to test for a lack of stream so I can display a message. Is there a way to test for a stream?
I'm wondering around lost in the future, not knowing where the present is, not knowing where the past disappeared to...

User avatar
jornmo
Site Admin
Posts: 127
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Reading a hiddev stream

Post by jornmo » Friday 23rd December 2016 9:29am

This is more or less of a guess work from my side, but perhaps you can check the Stream.EndOfFile boolean value, and send the Stream.Close() signal to kill it. Then you could monitor the hidraw3 file for changes with the gb.inotify component?

User avatar
jornmo
Site Admin
Posts: 127
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Reading a hiddev stream

Post by jornmo » Friday 23rd December 2016 9:30am

And, when there are changes you re-create the stream.

User avatar
Got2BeFree
Posts: 15
Joined: Saturday 26th November 2016 2:52am

Re: Reading a hiddev stream

Post by Got2BeFree » Friday 23rd December 2016 9:42am

I discovered using a _kill() sub works a treat. I can put whatever is needed in there to alert the user the scales is off-line.

I have to put this project to the side for awhile again. Next go around I should have enough to work this into my inventory project.
I'm wondering around lost in the future, not knowing where the present is, not knowing where the past disappeared to...

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests