Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java IOIO UART回读问题_Java_Android_Multithreading_Uart_Ioio - Fatal编程技术网

Java IOIO UART回读问题

Java IOIO UART回读问题,java,android,multithreading,uart,ioio,Java,Android,Multithreading,Uart,Ioio,我正在扩展BaseIOIOLooper以打开UART设备并发送消息。我正在用回读进行测试,我在一行上发送一个数据包,在另一行上接收该数据包并打印出来。因为我不想让InputStream.read()方法阻塞,所以我在另一个线程中处理数据包的形成和输入。我已经将问题缩小到InputStream.read()方法,该方法返回-1(没有读取字节,但没有异常)。 下面是它在活套线程中的外观: @Override protected void setup() throws Conn

我正在扩展BaseIOIOLooper以打开UART设备并发送消息。我正在用回读进行测试,我在一行上发送一个数据包,在另一行上接收该数据包并打印出来。因为我不想让InputStream.read()方法阻塞,所以我在另一个线程中处理数据包的形成和输入。我已经将问题缩小到InputStream.read()方法,该方法返回-1(没有读取字节,但没有异常)。 下面是它在活套线程中的外观:

        @Override
    protected void setup() throws ConnectionLostException, InterruptedException {
        log_.write_log_line(log_header_ + "Beginning IOIO setup.");
        // Initialize IOIO UART pins
        // Input at pin 1, output at pin 2
        try {
            inQueue_ = MinMaxPriorityQueue.orderedBy(new ComparePackets())
                    .maximumSize(QUEUESIZE).create();
            outQueue_ = MinMaxPriorityQueue.orderedBy(new ComparePackets())
                    .maximumSize(QUEUESIZE).create();
            ioio_.waitForConnect();
            uart_ = ioio_.openUart(1, 2, 38400, Uart.Parity.NONE, Uart.StopBits.ONE);
            // Start InputHandler. Takes packets from ELKA on inQueue_
            in_= new InputHandler(inQueue_, uart_.getInputStream());
            in_.start();
            // Start OutputHandler. Takes packets from subprocesses on outQueue_
            out_= new OutputHandler(outQueue_);
            out_.start();
            // Get output stream
            os_=uart_.getOutputStream();
            // Set default target state
            setTargetState(State.TRANSFERRING);
            currInPacket_[0]=1; //Initial value to start transferring
            log_.write_log_line(log_header_ + "IOIO setup complete.\n\t" +
                    "Input pin set to 1\n\tOutput pin set to 2\n\tBaud rate set to 38400\n\t" +
                    "Parity set to even\n\tStop bits set to 1");
        } catch (IncompatibilityException e) {
            log_.write_log_line(log_header_+e.toString());
        } catch (ConnectionLostException e) {
            log_.write_log_line(log_header_+e.toString());
        } catch (Exception e) {
            log_.write_log_line(log_header_+"mystery exception: "+e.toString());
        }
    }
    @Override
