找不到文件异常(没有这样的目录)

时间:2018-01-30 11:05:15

标签: java android i2c eeprom

我正在尝试从android中的用户空间写入eeprom(at24)。 我得到了exception

com.ipil.ipilMdm.service.lib I/System.out: java.io.FileNotFoundException: /sys/devices/soc.0/78ba000.i2c/i2c-6/6-0050/eeprom (No such file or directory)

提到的路径在命令行中从 echo cat 完美运行。它还在基于linux的应用程序中进行了测试,它作为读写文件打开。

我在清单文件中添加了权限。还有什么问题可以解决?

以下是我的代码:

@Override
public void prod_eeprom_write(String data, int id) {


String someText = "Writesomething";

 //String fileName = Environment.getRootDirectory().getAbsolutePath();
    final File permFile = new File("/sys/devices/soc.0/78ba000.i2c/i2c-6/6-0050/eeprom");

    try {

    /*  if (file == null) {
            System.out.print("error open\n");
            return;
        }*/

        //=================== Condition for action==========================

        switch (id) {

            case IMEI_NUMBER:
                offset = IMEI_NUMBER_OFFSET;
                length = IMEI_NUMBER_LENGTH;
                break;
            case HARDWARE_REVISION:
                offset = HW_REV_OFFSET;
                length = HW_REV_LENGTH;
                break;
            case WIFI_MAC_ADDRESS:
                offset = WIFI_MAC_OFFSET;
                length = WIFI_MAC_LENGTH;
                break;
            case BT_MAC_ADDRESS:
                offset = BT_MAC_OFFSET;
                length = BT_MAC_LENGTH;
                break;
            default : return;
        }


        /* now got offset and length, so update max buffer */
        //strncpy(data,max_data.length + offset, length);
        if (data.length() < length)
            length = data.length();

        if(data.length() > length){
            System.out.print("LENGTH OF DATA IS TOO BIG : CAN NOT WRITE\nMAX LENGTH IS %d BYTES\n"+ length);
            return;
        }

            //strncpy(data, max_data.length + offset, data.length());
        max_data[INFO_MAX_LENGTH] = '\0';
        System.out.println("DATA TO BE WRITTEN TO EEPROM: "+ data);

        //if(file.canWrite()){
            fileOutputStream = new FileOutputStream(permFile);

            byte[] b = data.getBytes(); //new byte[max_data.length];
                //for (int i = 0; i < b.length; i++)
                //      b[i] = (byte) max_data[i];


                    fileOutputStream.write(b, max_data.length + offset, data.length());
                    Log.i(TAG, " prod_eeprom_written-----------ok : hogya ");

                    Thread.sleep(10);
                    fileOutputStream.close();
                    System.out.println("success...");

    }catch (Exception io){
        io.printStackTrace();
    }

    }

0 个答案:

没有答案