Jump to content
Sign in to follow this  
john renfrew

Reading from DYMO scales

Recommended Posts

Recently bought some DYMO M10 scales and wanted to grab the weight from them.

Turns out this is not as easy as you think talking to USB, but after a lot of crashing out and frustration I managed to get a proof of concept working, so here to share...

You will need hid4java and jna, best grabbing them from Maven

 

// ReadDYMO
// 17_02_28 JR
// v1.0
// read weight from Dymo M10 scales
//requires hid4java.jar and jna.jar

import org.hid4java.*
import org.hid4java.jna.*

import java.nio.ByteBuffer

// specifc to these scales
Short VENDOR_ID = 0x0922
Short PRODUCT_ID = 0x8003

Short raw_weight = 0
DATA_MODE_OUNCES = 11

message = new byte[8]

hidServices = HidManager.getHidServices()
devices = hidServices.getAttachedHidDevices()

dymo = hidServices.getHidDevice(VENDOR_ID, PRODUCT_ID, null)

if (dymo){
	val = dymo.read(message, 1000)
	dymo.close()
} //end if

hidServices.shutdown()

if (dymo){ 
	byte[] data = [ message[5], message[4] ]
	wrapped = ByteBuffer.wrap(data)
	raw_weight = wrapped.getShort()
	if ( message[2] == DATA_MODE_OUNCES ) { 
		scale = 10.power(message[3].toString().toShort())
		weight = (raw_weight * scale) + ' oz'
		oz = true
 	} else { 
		weight = raw_weight + ' g'
		oz = false	
	} //end if
	return weight
} else {
	return '0'
} //end if

 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.