public void run() {
    boolean notRead;
    byte i;
    log_.write_log_line(log_header_+"Beginning InputHandler thread");
    while (!stop) {
        i = 0;
        notRead = true;
        nextInPacket = new byte[BUFFERSIZE];
        readBytes = -1;
        //StringBuilder s=new StringBuilder();
        //TODO re-implement this with signals
        while (i < READATTEMPTS && notRead) {
            try {
                // Make sure to adjust packet size. Done manually here for speed.
                readBytes = is_.read(nextInPacket, 0, BUFFERSIZE);
                /* Debugging
                for (int j=0;j<nextInPacket.length;j++)
                    s.append(Byte.toString(nextInPacket[j]));
                log_.write_log_line(log_header_+s.toString());
                */

                if (readBytes != -1) {
                    notRead = false;
                    nextInPacket= new byte[]{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0};
                    synchronized (q_) {
                        q_.add(nextInPacket);
                    }
                //log_.write_log_line(log_header_ + "Incoming packet contains valid data.");
                } else i++;
            } catch (IOException e) {
                log_.write_log_line(log_header_ + "mystery exception:\n\t" + e.toString());
            }
        }

        if (i>=READATTEMPTS)
            log_.write_log_line(log_header_+"Too many read attempts from input stream.");

        /*
        try {
            sleep(100);
        } catch (InterruptedException e) {
            log_.write_log_line(log_header_+"fuck");
        }
        */
    }
}
在InPuthHandler线程中:

        @Override
    protected void setup() throws ConnectionLostException, InterruptedException {
        log_.write_log_line(log_header_ + "Beginning IOIO setup.");
        // Initialize IOIO UART pins
        // Input at pin 1, output at pin 2
        try {
            inQueue_ = MinMaxPriorityQueue.orderedBy(new ComparePackets())
                    .maximumSize(QUEUESIZE).create();
            outQueue_ = MinMaxPriorityQueue.orderedBy(new ComparePackets())
                    .maximumSize(QUEUESIZE).create();
            ioio_.waitForConnect();
            uart_ = ioio_.openUart(1, 2, 38400, Uart.Parity.NONE, Uart.StopBits.ONE);
            // Start InputHandler. Takes packets from ELKA on inQueue_
            in_= new InputHandler(inQueue_, uart_.getInputStream());
            in_.start();
            // Start OutputHandler. Takes packets from subprocesses on outQueue_
            out_= new OutputHandler(outQueue_);
            out_.start();
            // Get output stream
            os_=uart_.getOutputStream();
            // Set default target state
            setTargetState(State.TRANSFERRING);
            currInPacket_[0]=1; //Initial value to start transferring
            log_.write_log_line(log_header_ + "IOIO setup complete.\n\t" +
                    "Input pin set to 1\n\tOutput pin set to 2\n\tBaud rate set to 38400\n\t" +
                    "Parity set to even\n\tStop bits set to 1");
        } catch (IncompatibilityException e) {
            log_.write_log_line(log_header_+e.toString());
        } catch (ConnectionLostException e) {
            log_.write_log_line(log_header_+e.toString());
        } catch (Exception e) {
            log_.write_log_line(log_header_+"mystery exception: "+e.toString());
        }
    }
    @Override
public void run() {
    boolean notRead;
    byte i;
    log_.write_log_line(log_header_+"Beginning InputHandler thread");
    while (!stop) {
        i = 0;
        notRead = true;
        nextInPacket = new byte[BUFFERSIZE];
        readBytes = -1;
        //StringBuilder s=new StringBuilder();
        //TODO re-implement this with signals
        while (i < READATTEMPTS && notRead) {
            try {
                // Make sure to adjust packet size. Done manually here for speed.
                readBytes = is_.read(nextInPacket, 0, BUFFERSIZE);
                /* Debugging
                for (int j=0;j<nextInPacket.length;j++)
                    s.append(Byte.toString(nextInPacket[j]));
                log_.write_log_line(log_header_+s.toString());
                */

                if (readBytes != -1) {
                    notRead = false;
                    nextInPacket= new byte[]{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0};
                    synchronized (q_) {
                        q_.add(nextInPacket);
                    }
                //log_.write_log_line(log_header_ + "Incoming packet contains valid data.");
                } else i++;
            } catch (IOException e) {
                log_.write_log_line(log_header_ + "mystery exception:\n\t" + e.toString());
            }
        }

        if (i>=READATTEMPTS)
            log_.write_log_line(log_header_+"Too many read attempts from input stream.");

        /*
        try {
            sleep(100);
        } catch (InterruptedException e) {
            log_.write_log_line(log_header_+"fuck");
        }
        */
    }
}
@覆盖
公开募捐{
布尔notRead;
字节i;
日志。写入日志行(日志头?+“从权限管理器线程开始”);
当(!停止){
i=0;
notRead=true;
nextInPacket=新字节[BUFFERSIZE];
readBytes=-1;
//StringBuilder s=新的StringBuilder();
//TODO使用信号重新执行此操作
而(i

在示波器上,针脚1和针脚2都读取振荡电压,尽管振幅非常高,这是一个值得关注的问题。关键是在InputHandler类中,从InputStream中读取不到任何内容。有什么想法吗?

-1从
read()返回
只应在UART关闭时发生。关闭可能是在
UART
对象上显式调用
close()
或在
IOIO
对象上调用
softReset()
的结果

Android日志可能会给你一些关于发生了什么的线索


您在示波器上看到的读数是可疑的:“甚高振幅”有多高?您应该只在这些引脚上看到0V或3.3V,或者在引脚由于某种原因未打开(或关闭)的情况下看到浮动。

-1从
read()返回
只应在UART关闭时发生。关闭可能是在
UART
对象上显式调用
close()
或在
IOIO
对象上调用
softReset()
的结果

Android日志可能会给你一些关于发生了什么的线索

您在示波器上看到的读数是可疑的:“甚高振幅”有多高?您应该只在这些引脚上看到0V或3.3V,或者在引脚因某种原因未打开(或关闭)的情况下看到浮动