New file |
| | |
| | | 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 |
| | | }) |
| | | } |
| | |
| | | </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>
|
| | |
|
| | |
| | | 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',
|
| | |
| | | '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" },
|
| | | ]
|
| | | ,
|
| | | },
|
| | |
|
| | |
|
| | |
| | | },
|
| | | methods: {
|
| | | init () {
|
| | | let viewname = "Action";
|
| | | let viewname = "action";
|
| | |
|
| | | if (typeof (WebSocket) == "undefined") {
|
| | | console.log("您的浏览器不支持WebSocket");
|
| | |
| | | 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已关闭");
|
| | |
| | |
|
| | | },
|
| | | 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));
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | 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 },
|
| | |
| | | ],
|
| | | 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',
|
| | |
| | | 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();
|
| | |
|
| | |
| | | <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>
|
| | |
| | | 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',
|
| | | // ],
|
| | |
|
| | | },
|
| | |
|
| | |
| | | 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";
|
| | | }
|
| | |
| | | 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]];
|
| | | this.record.xyData[a] = { name: this.record.canshu[a], value: this.record.params[0][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();
|
| | |
| | | background-color: red;
|
| | | }
|
| | |
|
| | | .geeen {
|
| | | .green {
|
| | | background-color: #00ff22;
|
| | | }
|
| | |
|
| | |
| | | //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] };
|
| | | }
|
| | |
| | | </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: "" } |
| | |
| | | }, |
| | | 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"); |
| | |
| | | //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); |
| | | //关闭事件 |
| | |
| | | border: none; |
| | | } |
| | | } |
| | | |
| | | td div, |
| | | th div { |
| | | text-align: center; |
| | | } |
| | | </style> |
| | |
| | | |
| | | 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); |
| | | } |
| | | public static void main(String[] args) { |
| | | |
| | | // SpringApplication.run(AuthorityApplication.class, args); |
| | | |
| | | SpringApplication springApplication = new SpringApplication(AuthorityApplication.class); |
| | | ConfigurableApplicationContext configurableApplicationContext = springApplication.run(args); |
| | | WebSocketServer.setApplicationContext(configurableApplicationContext); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | 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) { |
| | |
| | | |
| | | // 查询数据库 |
| | | // 推送到前端 |
| | | |
| | | // 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()); |
| | | } |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | import java.util.List;
|
| | |
|
| | | public class Plcaction extends Thread {
|
| | | @Override
|
| | | public void run() {
|
| | | while (this != null) {
|
| | | @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", 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());
|
| | | }
|
| | |
|
| | | WebSocketServer webSocketServer = WebSocketServer.sessionMap.get("action");
|
| | | 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 {
|
| | | Thread.sleep(10000);
|
| | | } catch (InterruptedException e) {
|
| | | e.printStackTrace();
|
| | | // 使用正则表达式清除非数字字符
|
| | | String cleanedPart = part.replaceAll("[^0-9-]", "");
|
| | | short value = Short.parseShort(cleanedPart.trim());
|
| | | messageValues.add(value);
|
| | | } catch (NumberFormatException e) {
|
| | | // 如果无法解析为 short 类型,则忽略该部分
|
| | |
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | List<Short> paramlist = S7control.getinstance().ReadWord("DB100.DBW", 12);
|
| | |
|
| | | JSONObject jsonObject = new JSONObject();
|
| | | jsonObject.append("params", paramlist);
|
| | | WebSocketServer sendwServer = WebSocketServer.sessionMap.get("action");
|
| | | if (sendwServer != null) {
|
| | | sendwServer.sendMessage(jsonObject.toString());
|
| | | }
|
| | |
|
| | | WebSocketServer webSocketServer = WebSocketServer.sessionMap.get("action");
|
| | | 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");
|
| | |
|
| | | 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);
|
| | | // 清空消息列表
|
| | | messages.clear();
|
| | | }
|
| | | }
|
| | | // 将消息值写入 PLC
|
| | | // S7control.getinstance().WriteWord(addressList, messageValues);
|
| | | System.out.println("messageValues:" + messageValues);
|
| | | System.out.println("addressList:" + addressList);
|
| | | // 清空消息列表
|
| | | webSocketServer.clearMessages();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
New file |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | |
| | | import javax.websocket.OnClose; |
| | | import javax.websocket.OnError; |
| | | import javax.websocket.OnMessage; |
| | |
| | | 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; |
| | |
| | | @Component |
| | | public class WebSocketServer { |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(WebSocketServer.class); |
| | | private List<String> messages; |
| | | /** |
| | | * 记录当前在线连接数 |
| | | */ |
| | | public static final Map<String, WebSocketServer> sessionMap = new ConcurrentHashMap<>(); |
| | | |
| | | String username; |
| | | Session session; |
| | | public WebSocketServer() { |
| | | this.messages = new ArrayList<>(); |
| | | } |
| | | /** |
| | | * 连接建立成功调用的方法 |
| | | */ |
| | | @OnOpen |
| | | public void onOpen(Session session, @PathParam("username") String username) { |
| | | this.username=username; |
| | | this.session=session; |
| | | sessionMap.put(username, this); |
| | | log.info("有新用户加入,username={}, 当前在线人数为:{}", username, sessionMap.size()); |
| | | |
| | | // JSONObject result = new JSONObject(); |
| | | // JSONArray array = new JSONArray(); |
| | | // result.set("users", array); |
| | | // for (Object key : sessionMap.keySet()) { |
| | | // JSONObject jsonObject = new JSONObject(); |
| | | // jsonObject.set("username", key); |
| | | // array.add(jsonObject); |
| | | // } |
| | | |
| | | //sendAllMessage(JSONUtil.toJsonStr(result)); // 后台发送消息给所有的客户端 |
| | | } |
| | | static ConfigurableApplicationContext applicationContext; |
| | | // 解决无法注入mapper问题 //使用方法 |
| | | // homeMapper=WebSocketServer.applicationContext.getBean(HomeMapper.class); |
| | | |
| | | /** |
| | | * 连接关闭调用的方法 |
| | | */ |
| | | @OnClose |
| | | public void onClose(Session session, @PathParam("username") String username) { |
| | | sessionMap.remove(username); |
| | | log.info("有一连接关闭,移除username={}的用户session, 当前在线人数为:{}", username, sessionMap.size()); |
| | | } |
| | | public static void setApplicationContext(ConfigurableApplicationContext configurableApplicationContext) { |
| | | WebSocketServer.applicationContext = configurableApplicationContext; |
| | | } |
| | | |
| | | /** |
| | | * 收到客户端消息后调用的方法 |
| | | * 后台收到客户端发送过来的消息 |
| | | * onMessage 是一个消息的中转站 |
| | | * 接受 浏览器端 socket.send 发送过来的 json数据 |
| | | * @param message 客户端发送过来的消息 |
| | | */ |
| | | @OnMessage |
| | | public void onMessage(String message, Session session, @PathParam("username") String username) { |
| | | log.info("服务端收到用户username={}的消息:{}", username, message); |
| | | JSONObject obj = JSONUtil.parseObj(message); |
| | | String text = obj.getStr("data"); |
| | | private static final Logger log = LoggerFactory.getLogger(WebSocketServer.class); |
| | | private List<String> messages; |
| | | /** |
| | | * 记录当前在线连接数 |
| | | */ |
| | | public static final Map<String, WebSocketServer> sessionMap = new ConcurrentHashMap<>(); |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.set("message", text); |
| | | this.messages.add(text); |
| | | this.sendMessage(jsonObject.toString()); //JSONUtil.toJsonStr(jsonObject) |
| | | } |
| | | String username; |
| | | Session session; |
| | | |
| | | @OnError |
| | | public void onError(Session session, Throwable error) { |
| | | log.error("发生错误"); |
| | | error.printStackTrace(); |
| | | } |
| | | public WebSocketServer() { |
| | | this.messages = new ArrayList<>(); |
| | | } |
| | | |
| | | /** |
| | | * 服务端发送消息给客户端 |
| | | */ |
| | | public void sendMessage(String message) { |
| | | try { |
| | | log.info("服务端给客户端[{}]发送消息{}", this.session.getId(), message); |
| | | this.session.getBasicRemote().sendText(message); |
| | | } catch (Exception e) { |
| | | log.error("服务端发送消息给客户端失败", e); |
| | | } |
| | | } |
| | | /** |
| | | * 连接建立成功调用的方法 |
| | | */ |
| | | @OnOpen |
| | | public void onOpen(Session session, @PathParam("username") String username) { |
| | | this.username = username; |
| | | this.session = session; |
| | | sessionMap.put(username, this); |
| | | log.info("有新用户加入,username={}, 当前在线人数为:{}", username, sessionMap.size()); |
| | | |
| | | /** |
| | | * 服务端发送消息给所有客户端 |
| | | */ |
| | | public void sendAllMessage(String message) { |
| | | try { |
| | | for (WebSocketServer webSocketServer : sessionMap.values()) { |
| | | log.info("服务端给客户端[{}]发送消息{}", this.session.getId(), message); |
| | | webSocketServer.sendMessage(message); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("服务端发送消息给客户端失败", e); |
| | | } |
| | | } |
| | | // JSONObject result = new JSONObject(); |
| | | // JSONArray array = new JSONArray(); |
| | | // result.set("users", array); |
| | | // for (Object key : sessionMap.keySet()) { |
| | | // JSONObject jsonObject = new JSONObject(); |
| | | // jsonObject.set("username", key); |
| | | // array.add(jsonObject); |
| | | // } |
| | | |
| | | public List<String> getMessages() { |
| | | return messages; |
| | | } |
| | | // sendAllMessage(JSONUtil.toJsonStr(result)); // 后台发送消息给所有的客户端 |
| | | } |
| | | |
| | | public void clearMessages() { |
| | | messages.clear(); |
| | | /** |
| | | * 连接关闭调用的方法 |
| | | */ |
| | | @OnClose |
| | | public void onClose(Session session, @PathParam("username") String username) { |
| | | sessionMap.remove(username); |
| | | log.info("有一连接关闭,移除username={}的用户session, 当前在线人数为:{}", username, sessionMap.size()); |
| | | } |
| | | |
| | | /** |
| | | * 收到客户端消息后调用的方法 |
| | | * 后台收到客户端发送过来的消息 |
| | | * onMessage 是一个消息的中转站 |
| | | * 接受 浏览器端 socket.send 发送过来的 json数据 |
| | | * |
| | | * @param message 客户端发送过来的消息 |
| | | */ |
| | | @OnMessage |
| | | public void onMessage(String message, Session session, @PathParam("username") String username) { |
| | | log.info("服务端收到用户username={}的消息:{}", username, message); |
| | | JSONObject obj = JSONUtil.parseObj(message); |
| | | String text = obj.getStr("data"); |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.set("message", text); |
| | | this.messages.add(text); |
| | | this.sendMessage(jsonObject.toString()); // JSONUtil.toJsonStr(jsonObject) |
| | | } |
| | | |
| | | @OnError |
| | | public void onError(Session session, Throwable error) { |
| | | log.error("发生错误"); |
| | | error.printStackTrace(); |
| | | } |
| | | |
| | | /** |
| | | * 服务端发送消息给客户端 |
| | | */ |
| | | public void sendMessage(String message) { |
| | | try { |
| | | log.info("服务端给客户端[{}]发送消息{}", this.session.getId(), message); |
| | | this.session.getBasicRemote().sendText(message); |
| | | } catch (Exception e) { |
| | | log.error("服务端发送消息给客户端失败", e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 服务端发送消息给所有客户端 |
| | | */ |
| | | public void sendAllMessage(String message) { |
| | | try { |
| | | for (WebSocketServer webSocketServer : sessionMap.values()) { |
| | | log.info("服务端给客户端[{}]发送消息{}", this.session.getId(), message); |
| | | webSocketServer.sendMessage(message); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("服务端发送消息给客户端失败", e); |
| | | } |
| | | } |
| | | |
| | | public List<String> getMessages() { |
| | | return messages; |
| | | } |
| | | |
| | | public void clearMessages() { |
| | | messages.clear(); |
| | | } |
| | | } |
| | |
| | | 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) |
| | |
| | | new PlcHold().start(); |
| | | |
| | | new Plcaction().start(); |
| | | |
| | | new PlcParameter().start(); |
| | | |
| | | new Plcalarm().start(); |
| | | |
| | | new Plcsign().start(); |
| | | |
| | | new Plcstate().start(); |
| | | } |
| | | } |
New file |
| | |
| | | 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); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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); |
| | | } |
New file |
| | |
| | | package com.example.springboot.service; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | @Service |
| | | public class AlarmService { |
| | | |
| | | } |