0

Considering the following for-each loop

        String S = "";
        byte[] sendingByte;
        List<Integer> lst = new ArrayList<Integer>();

        try {

            ReadHoldRegisters(lst, 1, 1, 10);
            for (int value : lst) {
                S = S + String.format("%02x ", value);
            }

            etWrite.setText(S);

        } finally {
            // send modbus rtu byte[] array to USB serial port
            }

Where ReadHoldRegisters generates a CRC16 ArrayList of Integer and that int in Java is a signed value

How can I allocate the int values inside the for-each loop into byte[] sendingByte array?

Machado
  • 14,105
  • 13
  • 56
  • 97
  • Java's `byte` is a signed 8-bit numeric type whose range is `-128` to `127` ([JLS 4.2.1](http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.1)). `233` is outside of this range and may cause communication problems on ModBus-RTU. – Machado Feb 06 '15 at 13:37
  • Probably this could help you http://stackoverflow.com/questions/842817/how-does-java-convert-int-into-byte – lifeisfoo Feb 06 '15 at 13:40
  • edit was made to clarify the question – Machado Feb 06 '15 at 15:46

0 Answers0