Browse Source

更新控制文件
Signed-off-by: Caner <40012261+Canees@users.noreply.github.com>

Caner 3 years ago
parent
commit
6a9d841eb9
1 changed files with 10 additions and 15 deletions
  1. 10 15
      contrl.js

+ 10 - 15
contrl.js

@@ -11,31 +11,26 @@ class ContrlService {
         this.P2 = 0x42
         this.P2 = 0x42
         this.P3 = 0x43
         this.P3 = 0x43
         this.P4 = 0x44
         this.P4 = 0x44
+        this.run()
     }
     }
 
 
     async run() {
     async run() {
         // 数模初始值
         // 数模初始值
-        const data = this.Orientation()
-        process.send(data);
-        await sleep(0.03)
+        const data = await this.Orientation()
+        console.log(data)
+       // process.send(data);
+        await sleep(500)
         this.run()
         this.run()
     }
     }
 
 
     // 获取值
     // 获取值
     async Orientation() {
     async Orientation() {
-        this.BUS.write_byte(this.ADR, this.P1)
-        const v0 = this.BUS.read_byte(this.ADR)
-        await sleep(0.02)
-        this.BUS.write_byte(this.ADR, this.P2)
-        const v1 = this.BUS.read_byte(this.ADR)
-        await sleep(0.02)
-        this.BUS.write_byte(this.ADR, this.P3)
-        const v2 = this.BUS.read_byte(this.ADR)
-        await sleep(0.02)
-        this.BUS.write_byte(this.ADR, this.P4)
-        const v3 = this.BUS.read_byte(this.ADR)
+        const v0 = this.BUS.readByteSync(this.ADR,this.P1)
+        const v1 = this.BUS.readByteSync(this.ADR,this.P2)
+        const v2 = this.BUS.readByteSync(this.ADR,this.P3)
+        const v3 = this.BUS.readByteSync(this.ADR,this.P4)
         // 接入socket 发送数据
         // 接入socket 发送数据
-        db = `{"type":"conctrl","conctrl":{"v0":${v0},"v1":${v1},"v2":${v2},"v3":${v3}}}`
+        const db = `{"type":"conctrl","conctrl":{"v0":${v0},"v1":${v1},"v2":${v2},"v3":${v3}}}`
         return db
         return db
     }
     }