1

I am trying to make a serial communication with an android device but when I run the write command I get the following error : java.io.IOException: write failed EBADF (Bad file number)

 public void write(boolean isAscii, String cmd) {
    log(SerialPortManager.write, port, isAscii, new StringBuffer().append("write:").append(cmd));
    if (outputStream != null) {
        synchronized (outputStream) {
            byte[] bytes;
            try {
                if (isAscii) {
                    bytes = cmd.getBytes();
                } else {
                    bytes = TransformUtils.hexStringToBytes(cmd);
                }

                outputStream.write(bytes);

            } catch (Exception e) {
                log(SerialPortManager.write, port, isAscii, new StringBuffer().append("WriteFail:").append(e));
            }
        }
        log(SerialPortManager.write, port, isAscii, new StringBuffer().append("Succesfully written :").append(cmd));
    } else {
        log(SerialPortManager.write, port, isAscii, new StringBuffer().append("write failure:outputStream is null"));
    }
}

0 Answers0