xseignard / cordovarduino

Cordova/Phonegap plugin for USB host serial communication from an Android device.
MIT License
166 stars 110 forks source link

Unable to open serial connection #84

Closed salvisb closed 6 years ago

salvisb commented 7 years ago

Hi, I'm trying to connect Datalogic GD4400 scanner with my Android (version 6.0) tablet. I was able to get pass requestPermission step, but at this point, can't open connection.

Tried using scanner default configuration with cordovarduino defaults (which should be equal), but with no luck.

Not really sure which scanner interface to use:

`serial.requestPermission({ vid: '05F9', pid: '4204', driver: 'ProlificSerialDriver' }, function success() { serial.open( {dtr: false}, function success() { alert("Success"); }, function error(evt) { alert("Error: Unable to open serial connection! "); }); },

function error(evt) { alert("Error: " + evt); });`

Any help would be highly appreciated.

xseignard commented 7 years ago

It is very hard for me to debug without the hardware. Please give me more inputs about the serial connexion your scanner provides.

sureshkumar-s89 commented 6 years ago

Hi xseignard,

I'm beginner to cordova, I have to read/write data from weighing scale which have rs232 (9 pole) port. I'll connect the device to my mobile using rs232-USB and USB OTG cable. I used the same above code with only VID and PID.

But I could not able to open the port and it gives no error. The serial settings given in device User's manual is: 8-bit ASCII code; 8 data bits; 1 stop bit; no parity bit; baud rate 9600.

Can you please help me to find out what am I missing?

xseignard commented 6 years ago

Hello,

Could you please show me your code?

Also, could you please check you can see data being sent to a computer through the arduino serial monitor (http://www.instructables.com/id/HOW-TO-use-the-ARDUINO-SERIAL-MONITOR/)

Regards

sureshkumar-s89 commented 6 years ago

Hi, please find the code which I used

function serialDataRead() {
    alert('Start');
    var errorCallback = function(message) {
        alert('Error: ' + message);
    };
    serial.requestPermission({vid: '1a86', pid: '7523'},
        function success(successMessage) {
            alert(successMessage);
            alert('Before Open');
        serial.open(
            {baudRate: 9600},
            function success(successMessage) {
                alert('Port opened');
                serial.read(
                    function success(successMessage) {
                        alert(successMessage);
                    },
                errorCallback);
            },
            errorCallback);
        },
        errorCallback);
}

I didn't use arduino serial monitor, but I can see data being sent to the computer using putty serial connection.

I get the alert message upto 'Before Open', then app quits itself.

sureshkumar-s89 commented 6 years ago

Hi, I changed the code as below and now I get this (Error: init failed!) errorCallback message.

...
serial.requestPermission({vid: '1a86', pid: '7523', driver: 'Ch34xSerialDriver'},
...
{baudRate: 9600, dataBits: 8, stopBits: 1, parity: 0},
...
xseignard commented 6 years ago

Do you have a link to your rs232/usb adapter? and to the scale?

sureshkumar-s89 commented 6 years ago

Sorry I don't have a link to my rs232/usb adapter, here is the link to the scale.

sureshkumar-s89 commented 6 years ago

I get below information when I connect the device with Ubuntu (lsusb):

ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter

And found this link.

xseignard commented 6 years ago

Could you try the following ?

serial.requestPermission({vid: '1a86', pid: '7523', driver: 'ProlificSerialDriver'}

sureshkumar-s89 commented 6 years ago

I tried with above driver change, and now it shows this error message: Error: ControlTransfer with value 0x0 failed: -1

xseignard commented 6 years ago

Are you sure about the conf here? {baudRate: 9600, dataBits: 8, stopBits: 1, parity: 0}

It can be the conf of the scale, but is the adapter is configured the same?

sureshkumar-s89 commented 6 years ago

I'm not sure about the conf of adapter, is it possible to configure the adapter with same conf?

xseignard commented 6 years ago

unfortunately I'm not sure, when your run putty serial monitor, do you see the data decoded right?

how are your serial settings on putty?

sureshkumar-s89 commented 6 years ago

When I run putty, I can see the data decoded correctly and putty serial settings is same as above (baudRate: 9600, Data bits: 8, Stop bits: 1, Parity: 0)

xseignard commented 6 years ago

My guess is that the driver of the usb chip (presumably CH340/CH341) on your rs232/usb cable is not working.

That's weird because I commited the following https://github.com/mik3y/usb-serial-for-android/blob/master/usbSerialForAndroid/src/main/java/com/hoho/android/usbserial/driver/Ch34xSerialDriver.java

And tested it with some arduino clones that have a CH340 usb chip and it was working.

Could you please take a picture of the electronics of your cable so I can check what is the chip you have in it?

Maybe you could also try to find a rs232/USB cable with a more reliable usb chip? such as PL2303 This one https://www.amazon.com/UGREEN-Adaptateur-Compatible-Windows-Sup%C3%A9rieur/dp/B00QUZY4WO/ref=pd_sim_147_3?_encoding=UTF8&psc=1&refRID=4R5A9YG2809PCFQKGYZQ

Regards

xseignard commented 6 years ago

PS: I would really love to see this working because RS232 to android through this plugin is a recurrent question.

Unfortunately, I don't have any matching hardware to test it.

Regards

sureshkumar-s89 commented 6 years ago

My guess is that the driver of the usb chip (presumably CH340/CH341) on your rs232/usb cable is not working.

You maybe right.

Maybe you could also try to find a rs232/USB cable with a more reliable usb chip? such as PL2303 This one https://www.amazon.com/UGREEN-Adaptateur-Compatible-Windows-Sup%C3%A9rieur/dp/B00QUZY4WO/ref=pd_sim_147_3?_encoding=UTF8&psc=1&refRID=4R5A9YG2809PCFQKGYZQ

I will buy and try with a reliable usb chip cable like you referred.

Thank you so much for the support and quick responses, and I hope it should work.

sureshkumar-s89 commented 6 years ago

Hi @xseignard

I'm happy to share you that after using rs232/USB adapter with reliable usb chip, I'm able to read data from weighing scale, will continue with write process as well.

Thank you so much for the quick responses and for giving right instructions to achieve my requirement, also for the helpful plugin.

xseignard commented 6 years ago

That's great news @sureshkumar-s89 !

Would you mind post a link to the adapter you used? For other people to know what adapter is working?

Regards

sureshkumar-s89 commented 6 years ago

Hi @xseignard

Sorry for the delayed response, unfortunately I don't have the link for adapter, it was an old one bought from near by retailer.

xseignard commented 6 years ago

Could you at least take some pictures? And if possible write down the references that you can read on the chips of the cable?

Regards

sureshkumar-s89 commented 6 years ago

It looks exactly same like this https://www.amazon.in/PruthvikTMUSB-Serial-Adapter-Desktop-Through/dp/B074W2CYCZ/ref=sr_1_8?ie=UTF8&qid=1513331616&sr=8-8&keywords=rs232+usb. Sorry I do not know how to read references on the chips.

xseignard commented 6 years ago

Thanks! I close the issue. Feel free to reopen it.

Have fun!