Tool/software: Code Composer Studio
Hi,
I am developing an android application that uses USB technology with this device. The problem is that when I send a RESET message, no action is performed by the device. I follow the steps reflected in the documentation, but I am not able to take any response for it.
I stablish the connection and send the RESET packet to the endpoint 0 for see the reset in the device (I also prove the endpoint 1) but any response is obtained from it.
I send the packet in an UsbRequest.queue and i do a requestWait to send the petition, but I do not appreciate the correspondent behaviour.
The containing packet is: 0x00 (first byte at 0), 0x40 (indicate that wants a response (also prove 0x00, 0x80 and 0xC0)), 0x00 (sequence byte), 0x00 0x02 (also interchanged and in LSB and MSB), 0x1A 0x02 (also interchanged). All joined is 0x00 0x40 0x00, 0x00, 0x02 0x1A 0x02
The code that I am using for generate the UsbRequest is:
static { SPECTROMETER_NAME_DIRECTION = "/dev/bus/usb/001/003"; INPUT_ENDPOINT = 0; OUTPUT_ENDPOINT = 1; // Information READ_MODEL_NUMBER = new byte[]{0x3C}; READ_SERIAL_NUMBER = new byte[]{0x33}; READ_REVISIONS = new UsbPacket() .setGroupByte((byte) 0x02) .setCommandByte((byte) 0x16) .setFlagRW(UsbPacket.RW.READ) .setFlagReady(UsbPacket.READY.READY) .toByteArray(); // 4 bits each one TIVA SW (0 - 4) SPECTRUM Lib (16 - 20) // Reset device RESET_DEVICE = new UsbPacket() .setGroupByte((byte) 0x02) .setCommandByte((byte) 0x1A) .setFlagRW(UsbPacket.RW.WRITE) .setFlagReady(UsbPacket.READY.READY) .toByteArray(); } } class UsbPacket { private byte flags; private int sequence = 0; private byte commandByte; private byte groupByte; private byte[] data; enum RW { WRITE, READ } enum READY { BUSY, READY } enum ERROR { SUCCESS, ERROR, BUSY } UsbPacket setFlagRW(RW flag) { if (flag == RW.READ) { this.flags = (byte) (this.flags | 0x80); } return this; } UsbPacket setFlagReady(READY flag) { if (flag == READY.READY) { this.flags = (byte) (this.flags | 0x40); } return this; } UsbPacket setFlagError(ERROR flag) { if (flag == ERROR.ERROR) { this.flags = (byte) (this.flags | 0x20); } if (flag == ERROR.BUSY) { this.flags = (byte) (this.flags | 0x10); } return this; } UsbPacket setSequence(int sequence) { if (0 > sequence || sequence > 255) { throw new IllegalArgumentException("Only values from 0 to 255 are allowed"); } this.sequence = sequence; return this; } UsbPacket setCommandByte(byte commandByte) { this.commandByte = commandByte; return this; } UsbPacket setGroupByte(byte groupByte) { this.groupByte = groupByte; return this; } public UsbPacket setData(byte[] data) { this.data = data; return this; } byte[] toByteArray() { byte[] dataLength = new byte[2]; int lengthOfCommandBytes = 2; if (data != null) { dataLength = ByteBuffer.allocate(2).putInt(lengthOfCommandBytes + data.length).array(); } else { dataLength[0] = (byte) (lengthOfCommandBytes & 0xFF); dataLength[1] = (byte) ((byte) ((lengthOfCommandBytes >> 8)) & 0xFF); } byte[] header = new byte[] { 0x00, flags, (byte) sequence, dataLength[0], dataLength[1], commandByte, groupByte }; byte[] packet; if (data != null) { packet = new byte[7 + data.length]; System.arraycopy(header, 0, packet, 0, header.length); System.arraycopy(data, 0, packet, 7, data.length); } else { packet = header; } return packet; } }
and the code for send the request is:
@Override public void execute() { // Obtaining correspondent interface, endpoint and connection UsbInterface usbInterface = USBController.getInstance().getUsbInterface(); UsbDeviceConnection connection = USBController.getInstance().getUsbManager().openDevice(USBController.getInstance().getSpectrophotometer()); UsbEndpoint outputEndpoint = usbInterface.getEndpoint(1); // obtain interface connection.claimInterface(usbInterface, true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Log.i("USB", "reset device...."); /* int r; r = connection.bulkTransfer(outputEndpoint, CommandsUSB.RESET_DEVICE, CommandsUSB.RESET_DEVICE.length, 0); if (r > 0){ Log.i("USB", "reset performed " + r); }else{ Log.i("USB", "reset not performed " + r); } */ //connection.controlTransfer(0xA1, 0x01, 0x00, 0x01, CommandsUSB.RESET_DEVICE, CommandsUSB.RESET_DEVICE.length, 0); String s = ""; for(byte b : CommandsUSB.RESET_DEVICE){ s += b; } Log.i("USB", "command sent: " + s); UsbRequest request = new UsbRequest(); request.initialize(connection, outputEndpoint); request.queue(ByteBuffer.wrap(CommandsUSB.RESET_DEVICE)); UsbRequest r = connection.requestWait(); request.close(); Log.i("USB", "requested data"); Log.i("USB", "request: " + r.toString()); } // realease interface connection.releaseInterface(usbInterface); connection.close(); }
like you can see, I tried to make a bulk and a control transfer too but no one provoke the action that i want.
Any help would be appreciated!!
Regards,
Brais