clll
2023-09-06 190cc52625bea627b6266f0124bd0d638f03394c
更新代码
10个文件已修改
9个文件已添加
963 ■■■■ 已修改文件
CanadaMes-ui/src/api/alarm.js 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CanadaMes-ui/src/views/Electrical/Action.vue 87 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CanadaMes-ui/src/views/Electrical/Parameter.vue 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CanadaMes-ui/src/views/Electrical/Sign.vue 147 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CanadaMes-ui/src/views/Electrical/State.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
CanadaMes-ui/src/views/Electrical/alarm.vue 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/AuthorityApplication.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java 41 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/component/PlcParameter.java 75 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/component/Plcaction.java 32 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java 148 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/component/Plcsign.java 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/component/Plcstate.java 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/config/AppRunnerConfig.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/controller/AlarmController.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/entity/alarmmg.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/mapper/AlarmMapper.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/service/AlarmService.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CanadaMes-ui/src/api/alarm.js
New file
@@ -0,0 +1,22 @@
import request from "../utils/request";
/**
 *登录
 * @param data
 * @returns {AxiosPromise}
 */
export function home (data) {
  return request({
    url: '/home/load',
    method: 'get',
    data
  })
}
export function setAll (data) {
  return request({
    url: '/alarm/load',
    method: 'get',
    data
  })
}
CanadaMes-ui/src/views/Electrical/Action.vue
@@ -12,10 +12,14 @@
    </el-breadcrumb>
    <div>Action</div>
    <el-form label-width="100px" style="display: flex;flex-wrap: wrap;" :model="{ messagepack }">
      <div class="kuai_div" v-for="item in this.record.xyData" :key="item.name">
      <!-- <div class="kuai_div" v-for="item in record.xyData" :key="item.value">
        <el-input v-model="item.name" style="width: 240px;" class="in_mc"></el-input>
        <!-- <el-input v-model="item[0]" style="width: 80px;"></el-input> -->
        <el-switch v-model="item.value" active-value="0" inactive-value="1"></el-switch>
      </div> -->
      <div class="kuai_div" v-for="(item, index) in record.xyData" :key="index">
        <el-input v-model="item.name" style="width: 240px;" class="in_mc"></el-input>
        <el-switch v-model="item.value" active-value="1" inactive-value="0" @change="send()"></el-switch>
      </div>
    </el-form>
