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

Cannot open connection with OPN-2001 scanner? #64

Open
alittle opened this issue Aug 2, 2016 · 9 comments
Open

Cannot open connection with OPN-2001 scanner? #64

alittle opened this issue Aug 2, 2016 · 9 comments

Comments

@alittle
Copy link

alittle commented Aug 2, 2016

Greetings, I've been testing a few cordova plugins for nfc and barcode-reading via device camera and was excited to see this plugin available as well. I'm hoping to pull scanned data from a tiny thumb-scanner using an HTC One running Android 6, an OTG cable and this plugin.

I've tried various combinations with VID/PID specified and the ProlificSerialDriver that it should be using but it appears consistently unable to connect hitting the first error callback with the message:

ControlTransfer with value 0x0 failed: -1

I believe everything is in place to specify the connection, rather than assuming the defaults, even though it should pretty much match those but have yet to successfully connect with the device. I'd certainly appreciate any pointers if there is something simple I'm missing.

The request looks something like:

            serial.requestPermission({
                    vid: '065A',
                    pid: '0009',
                    driver: 'ProlificSerialDriver'
                },
                function(successMessage) {
                    serial.open(
                        {baudeRate : 9600, dataBits: 8, parity: 0, stopBits: 0, "dtr":false},
                        function(successMessage) {
                            alert('Open Success! ', successMessage);
                            serial.writeHex('01 02 00 9f de',
                                function(successMessage) {
                                    alert('Write Success: ', successMessage);
                                },
                                errorCallback
                            );
                        },
                        errorCallback
                    );
                },
                errorCallback
            );
@xseignard
Copy link
Owner

Hello @alittle
I tried to find some documentation about your device, and couldn't find any reliable one.

Do you have some, so I can check what are the specifications of the underlying serial port?

Regards

Xavier

@alittle
Copy link
Author

alittle commented Aug 3, 2016

Hi @xseignard - thank you for offering to take a look. I'm working in large part from python project code for a scanner that uses the same protocol here, otherwise all example code for the device is provided in wrapper libraries in objective-c and .net:

https://github.com/fazalmajid/cs1504!
cs1504

It looks like some of this may be configurable though in the device itself by scanning particular barcode sequences, according to the details in this PDF manual, starting from page "U7"

http://www.opticonusa.com/pdf/Manuals/Universal_Menu_Book.pdf!
OPN-2001 Manual

So tomorrow I may try a few of those reset codes for different Parity or Stop Bits but so far I am able to open a connection with the OPN-2001 device using either the python script above or node-serialport code and my Windows 10 machine.

@xseignard
Copy link
Owner

xseignard commented Aug 3, 2016

According to this: https://github.com/fazalmajid/cs1504/blob/master/cs1504.py#L130-L135

It seems the serial port should be configured as 8-Odd-1, and from what I see, you configured it with:
dataBits: 8, parity: 0, stopBits: 0. It means 8 data bits, parity None and 0 stop bits.

Maybe you could try to configure the serial port with:
dataBits: 8, parity: 1, stopBits: 1 and since dataBits: 8 and stopBits: 1 are the default values (same apply for baudRate: 9600) you could shorten the opts, to end with:

serial.open(
  { parity: 1, dtr: false },
  (successMsg) => { /*...*/ },
  (errorMsg) => { /*...*/ }
);

Let me know if it solves your problem.

Regards

@xseignard
Copy link
Owner

But according to the manual (U7). It seems the bold options are the default ones, and then it would be:
a 8-N-1 serial port configuration.
8-N-1 are the defaults, then you'd end up with:

serial.open(
  { dtr: false },
  (successMsg) => { /*...*/ },
  (errorMsg) => { /*...*/ }
);

@xseignard
Copy link
Owner

Any updates?

@xseignard
Copy link
Owner

Cough, cough, cough :)

@alittle
Copy link
Author

alittle commented Aug 17, 2016

Thanks for checking back in with me. Unfortunately while it may have taken slightly longer for the error message to appear, after simplifying the port configuration it still resulted in the same error message as before. Slight changes to the configuration could cause the application to quit unexpectedly so it feels like I'm still on the right track. I think my next step is to figure out how to read the error/crash logs around the time when it's trying to make the serial connection and see if any potential culprits appear there. I'm trying to figure how to do adb-over-wifi connections to the phone so that I can have the OTG device connected at the same time as I am monitoring activity and will post any findings I glean from those tests back here.

@alittle
Copy link
Author

alittle commented Aug 17, 2016

After connecting to the device via wifi and watching the logs I'm seeing the following activity when attempting to connect to the scanner:

Serial  : Action: requestPermission
UsbBroadcastReceiver: Permission to connect to the device was accepted!
Serial  : Action: openSerial
Serial  : ControlTransfer with value 0x0 failed: -1
Serial  : Serial port opened!
CordovaPlugin: Attempted to send a second callback for ID: Serial983166383
CordovaPlugin: Result was: "Serial port opened!"
Serial  : Stopping io manager.
Serial  : Starting io manager.
SerialInputOutputManager: Running ..
SerialInputOutputManager: Run ending due to exception: Attempt to invoke virtual method 'int android.hardware.usb.UsbDeviceConnection.bulkTransfer(android.hardware.usb.UsbEndpoint, byte[], int, int)' on a null object reference
SerialInputOutputManager: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.hardware.usb.UsbDeviceConnection.bulkTransfer(android.hardware.usb.UsbEndpoint, byte[], int, int)' on a null object reference
SerialInputOutputManager:      at com.hoho.android.usbserial.driver.ProlificSerialDriver$ProlificSerialPort.read(ProlificSerialDriver.java:373)
SerialInputOutputManager:      at com.hoho.android.usbserial.util.SerialInputOutputManager.step(SerialInputOutputManager.java:159)
SerialInputOutputManager:      at com.hoho.android.usbserial.util.SerialInputOutputManager.run(SerialInputOutputManager.java:141)
SerialInputOutputManager:      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
SerialInputOutputManager:      at java.util.concurrent.FutureTask.run(FutureTask.java:237)
SerialInputOutputManager:      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
SerialInputOutputManager:      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
SerialInputOutputManager:      at java.lang.Thread.run(Thread.java:818)
Serial  : Runner stopped.
SerialInputOutputManager: Stopped.

I'm unsure with the "Serial port opened!" message how it hits the ControlTransfer issue and then fails so quickly but perhaps things don't bubble up in the logs in the same order or an initial handshake is successful but something soon after that but before the success callbacks are invoked fails. The success callback never appears to get called so I don't think I could be messing anything up yet by passing in funky .write data. Omitting the driver: 'ProlificSerialDriver' property was one way to make the app to crash immediately. I don't know if any of this is useful but certainly appreciate your willingness to assist with this so far @xseignard.

@xseignard
Copy link
Owner

Sorry for the (very) late reply...
Did you find a solution?
Regards

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

2 participants