I’m working with some devices that do not have a driver in android. The device I am trying to interface with is a scanner scale in USB-OEM mode (specifically a Datalogic 9800).
The device is a dual usb device that has 2 separate endpoints. One that I can send an empty bulk transfer and then listen to possible data incoming, this is the scanner endpoint and it is working. The other endpoint is the scale, I am sending the English Weight Request Command: 01h, 00h, 00h, 00h, 00h and expect a response of the weight on this scale. This is not working and I am getting a response of -1
Here is the working code where I am able to receive data from the scanner endpoint:
device?.getInterface(0)?.also { intf ->
intf.getEndpoint(0)?.also { endpoint ->
println(endpoint.direction)
manager.openDevice(device)?.apply {
claimInterface(intf, forceClaim)
coroutineScope.launch {
// Loop and check if any data is incoming.
val buffer = ByteArray(endpoint.maxPacketSize)
while (true) {
val bytesRead = bulkTransfer(endpoint, buffer, buffer.size, TIMEOUT)
if (bytesRead > 0) {
val bufferString = buffer.joinToString(separator = " ")
val receivedData = bufferString.split(" ").subList(3, 16).joinToString("")
println(receivedData)
val ret = JSObject()
ret.put("upc", receivedData)
call.resolve(ret)
}
}
}
}
}
}
The above method listens for data and works as expected. The following code is to send data but does not receive data, it is working as expected with another USB device (a receipt printer):
device?.getInterface(0)?.also { intf ->
intf.getEndpoint(0)?.also { endpoint ->
manager.openDevice(device)?.apply {
claimInterface(intf, forceClaim)
bulkTransfer(endpoint, bytes, bytes.size, TIMEOUT)
}
}
}
This also works correctly. However I need to both make a command and I expect data to be returned. Here is the command I need to make: 0x01
, 0x00
, 0x00
, 0x00
, 0x00
and I expect to get a response like: 00000x00b
, 0xxxxx00b
, <00xxxxx0b, xxh, xxh, xxh, xxh >
However I never receive any bytes back after my request.
Here is the code I am attempting to use:
device?.getInterface(1)?.also { intf ->
intf.getEndpoint(0)?.also { endpoint ->
println(intf)
manager.openDevice(device)?.apply {
claimInterface(intf, forceClaim)
coroutineScope.launch {
val buffer = byteArrayOf(0x01, 0x00, 0x00, 0x00, 0x00)
val bytesSent = bulkTransfer(endpoint, buffer, buffer.size, TIMEOUT)
// Loop and check if any data is incoming.
while (true) {
val bytesRead = bulkTransfer(endpoint, buffer, buffer.size, TIMEOUT)
println(bytesRead)
}
}
}
}
}
I always get a return of -1
. What am I doing wrong here, how can I send a simple command and get a response?