@@ -31,7 +35,7 @@
  data () {
    return {
      record: {
        params: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        params: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        canshu: [
          'D01 VFD conveyor',
          'D02 VFD conveyor',
@@ -61,13 +65,34 @@
          'B02 YV UP DOWN',
        ],
        xyData: [
          { name: 'D01 VFD conveyor', value: 0 },
          { name: "D02 VFD conveyor", value: 0 },
          { name: "D03 VFD conveyor", value: 0 },
          { name: "D04 VFD conveyor", value: 0 },
          { name: "B01 B02 TRAVEL JOG Velocity", value: 0 },
          { name: "conveyor Velocity(Manual)", value: 0 },
        ],
          { name: 'D01 VFD conveyor', value: "0" },
          { name: 'D02 VFD conveyor', value: "0" },
          { name: 'D03 VFD conveyor', value: "1" },
          { name: 'D04 VFD conveyor', value: "0" },
          { name: 'D05 VFD conveyor', value: "0" },
          { name: 'D06 VFD conveyor', value: "0" },
          { name: 'A01 VFD conveyor', value: "0" },
          { name: 'A02 VFD conveyor', value: "0" },
          { name: 'B01 VFD conveyor', value: "0" },
          { name: 'B02 VFD conveyor', value: "0" },
          { name: 'A01 SERVE TURN JOG+', value: "0" },
          { name: 'A02 SERVE TURN JOG-', value: "0" },
          { name: 'A01 SERVE TRAVEL JOG+', value: "0" },
          { name: 'A02 SERVE TRAVEL JOG-', value: "0" },
          { name: 'B01 SERVE TRAVEL JOG+', value: "0" },
          { name: 'B02 SERVE TRAVEL JOG-', value: "0" },
          { name: 'A01 SERVE TURN POS', value: "0" },
          { name: 'A02 SERVE TURN POS', value: "0" },
          { name: 'A01 SERVE TRAVEL POS', value: "0" },
          { name: 'A02 SERVE TRAVEL POS', value: "0" },
          { name: 'B01 SERVE TRAVEL POS', value: "0" },
          { name: 'B02 SERVE TRAVEL POS', value: "0" },
          { name: 'B01 YV TURN', value: "0" },
          { name: 'B01 YV UP DOWN', value: "0" },
          { name: 'B02 YV TURN', value: "0" },
          { name: 'B02 YV UP DOWN', value: "0" },
        ]
        ,
      },
@@ -86,7 +111,7 @@
  },
  methods: {
    init () {
      let viewname = "Action";
      let viewname = "action";
      if (typeof (WebSocket) == "undefined") {
        console.log("您的浏览器不支持WebSocket");
@@ -105,25 +130,26 @@
          console.log("websocket已打开");
        };
        //  浏览器端收消息,获得从服务端发送过来的文本消息
        socket.onmessage = function (msg) {
          //console.log("收到数据====" + msg.data);
          let obj = JSON.parse(msg.data);
          this.record.params[0] = obj.acion[0].join(",");
          this.record.params[0] = this.record.params[0].split(",");
          for (let a = 0; a <= this.record.params.length - 1; a++) {
            // if (!this.record.xyData[a]) {
            //   this.record.xyData[a] = { name: this.record.canshu[a], value: this.record.params[0][a] };
            // } else {
            //   this.record.xyData[a].value = this.record.params[0][a];
            // }
            this.record.xyData[a] = { name: this.record.canshu[a], value: this.record.params[0][a] };
        socket.onmessage = (msg) => {
          if (!msg.data) {
            return; // 如果收到空数据,则直接返回,不执行后续逻辑
          }
          console.log(this.record.xyData)
          let obj = JSON.parse(msg.data);
          this.record.params[0] = obj.params[0];
          for (let a = 0; a <= this.record.params[0].length; a++) {
            if (!this.record.xyData[a]) {
              this.record.xyData[a] = { name: this.record.canshu[a], value: this.record.params[0][a].toString() };
            } else {
              this.record.xyData[a].value = this.record.params[0][a].toString();
            }
          }
          console.log(this.record.xyData);
          this.$forceUpdate();
        }.bind(this);
        };
        //关闭事件
        socket.onclose = function () {
          console.log("websocket已关闭");
@@ -136,8 +162,9 @@
    },
    send () {
      this.messagepack.data = { taskname: "前端到后台" };
      socket?.send(JSON.stringify(this.messagepack));  // 将组装好的json发送给服务端,由服务端进行转发
      this.messagepack.data = this.record.xyData.map(item => parseInt(item.value)); // 转换为整数数组
      console.log(this.messagepack);
      socket?.send(JSON.stringify(this.messagepack));
    }
  }
CanadaMes-ui/src/views/Electrical/Parameter.vue
@@ -44,12 +44,14 @@
        params: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        xyData: [
          { name: 'conveyor Velocity(Auto FAST)', value: 0 },
          { name: 'conveyor Velocity(Auto SLOW)', value: 0 },
          { name: 'conveyor Velocity(Manual)', value: 0 },
          { name: 'A01 A02 TURN JOG Velocity', value: 0 },
          { name: 'A01 A02 TRAVEL JOG Velocity', value: 0 },
          { name: 'B01 B02 TRAVEL JOG Velocity', value: 0 },
          { name: 'A01 A02 TURN POS Velocity AUTO', value: 0 },
          { name: 'A01 A02 TURN POS Velocity manual', value: 0 },
          { name: '01 A02 TRAVEL POS Velocity AUTO', value: 0 },
          { name: 'A01 A02 TRAVEL POS Velocity AUTO', value: 0 },
          { name: 'A01 A02 TRAVEL POS Velocity manual', value: 0 },
          { name: 'B01 B02 TRAVEL POS Velocity AUTO', value: 0 },
          { name: 'B01 B02 TRAVEL POS Velocity manual', value: 0 },
@@ -57,6 +59,10 @@
        ],
        canshu: [
          'conveyor Velocity(Auto FAST)',
          'conveyor Velocity(Auto SLOW)',
          'conveyor Velocity(Manual)',
          'A01 A02 TURN JOG Velocity',
          'A01 A02 TRAVEL JOG Velocity',
          'B01 B02 TRAVEL JOG Velocity',
          'A01 A02 TURN POS Velocity AUTO',
          'A01 A02 TURN POS Velocity manual',
@@ -109,10 +115,10 @@
          let obj = JSON.parse(msg.data);
          //this.$set(this.record.params, 0, obj.params[0]);
          this.record.params[0] = obj.params[0];
          for (let a = 0; a <= this.record.params.length - 1; a++) {
          for (let a = 0; a <= this.record.params.length; a++) {
            // this.record.xyData[a] = [this.record.canshu[a], this.record.params[0][a]];
            // this.record.xyData[a] = { name: this.record.canshu[a], value: this.record.params[0][a] };
            this.record.xyData[a].value = this.record.params[0][a];
            this.record.xyData[a] = { name: this.record.canshu[a], value: this.record.params[0][a] };
            // this.record.xyData[a].value = this.record.params[0][a];
          }
          this.$forceUpdate();
CanadaMes-ui/src/views/Electrical/Sign.vue
@@ -14,12 +14,10 @@
    <div style="padding-right: 30px;display: flex;flex-wrap: wrap;" class="neir">
      <div class="kuai_sb" v-for="item in record.xyData" :key="item.name">
        <el-col class="deng" :class="getStatusClass(item.value, item.name)">
          <!-- <el-input v-model="item.zhuangtai" style="width: 280px;display: none;"
            class="in_mc"></el-input>-->
          <!-- <el-input v-model="item.value" style="width: 280px;" class="in_mc"></el-input> -->
        </el-col>
        <el-input v-model="item.name" style="width: 280px;" class="in_mc"></el-input>
        <!-- <el-switch v-model="item.zhuangtai" active-color="#13ce66" active-value="1" inactive-value="2"></el-switch> -->
      </div>
    </div>
@@ -34,49 +32,102 @@
  data () {
    return {
      record: {
        params: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,],
        params: [1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
          1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,],
        xyData: [
          { name: 'D01.SR dec', value: 0 },
          { name: "D01.SR in pos", value: 0 },
          { name: "D02.SR dec", value: 0 },
          { name: "D02.SR in pos", value: 0 },
          { name: "D03.SR into", value: 0 },
          { name: "D03.SR dec", value: 0 },
          { name: "D03.SR in pos", value: 0 },
          { name: 'D03.SR in pos', value: 0 },
          { name: "D04.SR dec", value: 0 },
          { name: "D04.SR in pos", value: 0 },
          { name: "D05.SR dec", value: 0 },
          { name: "D05.SR in pos", value: 0 },
          { name: "D06.SR dec", value: 0 },
          { name: 'D06.SR in pos', value: 0 },
          { name: "B01.SR out dec", value: 0 },
          { name: "B01.SR out in pos", value: 0 },
          { name: "B01.SR in dec", value: 0 },
          { name: "B01.SR in in pos", value: 0 },
          { name: "B01.SR turn on", value: 0 },
          { name: 'B01.SR turn off', value: 0 },
          { name: "B01.SR up", value: 0 },
          { name: "B01.SR down", value: 0 },
          { name: "B02.SR out dec", value: 0 },
          { name: "B02.SR out in pos", value: 0 },
          { name: "B02.SR in dec", value: 0 },
          { name: 'B02.SR in in pos', value: 0 },
          { name: "B02.SR turn on", value: 0 },
          { name: "B02.SR turn off", value: 0 },
          { name: "B02.SR up", value: 0 },
          { name: "B02.SR down", value: 0 },
          { name: "B01.SR out safety", value: 0 },
          { name: "B01.SR in safety", value: 0 },
          { name: "B02.SR out safety", value: 0 },
          { name: "SB.start(+)", value: 0 },
          { name: "SB.stop(1)", value: 0 },
          { name: "SB.reset", value: 0 },
          { name: "SB.auto/manul", value: 0 },
          { name: "SB.pause", value: 0 },
          { name: "SB.emg", value: 0 },
          { name: "D01.SB.start", value: 0 },
          { name: "D06.SB.start", value: 0 },
          { name: "B02.SR in safety", value: 0 },
          { name: "SAFETYDOOR.requset", value: 0 },
          { name: "SAFETYDOOR.confirm", value: 0 },
          { name: "SAFETYDOOR.reset", value: 0 },
          { name: "LED.red", value: 0 },
          { name: "LED.green", value: 0 },
          { name: "LED.yellow", value: 0 },
          { name: "D01.LED.green", value: 0 },
          { name: "D06.LED.green", value: 0 },
          { name: "B01.YV.turn", value: 0 },
          { name: "B01.YV.up down", value: 0 },
          { name: "B01.YV.gassing", value: 0 },
          { name: "B02.YV.turn", value: 0 },
          { name: "B02.YV.up down", value: 0 },
          { name: "B02.YV.gassing", value: 0 },
          { name: "SAFETYDOOR.led", value: 0 },
          { name: "SAFETYDOOR.open", value: 0 },
        ],
        canshu: [
          'D01.SR dec',
          'D01.SR in pos',
          'D02.SR dec',
          'D02.SR in pos',
          'D03.SR into',
          'D03.SR dec',
          'D03.SR in pos',
          'D04.SR dec',
          'D04.SR in pos',
          'D05.SR dec',
          'D05.SR in pos',
          'D06.SR dec',
          'D06.SR in pos',
          'B01.SR out dec',
          'B01.SR out in pos',
          'B01.SR in dec',
          'B01.SR in in pos',
          'B01.SR turn on',
          'B01.SR turn off',
          'B01.SR up',
          'B01.SR down',
          'B02.SR out dec',
          'B02.SR out in pos',
          'B02.SR in dec',
          'B02.SR in in pos',
          'B02.SR turn on',
          'B02.SR turn off',
          'B02.SR up',
          'B02.SR down',
          'LED.red',
          'LED.green',
          'LED.yellow',
        ],
        // canshu: [
        //   'D01.SR dec',
        //   'D01.SR in pos',
        //   'D02.SR dec',
        //   'D02.SR in pos',
        //   'D03.SR into',
        //   'D03.SR dec',
        //   'D03.SR in pos',
        //   'D04.SR dec',
        //   'D04.SR in pos',
        //   'D05.SR dec',
        //   'D05.SR in pos',
        //   'D06.SR dec',
        //   'D06.SR in pos',
        //   'B01.SR out dec',
        //   'B01.SR out in pos',
        //   'B01.SR in dec',
        //   'B01.SR in in pos',
        //   'B01.SR turn on',
        //   'B01.SR turn off',
        //   'B01.SR up',
        //   'B01.SR down',
        //   'B02.SR out dec',
        //   'B02.SR out in pos',
        //   'B02.SR in dec',
        //   'B02.SR in in pos',
        //   'B02.SR turn on',
        //   'B02.SR turn off',
        //   'B02.SR up',
        //   'B02.SR down',
        //   'LED.red',
        //   'LED.green',
        //   'LED.yellow',
        // ],
      },
@@ -97,15 +148,18 @@
  methods: {
    getStatusClass (zhuangtai, mc) {
      if (mc === "LED.red" && zhuangtai === 0) {
        return "red";
      }
      if (mc === "LED.green" && zhuangtai === 0) {
        return "green";
      }
      if (mc === "LED.red" && zhuangtai === 0) {
        return "red";
      }
      if (mc === "LED.yellow" && zhuangtai === 0) {
        return "yellow"
      }
      if (zhuangtai === 0) {
        return "op";
      }
@@ -144,9 +198,12 @@
          let obj = JSON.parse(msg.data);
          //this.$set(this.record.params, 0, obj.params[0]);
          this.record.params[0] = obj.sig[0];
          for (let a = 0; a <= this.record.params.length - 1; a++) {
            //this.record.xyData[a] = [this.record.params[0][a], this.record.canshu[a]];
          for (let a = 0; a <= this.record.params.length; a++) {
            if (!this.record.xyData[a]) {
            this.record.xyData[a] = { name: this.record.canshu[a], value: this.record.params[0][a] };
            } else {
              this.record.xyData[a].value = this.record.params[0][a];
            }
          }
          this.$forceUpdate();
@@ -236,7 +293,7 @@
  background-color: red;
}
.geeen {
.green {
  background-color: #00ff22;
}
CanadaMes-ui/src/views/Electrical/State.vue
@@ -109,7 +109,7 @@
          //console.log("收到数据====" + msg.data);
          let obj = JSON.parse(msg.data);
          this.record.params[0] = obj.sta[0];
          for (let a = 0; a <= this.record.params.length - 1; a++) {
          for (let a = 0; a <= this.record.params.length; a++) {
            //this.record.xyData[a] = [this.record.params[0][a], this.record.canshu[a]];
            this.record.xyData[a] = { name: this.record.canshu[a], value: this.record.params[0][a] };
          }
CanadaMes-ui/src/views/Electrical/alarm.vue
@@ -18,65 +18,33 @@
        </div>
      </el-form> -->
    <el-table :data="record.xyData" style="width: 100%">
      <el-table-column prop="xyData[1]" label="content" width="180">
    <el-table :data="tableData" style="width: 100%;" height="590">
      <el-table-column prop="id" label="id" width="80">
      </el-table-column>
      <el-table-column prop="name" label="time-on" width="180">
      <el-table-column prop="content" label="content">
      </el-table-column>
      <el-table-column prop="address" label="End Time">
      <el-table-column prop="timeon" label="time-on">
      </el-table-column>
      <el-table-column prop="endTime" label="End Time">
      </el-table-column>
    </el-table>
  </div>
</template>
<script >
import { setAll } from "../../api/alarm";
let socket;
export default {
  name: "alarm",
  data () {
    return {
      record: {
        params: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        canshu: [
          'D01 VFD error',
          'D02 VFD error',
          'D03 VFD error',
          'D04 VFD conveyor',
          'D05 VFD conveyor',
          'D06 VFD conveyor',
          'A01 VFD conveyor',
          'A02 VFD conveyor',
          'B01 VFD conveyor',
          'B02 VFD conveyor',
          'A01 SERVE TURN JOG+',
          'A02 SERVE TURN JOG-',
          'A01 SERVE TRAVEL JOG+',
          'A02 SERVE TRAVEL JOG-',
          'B01 SERVE TRAVEL JOG+',
          'B02 SERVE TRAVEL JOG-',
          'A01 SERVE TURN POS',
          'A02 SERVE TURN POS',
          'A01 SERVE TRAVEL POS',
          'A02 SERVE TRAVEL POS',
          'B01 SERVE TRAVEL POS',
          'B02 SERVE TRAVEL POS',
          'B01 YV TURN',
          'B01 YV UP DOWN',
          'B02 YV TURN',
          'B02 YV UP DOWN',
        ],
        // canshu: [
        //   '1',
        //   '1',
        //   '0',
        //   '0',
        //   '0',
        //   '0'
        // ],
        xyData: [],
      },
        params: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        // xyData: [],
      },
      tableData: [],
      messagepack: {
        data: { taskname: "" }
@@ -90,10 +58,18 @@
  },
  created () {
    this.init();
    this.load();
  },
  methods: {
    load () {
      setAll().then(res => {
        this.tableData = res.data.list;
        //console.log(this.tableData);
      });
    },
    init () {
      let viewname = "Action";
      let viewname = "alarm";
      if (typeof (WebSocket) == "undefined") {
        console.log("您的浏览器不支持WebSocket");
@@ -117,14 +93,9 @@
          //console.log("收到数据====" + msg.data);
          let obj = JSON.parse(msg.data);
          this.record.params[0] = obj.acion[0].join(",");
          this.record.params[0] = this.record.params[0].split(",");
          for (let a = 0; a <= this.record.params.length - 1; a++) {
            this.record.xyData[a] = [this.record.params[0][a], this.record.canshu[a]];
          }
          //console.log(this.record.params[0]);
          //console.log(this.record.xyData);
          this.record.params[0] = obj.arm;
          //每次请求更新数据
          this.load();
          this.$forceUpdate();
        }.bind(this);
        //关闭事件
@@ -176,4 +147,9 @@
    border: none;
  }
}
td div,
th div {
  text-align: center;
}
</style>
springboot-vue3/src/main/java/com/example/springboot/AuthorityApplication.java
@@ -2,12 +2,20 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import com.example.springboot.component.WebSocketServer;
@SpringBootApplication
public class AuthorityApplication {
    public static void main(String[] args) {
        SpringApplication.run(AuthorityApplication.class, args);
    // SpringApplication.run(AuthorityApplication.class, args);
    SpringApplication springApplication = new SpringApplication(AuthorityApplication.class);
    ConfigurableApplicationContext configurableApplicationContext = springApplication.run(args);
    WebSocketServer.setApplicationContext(configurableApplicationContext);
    }
}
springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java
@@ -4,10 +4,15 @@
import javax.websocket.Session;
import com.example.springboot.mapper.AlarmMapper;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
public class PlcHold extends Thread {
  private AlarmMapper alarmMapper;
  @Override
  public void run() {
    while (this != null) {
@@ -24,42 +29,6 @@
      // 查询数据库
      // 推送到前端
      // Parameter
      JSONObject jsonObject = new JSONObject();
      jsonObject.append("params", new short[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, });
      WebSocketServer sendwServer = WebSocketServer.sessionMap.get("Parameter");
      if (sendwServer != null) {
        sendwServer.sendMessage(jsonObject.toString());
      }
      // Action
      // JSONObject jsonObject2 = new JSONObject();
      // jsonObject2.append("acion",
      // new short[] { 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
      // 1, 1, 1, 0, 0, });
      // WebSocketServer sendwServer2 = WebSocketServer.sessionMap.get("Action");
      // if (sendwServer2 != null) {
      // sendwServer2.sendMessage(jsonObject2.toString());
      // }
      // Sign
      JSONObject jsonObject3 = new JSONObject();
      jsonObject3.append("sig",
          new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0,
              1, });
      WebSocketServer sendwServer3 = WebSocketServer.sessionMap.get("Sign");
      if (sendwServer3 != null) {
        sendwServer3.sendMessage(jsonObject3.toString());
      }
      // State
      JSONObject jsonObject4 = new JSONObject();
      jsonObject4.append("sta", new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, });
      WebSocketServer sendwServer4 = WebSocketServer.sessionMap.get("State");
      if (sendwServer4 != null) {
        sendwServer4.sendMessage(jsonObject4.toString());
      }
    }
  }
springboot-vue3/src/main/java/com/example/springboot/component/PlcParameter.java
New file
@@ -0,0 +1,75 @@
package com.example.springboot.component;
import cn.hutool.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class PlcParameter extends Thread {
  @Override
  public void run() {
    while (this != null) {
      try {
        Thread.sleep(10000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      List<Short> paramlist = S7control.getinstance().ReadWord("DB100.DBW", 12);
      JSONObject jsonObject = new JSONObject();
      // jsonObject.append("params", paramlist);
      jsonObject.append("params", new short[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, });
      WebSocketServer sendwServer = WebSocketServer.sessionMap.get("Parameter");
      if (sendwServer != null) {
        sendwServer.sendMessage(jsonObject.toString());
      }
      WebSocketServer webSocketServer = WebSocketServer.sessionMap.get("Parameter");
      if (webSocketServer != null) {
        List<String> messages = webSocketServer.getMessages();
        String addressList = "DB100.DBW0";
        // addressList.add("DB100.DBW0");
        // addressList.add("DB100.DBW2");
        // addressList.add("DB100.DBW4");
        // addressList.add("DB100.DBW6");
        // addressList.add("DB100.DBW8");
        // addressList.add("DB100.DBW10");
        // addressList.add("DB100.DBW12");
        // addressList.add("DB100.DBW14");
        // addressList.add("DB100.DBW16");
        // addressList.add("DB100.DBW18");
        // addressList.add("DB100.DBW20");
        // addressList.add("DB100.DBW22");
        if (!messages.isEmpty()) {
          // 将最后一个消息转换为 short 类型的列表
          String lastMessage = messages.get(messages.size() - 1);
          System.out.println("messages:" + messages);
          String[] parts = lastMessage.split(",");
          List<Short> messageValues = new ArrayList<>();
          for (String part : parts) {
            try {
              // 使用正则表达式清除非数字字符
              String cleanedPart = part.replaceAll("[^0-9-]", "");
              short value = Short.parseShort(cleanedPart.trim());
              messageValues.add(value);
            } catch (NumberFormatException e) {
              // 如果无法解析为 short 类型,则忽略该部分
              e.printStackTrace();
            }
          }
          // 将消息值写入 PLC
          // S7control.getinstance().WriteWord(addressList, messageValues);
          System.out.println("messageValues:" + messageValues);
          System.out.println("addressList:" + addressList);
          // 清空消息列表
          webSocketServer.clearMessages();
        }
      }
    }
  }
}
springboot-vue3/src/main/java/com/example/springboot/component/Plcaction.java
@@ -18,7 +18,8 @@
            List<Short> paramlist = S7control.getinstance().ReadWord("DB100.DBW", 12);
            JSONObject jsonObject = new JSONObject();
            jsonObject.append("params", paramlist);
      jsonObject.append("params", new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0
      });
            WebSocketServer sendwServer = WebSocketServer.sessionMap.get("action");
            if (sendwServer != null) {
                sendwServer.sendMessage(jsonObject.toString());
@@ -28,19 +29,19 @@
            if (webSocketServer != null) {
                List<String> messages = webSocketServer.getMessages();
                List<String> addressList = new ArrayList<>();
                addressList.add("DB100.DBW0");
                addressList.add("DB100.DBW2");
                addressList.add("DB100.DBW4");
                addressList.add("DB100.DBW6");
                addressList.add("DB100.DBW8");
                addressList.add("DB100.DBW10");
                addressList.add("DB100.DBW12");
                addressList.add("DB100.DBW14");
                addressList.add("DB100.DBW16");
                addressList.add("DB100.DBW18");
                addressList.add("DB100.DBW20");
                addressList.add("DB100.DBW22");
        String addressList = "DB100.DBW0";
        // addressList.add("DB100.DBW0");
        // addressList.add("DB100.DBW2");
        // addressList.add("DB100.DBW4");
        // addressList.add("DB100.DBW6");
        // addressList.add("DB100.DBW8");
        // addressList.add("DB100.DBW10");
        // addressList.add("DB100.DBW12");
        // addressList.add("DB100.DBW14");
        // addressList.add("DB100.DBW16");
        // addressList.add("DB100.DBW18");
        // addressList.add("DB100.DBW20");
        // addressList.add("DB100.DBW22");
                if (!messages.isEmpty()) {
                    // 将最后一个消息转换为 short 类型的列表
@@ -64,8 +65,9 @@
                    // 将消息值写入 PLC
//                    S7control.getinstance().WriteWord(addressList, messageValues);
                    System.out.println("messageValues:" + messageValues);
          System.out.println("addressList:" + addressList);
                    // 清空消息列表
                    messages.clear();
          webSocketServer.clearMessages();
                }
            }
        }
springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java
New file
@@ -0,0 +1,148 @@
package com.example.springboot.component;
import cn.hutool.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import com.example.springboot.mapper.AlarmMapper;
public class Plcalarm extends Thread {
  private AlarmMapper alarmMapper;
  @Override
  public void run() {
    while (this != null) {
      try {
        Thread.sleep(10000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      List<Short> paramlist = S7control.getinstance().ReadWord("DB100.DBW", 12);
      // JSONObject jsonObject = new JSONObject();
      // // jsonObject.append("params", paramlist);
      // jsonObject.append("params", new short[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
      // 11, });
      // WebSocketServer sendwServer = WebSocketServer.sessionMap.get("Parameter");
      // if (sendwServer != null) {
      // sendwServer.sendMessage(jsonObject.toString());
      // }
      JSONObject jsonObject = new JSONObject();
      jsonObject.append("arm",
          new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0,
              1, 0, 1, 0, 1, 0, 1, 0, 1, });
      WebSocketServer sendwServer = WebSocketServer.sessionMap.get("alarm");
      if (sendwServer != null) {
        sendwServer.sendMessage(jsonObject.toString());
      }
      Short[] shuzu1 = {
          1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0,
          1, 0, 1, 0, 1, 0, 1, 0, 1,
      };
      String[] shuzu = {
          "D01 VFD error",
          "D02 VFD error",
          "D03 VFD error",
          "D04 VFD error",
          "D05 VFD error",
          "D06 VFD error",
          "B01 VFD error",
          "B02 VFD error",
          "A01 VFD error",
          "A02 VFD error",
          "A01 servo turn error",
          "A02 servo turn error",
          "A01 servo travel error",
          "A02 servo travel error",
          "B01 servo travel error",
          "B02 servo travel error",
          "D01 DEC error",
          "D01 pos error",
          "D02 DEC error",
          "D02 pos error",
          "D03 DEC error",
          "D03 pos error",
          "D04 DEC error",
          "D04 pos error",
          "D05 DEC error",
          "D05 pos error",
          "D06 DEC error",
          "D06 pos error",
          "A01 DEC error",
          "A01 pos error",
          "A02 DEC error",
          "A02 pos error",
          "B01 IN DEC error",
          "B01 IN pos error",
          "B01 OUT DEC error",
          "B01 OUT pos error",
          "B02 IN DEC error",
          "B02 IN pos error",
          "B02 OUT DEC error",
          "B02 OUT pos error",
      };
      alarmMapper = WebSocketServer.applicationContext.getBean(AlarmMapper.class);
      for (short i = 0; i < shuzu1.length; i++) {
        short result = alarmMapper.selectnullti(shuzu[i]);
        if (shuzu1[i] == 1 && result == 0) {
          alarmMapper.Insertalarm(shuzu[i]);
        } else if (shuzu1[i] == 0 && result > 0) {
          alarmMapper.updatealarm(shuzu[i]);
        }
      }
      // 写
      WebSocketServer webSocketServer = WebSocketServer.sessionMap.get("Parameter");
      if (webSocketServer != null) {
        List<String> messages = webSocketServer.getMessages();
        String addressList = "DB100.DBW0";
        // addressList.add("DB100.DBW0");
        // addressList.add("DB100.DBW2");
        // addressList.add("DB100.DBW4");
        // addressList.add("DB100.DBW6");
        // addressList.add("DB100.DBW8");
        // addressList.add("DB100.DBW10");
        // addressList.add("DB100.DBW12");
        // addressList.add("DB100.DBW14");
        // addressList.add("DB100.DBW16");
        // addressList.add("DB100.DBW18");
        // addressList.add("DB100.DBW20");
        // addressList.add("DB100.DBW22");
        if (!messages.isEmpty()) {
          // 将最后一个消息转换为 short 类型的列表
          String lastMessage = messages.get(messages.size() - 1);
          System.out.println("messages:" + messages);
          String[] parts = lastMessage.split(",");
          List<Short> messageValues = new ArrayList<>();
          for (String part : parts) {
            try {
              // 使用正则表达式清除非数字字符
              String cleanedPart = part.replaceAll("[^0-9-]", "");
              short value = Short.parseShort(cleanedPart.trim());
              messageValues.add(value);
            } catch (NumberFormatException e) {
              // 如果无法解析为 short 类型,则忽略该部分
              e.printStackTrace();
            }
          }
          // 将消息值写入 PLC
          // S7control.getinstance().WriteWord(addressList, messageValues);
          System.out.println("messageValues:" + messageValues);
          System.out.println("addressList:" + addressList);
          // 清空消息列表
          webSocketServer.clearMessages();
        }
      }
    }
  }
}
springboot-vue3/src/main/java/com/example/springboot/component/Plcsign.java
New file
@@ -0,0 +1,85 @@
package com.example.springboot.component;
import cn.hutool.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class Plcsign extends Thread {
  @Override
  public void run() {
    while (this != null) {
      try {
        Thread.sleep(10000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      List<Short> paramlist = S7control.getinstance().ReadWord("DB100.DBW", 12);
      // JSONObject jsonObject = new JSONObject();
      // // jsonObject.append("params", paramlist);
      // jsonObject.append("params", new short[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
      // 11, });
      // WebSocketServer sendwServer = WebSocketServer.sessionMap.get("Parameter");
      // if (sendwServer != null) {
      // sendwServer.sendMessage(jsonObject.toString());
      // }
      JSONObject jsonObject3 = new JSONObject();
      jsonObject3.append("sig",
          new short[] { 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
              1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, });
      WebSocketServer sendwServer3 = WebSocketServer.sessionMap.get("Sign");
      if (sendwServer3 != null) {
        sendwServer3.sendMessage(jsonObject3.toString());
      }
      WebSocketServer webSocketServer = WebSocketServer.sessionMap.get("Sign");
      if (webSocketServer != null) {
        List<String> messages = webSocketServer.getMessages();
        String addressList = "DB100.DBW0";
        // addressList.add("DB100.DBW0");
        // addressList.add("DB100.DBW2");
        // addressList.add("DB100.DBW4");
        // addressList.add("DB100.DBW6");
        // addressList.add("DB100.DBW8");
        // addressList.add("DB100.DBW10");
        // addressList.add("DB100.DBW12");
        // addressList.add("DB100.DBW14");
        // addressList.add("DB100.DBW16");
        // addressList.add("DB100.DBW18");
        // addressList.add("DB100.DBW20");
        // addressList.add("DB100.DBW22");
        if (!messages.isEmpty()) {
          // 将最后一个消息转换为 short 类型的列表
          String lastMessage = messages.get(messages.size() - 1);
          System.out.println("messages:" + messages);
          String[] parts = lastMessage.split(",");
          List<Short> messageValues = new ArrayList<>();
          for (String part : parts) {
            try {
              // 使用正则表达式清除非数字字符
              String cleanedPart = part.replaceAll("[^0-9-]", "");
              short value = Short.parseShort(cleanedPart.trim());
              messageValues.add(value);
            } catch (NumberFormatException e) {
              // 如果无法解析为 short 类型,则忽略该部分
              e.printStackTrace();
            }
          }
          // 将消息值写入 PLC
          // S7control.getinstance().WriteWord(addressList, messageValues);
          System.out.println("messageValues:" + messageValues);
          System.out.println("addressList:" + addressList);
          // 清空消息列表
          webSocketServer.clearMessages();
        }
      }
    }
  }
}
springboot-vue3/src/main/java/com/example/springboot/component/Plcstate.java
New file
@@ -0,0 +1,85 @@
package com.example.springboot.component;
import cn.hutool.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class Plcstate extends Thread {
  @Override
  public void run() {
    while (this != null) {
      try {
        Thread.sleep(10000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      List<Short> paramlist = S7control.getinstance().ReadWord("DB100.DBW", 12);
      // JSONObject jsonObject = new JSONObject();
      // // jsonObject.append("params", paramlist);
      // jsonObject.append("params", new short[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
      // 11, });
      // WebSocketServer sendwServer = WebSocketServer.sessionMap.get("Parameter");
      // if (sendwServer != null) {
      // sendwServer.sendMessage(jsonObject.toString());
      // }
      JSONObject jsonObject = new JSONObject();
      jsonObject.append("sta",
          new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0,
              1, });
      WebSocketServer sendwServer = WebSocketServer.sessionMap.get("State");
      if (sendwServer != null) {
        sendwServer.sendMessage(jsonObject.toString());
      }
      WebSocketServer webSocketServer = WebSocketServer.sessionMap.get("State");
      if (webSocketServer != null) {
        List<String> messages = webSocketServer.getMessages();
        String addressList = "DB100.DBW0";
        // addressList.add("DB100.DBW0");
        // addressList.add("DB100.DBW2");
        // addressList.add("DB100.DBW4");
        // addressList.add("DB100.DBW6");
        // addressList.add("DB100.DBW8");
        // addressList.add("DB100.DBW10");
        // addressList.add("DB100.DBW12");
        // addressList.add("DB100.DBW14");
        // addressList.add("DB100.DBW16");
        // addressList.add("DB100.DBW18");
        // addressList.add("DB100.DBW20");
        // addressList.add("DB100.DBW22");
        if (!messages.isEmpty()) {
          // 将最后一个消息转换为 short 类型的列表
          String lastMessage = messages.get(messages.size() - 1);
          System.out.println("messages:" + messages);
          String[] parts = lastMessage.split(",");
          List<Short> messageValues = new ArrayList<>();
          for (String part : parts) {
            try {
              // 使用正则表达式清除非数字字符
              String cleanedPart = part.replaceAll("[^0-9-]", "");
              short value = Short.parseShort(cleanedPart.trim());
              messageValues.add(value);
            } catch (NumberFormatException e) {
              // 如果无法解析为 short 类型,则忽略该部分
              e.printStackTrace();
            }
          }
          // 将消息值写入 PLC
          // S7control.getinstance().WriteWord(addressList, messageValues);
          System.out.println("messageValues:" + messageValues);
          System.out.println("addressList:" + addressList);
          // 清空消息列表
          webSocketServer.clearMessages();
        }
      }
    }
  }
}
springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java
@@ -7,7 +7,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
@@ -16,8 +15,8 @@
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
@@ -25,6 +24,14 @@
@ServerEndpoint(value = "/api/talk/{username}")
@Component
public class WebSocketServer {
  static ConfigurableApplicationContext applicationContext;
  // 解决无法注入mapper问题  //使用方法
  // homeMapper=WebSocketServer.applicationContext.getBean(HomeMapper.class);
  public static void setApplicationContext(ConfigurableApplicationContext configurableApplicationContext) {
    WebSocketServer.applicationContext = configurableApplicationContext;
  }
   private static final Logger log = LoggerFactory.getLogger(WebSocketServer.class);
    private List<String> messages;
@@ -35,9 +42,11 @@
    
    String username;
    Session session;
    public WebSocketServer() {
        this.messages = new ArrayList<>();
    }
    /**
     * 连接建立成功调用的方法
     */
@@ -74,6 +83,7 @@
     * 后台收到客户端发送过来的消息
     * onMessage 是一个消息的中转站
     * 接受 浏览器端 socket.send 发送过来的 json数据
   *
     * @param message 客户端发送过来的消息
     */
    @OnMessage
springboot-vue3/src/main/java/com/example/springboot/config/AppRunnerConfig.java
@@ -6,7 +6,11 @@
import org.springframework.stereotype.Component;
import com.example.springboot.component.PlcHold;
import com.example.springboot.component.PlcParameter;
import com.example.springboot.component.Plcaction;
import com.example.springboot.component.Plcalarm;
import com.example.springboot.component.Plcsign;
import com.example.springboot.component.Plcstate;
@Component
@Order(1)
@@ -20,5 +24,13 @@
    new PlcHold().start();
    new Plcaction().start();
    new PlcParameter().start();
    new Plcalarm().start();
    new Plcsign().start();
    new Plcstate().start();
  }
}
springboot-vue3/src/main/java/com/example/springboot/controller/AlarmController.java
New file
@@ -0,0 +1,34 @@
package com.example.springboot.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.springboot.common.Result;
import com.example.springboot.entity.alarmmg;
import com.example.springboot.mapper.AlarmMapper;
import com.example.springboot.service.AlarmService;
@RestController
@RequestMapping("/alarm")
public class AlarmController {
  @Autowired
  AlarmMapper alarmMapper;
  @Autowired
  AlarmService alarmService;
  @GetMapping("/load")
  public Result selectAll() {
    List<alarmmg> storageCagelist = alarmMapper.selectAll();
    Map<String, Object> map = new HashMap<>();
    map.put("list", storageCagelist);
    return Result.success(map);
  }
}
springboot-vue3/src/main/java/com/example/springboot/entity/alarmmg.java
New file
@@ -0,0 +1,43 @@
package com.example.springboot.entity;
import java.util.Date;
public class alarmmg {
  private Integer id;
  private String content;
  private Date timeon;
  private Date endTime;
  public void setid(Integer id) {
    this.id = id;
  }
  public Integer getid() {
    return id;
  }
  public void setontent(String content) {
    this.content = content;
  }
  public String getcontent() {
    return content;
  }
  public void settimeon(Date timeon) {
    this.timeon = timeon;
  }
  public Date gettimeon() {
    return timeon;
  }
  public void setendTime(Date endTime) {
    this.endTime = endTime;
  }
  public Date getendTime() {
    return endTime;
  }
}
springboot-vue3/src/main/java/com/example/springboot/mapper/AlarmMapper.java
New file
@@ -0,0 +1,22 @@
package com.example.springboot.mapper;
import org.apache.ibatis.annotations.*;
import com.example.springboot.entity.alarmmg;
import java.util.List;
@Mapper
public interface AlarmMapper {
  @Select("SELECT * FROM alarmmg")
  List<alarmmg> selectAll();
  @Select("SELECT count(*) FROM alarmmg where endTime is null and content=#{content}")
  short selectnullti(String content);
  @Insert("INSERT INTO `canadames`.`alarmmg`( `content`,`timeon`) VALUES ( #{content},now())")
  void Insertalarm(String content);
  @Insert("UPDATE  `canadames`.`alarmmg` set endTime= now() where endTime is null and content=#{content}")
  void updatealarm(String content);
}
springboot-vue3/src/main/java/com/example/springboot/service/AlarmService.java
New file
@@ -0,0 +1,8 @@
package com.example.springboot.service;
import org.springframework.stereotype.Service;
@Service
public class AlarmService {
}