Search code examples
angularserial-portsmselectronucs2

How to convert input from user to UCS2 in angular 7 and Send Msg through Usb Gsm Modem)


I have an angular 7 app which get input (phone number and message) from user to send sms using electron serialport.

I want to encode phone number and message in UCS2. How can i convert it in angular 7.

I am not able to find any guide about converting to UCS2 I have tried https://maketips.net/tip/239/convert-to-ucs2-and-from-ucs2-in-javascript

But I am not able to include it properly as i am newbee.


Solution

  • I found a solution for this. I tried to used a library https://github.com/emilsedgh/modem

    and it worked well. So i didn't need to do anything (convert to ucs2) manually.

    let isElectron: boolean = window && window['process'] &&  window['process'].type;
    if(isElectron){
        modem.open("COM7",function(){
            console.log('modem opened');
            modem.sms({
                receiver:"00923325200***",
                text:"abc i am a msg",
                encoding:'16bit'
            }, function(err, sent_ids) {
                console.log('>>', arguments);
                if(err)
                    console.log('Error sending sms:', err);
                else
                    console.log('Message sent successfully, here are reference ids:', sent_ids.join(','));
                    modem.close();
            });
        });
    }