<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ### 獲取串口 ` window.getComList(e=>{console.log(e)}) ` ![](https://img.kancloud.cn/f0/2f/f02fdfb8d03e428abfae254c1dd55cec_277x107.png) * 成功`code`為0 ### 監聽串口數據【對應調用參數位】 raw\_data?非必填?寫入的數據#16進制字符串?寫入模式下必填 com?必填?串口號?例如COM2 baudrate?必填?波特率例如9600 timeout?非必填?超時時間默認0.1 bytesize?必填?字節大小?例如8 stopbites?必填?停止位?例如1 ReadWriteMode?必填?讀寫模式【只讀模式?r、讀寫模式(單次寫入)rw、讀寫模式(持續寫入根據超時時間)rw+】 ResultMode?必填?結果獲取模式【單次獲取o、持續獲取o+】 EvnetName?非必填?事件名稱?未定義時間自動使用\[EventSerialWeight\]事件名?與?匿名回調函數共存 ResultType?必填?結果類型【ASCII(默認)?Hex】 **readBytesSize?必填?讀取字節大小 建議-1 可自動按行分割讀取\n結束符 如果指定了字節大小需要自行處理數據分割問題** callback?非必填?回調函數 * 如果為空的參數使用null占位即可 * 注意事項 如果已打開comx口 在此執行的時候會復用打開的句柄 如果是多個命令會有多個返回可能要自己判斷返回數據是否是自己需要的 * 如果是復用串口時 注意自定義回調事件名不要重復 不然讀取可能存在異常數據 ### 注意對獲取結果為空字符串導致NaN計算問題的處理 * 監聽重量僅能調用一次 要么使用單次獲取重量 要么全局監聽一個重量 不得一起使用 建議使用**全局一次監聽重量 通過掛載共享重量數據 例如vuex** * 對于去皮置零等非監聽重量命令執行時需要保證一個命令一個事件名 ### 某電子秤調用示例如下 * 獲取重量命令 `\x02\x41\x4e\x03` * 置零命令 `\x02\x41\x5a\x03` * 去皮命令 `\x02\x41\x54\x03` ``` window.onSerialWeight( '\x02\x41\x4e\x03', //表示讀取重量命令 'COM2', 9600, 0.1, 8, 1, 'rw+', 'o+', 'EventSerialWeight', 'ASCII', 26, e=>{ //對某電子秤返回結果解析 if(e.code === 0){ //截取4-10的字符串 let mystr = e.data.slice(3,10) //對字符串左右顛倒 mystr = mystr.split('').reverse().join(''); //轉為數字類型浮點數 weight = Number(mystr) console.log(weight ,'KG') } } ) ``` ### 事件方式 ``` window.onSerialWeight( '\x02\x41\x4e\x03', //表示讀取重量命令 'COM2', 9600, 0.1, 8, 1, 'rw+', 'o+', 'EventSerialWeight', 'ASCII', 26, null ) addEvent('EventSerialWeight',function(e){ if(e.code === 0){ //截取4-10的字符串 let mystr = e.data.slice(3,10) //對字符串左右顛倒 mystr = mystr.split('').reverse().join(''); //轉為數字類型浮點數 weight = Number(mystr) console.log(weight ,'KG') } }) ``` ![](https://img.kancloud.cn/ba/61/ba6197d18dc428530ca291b68ed47df9_422x340.png) ![](https://img.kancloud.cn/f3/b8/f3b8f8fddfcc19d8eb0d89cfbb78e2a8_223x301.png) ### 其他示例(“健坤”電子秤示例) * 無命令 持續獲取重量 ``` window.onSerialWeight( null, 'COM3', 9600, 5, 8, 1, 'r', 'o+', 'EventSerialWeight', 'ASCII', 17, e=>{ console.log(e) } ) ``` * 去皮 ``` window.onSerialWeight( "\x02\x54\x03", 'COM3', 9600, 5, 8, 1, 'rw', 'o', 'EventSerialWeight_qupi', 'ASCII', 17, null ) ``` * 置零 ``` window.onSerialWeight( "\x02\x5A\x03", 'COM3', 9600, 5, 8, 1, 'rw', 'o', 'EventSerialWeight_zhiling', 'ASCII', 17, null ) ``` ## 對以上電子秤重量結果處理方式演示 ``` window.onSerialWeight( null, 'COM3', 9600, 5, 8, 1, 'r', 'o+', 'EventSerialWeight', 'ASCII', -1, e=>{ //對于NaN問題 請注意上面的問題 避免因為監聽等導致NaN發生 監聽重量保持一次 對電子秤操作事件不要重復即可 weight = parseFloat(e.data) if(!isNaN(weight)){ console.log(weight) } } ) ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看