Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Serialport nodejs模块向客户杆显示器COM2发送命令_Javascript_Angular_Serial Port_Electron - Fatal编程技术网

Javascript 使用Serialport nodejs模块向客户杆显示器COM2发送命令

Javascript 使用Serialport nodejs模块向客户杆显示器COM2发送命令,javascript,angular,serial-port,electron,Javascript,Angular,Serial Port,Electron,我尝试向一个客户柱显示器发送一个清晰的屏幕命令,其型号为LCD210,波特率为9600,8,n,1(V.1),20个字符2行,命令类型为CD5220,字体为U.S.a/PC437。我有手册,但当我试图发送命令时。它没有把它捡起来,只是像绳子一样打印出来 下面是我的代码 onDisplayTextOnPole(msg: any) { //Check if we are in electron env if (this.isElectron()) { //Star

我尝试向一个客户柱显示器发送一个清晰的屏幕命令,其型号为LCD210,波特率为9600,8,n,1(V.1),20个字符2行,命令类型为CD5220,字体为U.S.a/PC437。我有手册,但当我试图发送命令时。它没有把它捡起来,只是像绳子一样打印出来

下面是我的代码

  onDisplayTextOnPole(msg: any) {

    //Check if we are in electron env
    if (this.isElectron()) {

      //Start
      const port =  new this.serialPort('COM2', { baudRate: 9600 }, function (err) {
        if (err) {
          return console.log('Error: ', err.message);
        }
      });



      port.write('\0x0C');//Command to clear screen
      port.write(Buffer.from(msg), function(err: { message: any; }) {
        if (err) {
          return console.log('Error on write: ', err.message)
        }
        console.log('message written')
      });
      port.close();
      //End 

    }


  }

实际上,我想先清除屏幕,然后写一条消息。我遇到的问题是,每当我发送一条新消息时,它都会附加到上一条消息。因此,在编写新消息之前,我需要一种方法来清除以前的消息。

我使用以下代码解决此问题:

this.myserialportinstance.write(Buffer.from('CLR', 'hex'));

我使用以下代码解决此问题:

this.myserialportinstance.write(Buffer.from('CLR', 'hex'));

你的问题解决了吗?如果是,请给我一个提示。你的问题解决了吗?如果是,请给我小费。