Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

just read a part of message of file name from SD Card on 3D printer #20

Open
drinkingcode opened this issue Mar 2, 2016 · 1 comment

Comments

@drinkingcode
Copy link

when the count of files from SD Card on 3D printer is few, i can get all the correct file name of SD Card, but when the count of files from SD Card is many, i just get a part of file name , do you meet the same problem ? if you know that, please tell me

@drinkingcode
Copy link
Author

the bug is here:

private Runnable mLoop = new Runnable() {
    @Override
    public void run() {
        int len=0;
        byte[] rbuf = new byte[USB_READ_BUFFER_SIZE];
        for (;;) {// this is the main loop for transferring

            try {
                len = mConnection.bulkTransfer(mEndpointIn,
                        rbuf, rbuf.length, 50);
            } catch(Exception e) {
                Log.e(TAG, e.toString());
            }

            if (len > 0) {
                mBuffer.add(rbuf, len);
                for(int i=0; i<len; i++){
                    Log.v("rbuf",""+((char)rbuf[i]));
                }
                onRead(len);
            }

            if (mReadThreadStop) {
                return;
            }

                              //当数据量大时,有时mEndpointIn的最大缓存已满,而此时在sleep中,所以
            try {                  //就会覆盖一部分数据,所以这里的这个延迟需要去掉;
                Thread.sleep(50);
            } catch (InterruptedException e) {
            }


        }
    } // end of run()
}; // end of runnable

it should be modifid as following :

private Runnable mLoop = new Runnable() {
    @Override
    public void run() {
        int len=0;
        byte[] rbuf = new byte[USB_READ_BUFFER_SIZE];
        for (;;) {// this is the main loop for transferring

            try {
                len = mConnection.bulkTransfer(mEndpointIn,
                        rbuf, rbuf.length, 50);
            } catch(Exception e) {
                Log.e(TAG, e.toString());
            }

            if (len > 0) {
                mBuffer.add(rbuf, len);
                for(int i=0; i<len; i++){
                    Log.v("rbuf",""+((char)rbuf[i]));
                }
                onRead(len);
            }

            if (mReadThreadStop) {
                return;
            }

            /*                    //当数据量大时,有时mEndpointIn的最大缓存已满,而此时在sleep中,所以
            try {                  //就会覆盖一部分数据,所以这里的这个延迟需要去掉;
                Thread.sleep(50);
            } catch (InterruptedException e) {
            }
            */


        }
    } // end of run()
}; // end of runnable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant