February 28, 20178 yr 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
Create an account or sign in to comment