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

serial.registerReadCallback With USB Modem via AT Commands #121

Open
Mamdouh-Freelancer opened this issue Aug 25, 2020 · 0 comments
Open

Comments

@Mamdouh-Freelancer
Copy link

Hello all authors,

I tried to connect USB modem to send AT Commands and the problem I'm facing that when I use serial.registerReadCallback after serial.open it's receiving unlimited of buffers (app crashed after few seconds) and all of zeros [0,0,0,0,0,0,0,0,0] witch nothing after decoded and I don't know what's wrong with that.

What/when is the right way to use serial.registerReadCallback and serial.read?
What's the right way to handle this unusual received buffers?

Note: AT Commands tested on PC and working well.

Simple AT Commands && also tried without \r\n
serial.write('AT+CMGF=0\r\n'); // set modem to PDU mode
serial.write('AT+COPS?\r\n'); // get Operator Name

Same as:

 serial.requestPermission(
            // if user grants permission
            function(successMessage) {
                // open serial port
                serial.open(
                    {baudRate: 9600},
                    // if port is succesfuly opened
                    function(successMessage) {
                        open = true;
                        // register the read callback
                        serial.registerReadCallback(
                            function success(data){
                                // decode the received message
                                var view = new Uint8Array(data);
                                if(view.length >= 1) {
                                    for(var i=0; i < view.length; i++) {
                                        // if we received a \n, the message is complete, display it
                                        if(view[i] == 13) {
                                            // check if the read rate correspond to the arduino serial print rate
                                            var now = new Date();
                                            delta.innerText = now - lastRead;
                                            lastRead = now;
                                            // display the message
                                            var value = parseInt(str);
                                            pot.innerText = value;
                                            str = '';
                                        }
                                        // if not, concatenate with the begening of the message
                                        else {
                                            var temp_str = String.fromCharCode(view[i]);
                                            var str_esc = escape(temp_str);
                                            str += unescape(str_esc);
                                        }
                                    }
                                }
                            },
                            // error attaching the callback
                            errorCallback
                        );
                    },
                    // error opening the port
                    errorCallback
                );
            },
            // user does not grant permission
            errorCallback
        );
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