| | |
| | | [ |
| | | { |
| | | "name": "A01手动格子", |
| | | "value": 33, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "type": "0", |
| | | "address": "DB100.0", |
| | |
| | | }, |
| | | { |
| | | "name": "A01定位速度", |
| | | "value": 11, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | |
| | | }, |
| | | { |
| | | "name": "A01当前格子", |
| | | "value": 22, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | |
| | | [ |
| | | { |
| | | "name": "A02手动格子", |
| | | "value": 33, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "type": "0", |
| | | "address": "DB100.0", |
| | |
| | | }, |
| | | { |
| | | "name": "A02定位速度", |
| | | "value": 11, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | |
| | | }, |
| | | { |
| | | "name": "A02当前格子", |
| | | "value": 22, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | |
| | | [ |
| | | { |
| | | "name": "B01手动格子", |
| | | "value": 33, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "type": "0", |
| | | "address": "DB100.0", |
| | |
| | | }, |
| | | { |
| | | "name": "B01定位速度", |
| | | "value": 11, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | |
| | | }, |
| | | { |
| | | "name": "B01当前格子", |
| | | "value": 22, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | |
| | | [ |
| | | { |
| | | "name": "B02手动格子", |
| | | "value": 33, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "type": "0", |
| | | "address": "DB100.0", |
| | |
| | | }, |
| | | { |
| | | "name": "B02定位速度", |
| | | "value": 11, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | |
| | | }, |
| | | { |
| | | "name": "B02当前格子", |
| | | "value": 22, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | |
| | | [ |
| | | { |
| | | "name": "A01实时位置", |
| | | "value": 33, |
| | | "value": 0, |
| | | "sending": 4, |
| | | "type": "0", |
| | | "address": "DB100.0", |
| | |
| | | [ |
| | | { |
| | | "name": "A02实时位置", |
| | | "value": 33, |
| | | "value": 0, |
| | | "sending": 5, |
| | | "type": "0", |
| | | "address": "DB100.0", |
| | |
| | | [ |
| | | { |
| | | "name": "B01实时位置", |
| | | "value": 33, |
| | | "value": 0, |
| | | "sending": 6, |
| | | "type": "0", |
| | | "address": "DB100.0", |
| | |
| | | [ |
| | | { |
| | | "name": "B02实时位置", |
| | | "value": 33, |
| | | "value": 0, |
| | | "sending": 7, |
| | | "type": "0", |
| | | "address": "DB100.0", |
| | |
| | | [ |
| | | { |
| | | "name": "手动位置", |
| | | "value": 33, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "type": "0", |
| | | "address": "DB100.0", |
| | |
| | | }, |
| | | { |
| | | "name": "定位速度", |
| | | "value": 11, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "address": "DB100.0", |
| | | "type": "0" |
| | | }, |
| | | { |
| | | "name": "A01翻转实时位置", |
| | | "value": 22, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "address": "DB100.0", |
| | | "type": "0" |
| | |
| | | [ |
| | | { |
| | | "name": "手动位置", |
| | | "value": 33, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "type": "0", |
| | | "address": "DB100.0", |
| | |
| | | }, |
| | | { |
| | | "name": "定位速度", |
| | | "value": 11, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "address": "DB100.0", |
| | | "type": "0" |
| | | }, |
| | | { |
| | | "name": "A02翻转实时位置", |
| | | "value": 22, |
| | | "value": 0, |
| | | "sending": 0, |
| | | "address": "DB100.0", |
| | | "type": "0" |
| | |
| | | { |
| | | "para": [ |
| | | [ |
| | | { |
| | | "name": "D01-D06 conveyor Velocity(Auto FAST)", |
| | | "value": 123, |
| | |
| | | "type": "1", |
| | | "page": "1" |
| | | } |
| | | ], |
| | | "address": [ |
| | | { |
| | | "name": "DB100.0", |
| | | "count": 72 |
| | | }, |
| | | { |
| | | "name": "DB101.0", |
| | | "count": 22 |
| | | }, |
| | | { |
| | | "name": "DB102.0", |
| | | "count": 33 |
| | | } |
| | | ] |
| | | } |
| | | ] |
| | |
| | | path: '/home', |
| | | component: () => import('../views/home') |
| | | }, |
| | | |
| | | |
| | | |
| | | |
| | | { |
| | |
| | | component: () => import('../views/device/parameter'), |
| | | |
| | | }, |
| | | |
| | | |
| | | { |
| | | path: '/device/alarm', |
| | | component: () => import('../views/device/alarm') |
| | |
| | | path: '/device/iostate', |
| | | component: () => import('../views/device/iostate') |
| | | }, |
| | | |
| | | |
| | | { |
| | | path: '/device/control', |
| | | component: () => import('../views/device/control') |
| | |
| | | path: '/Electrical/Positioning2', |
| | | component: () => import('../views/Electrical/Positioning2') |
| | | }, |
| | | { |
| | | path: '/Electrical/ManualonePosition', |
| | | component: () => import('../views/Electrical/ManualonePosition') |
| | | }, |
| | | { |
| | | path: '/Electrical/ManualonePosition2', |
| | | component: () => import('../views/Electrical/ManualonePosition2') |
| | | }, |
| | | { |
| | | path: '/Electrical/AutomaticParameterSetting', |
| | | component: () => import('../views/Electrical/AutomaticParameterSetting') |
| | | }, |
| | | { |
| | | path: '/Electrical/ManualJog', |
| | | component: () => import('../views/Electrical/ManualJog') |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | |
| | | }); |
| | | |
| | | // 路由控制守卫,解决需要登录才可以访问的页面 |
| | | |
| | | |
| | | router.beforeEach((to, from, next) => { |
| | | // 如果访问的是登录或注册页面直接放行 |
| | | if (to.path === '/login' || to.path === '/register') return next(); |
| | | |
| | | // 获取token |
| | | const hasToken = getToken(); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | |
| | | |
| | | let obj = JSON.parse(msg.data); |
| | | const jsonData2 = this.jsonData; |
| | | |
| | | console.log(obj); |
| | | const handleMouseMove = throttle(function (event) { |
| | | |
| | | const inputBox = document.querySelectorAll('.el-card__body'); |
| | |
| | | jsonData2[2][0]['value'] = dache[0][0]; |
| | | } |
| | | } |
| | | }, 50); |
| | | }, 200); |
| | | |
| | | document.addEventListener('mouseover', handleMouseMove); |
| | | }; |
| | |
| | | } |
| | | |
| | | let obj = JSON.parse(msg.data); |
| | | //console.log(obj) |
| | | // console.log(obj) |
| | | const jsonData2 = this.jsonData; |
| | | |
| | | const handleMouseMove = throttle(function (event) { |
| | |
| | | <template> |
| | | <div class="app"> |
| | | <el-breadcrumb separator-class="el-icon-arrow-right" class="el-breadcrumb"> |
| | | <router-link to="/Electrical/alarm" tag="el-button" type="text" active-class="blue-button">{{ $t('Alarm') |
| | | }}</router-link> |
| | | <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') |
| | | }}</router-link> |
| | | <router-link to="/Electrical/Action" tag="el-button" type="text" active-class="blue-button">{{ $t('Action') |
| | | }}</router-link> |
| | | <router-link to="/Electrical/Parameter" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter') |
| | | }}</router-link> |
| | | <router-link to="/Electrical/Sign" tag="el-button" type="text" active-class="blue-button">{{ $t('Sign') |
| | | }}</router-link> |
| | | <router-link to="/Electrical/Servomanual" tag="el-button" type="text" active-class="blue-button">{{ |
| | | $t('ServoManual') |
| | | }}</router-link> |
| | | </el-breadcrumb> |
| | | |
| | | <el-breadcrumb separator-class="el-icon-arrow-right" class="el-breadcrumb"> |
| | | |
| | | <router-link to="/Electrical/Servomanualone" tag="el-button" type="text" active-class="blue-button">{{ |
| | | $t('Servomanualone') |
| | | }}</router-link> |
| | | <router-link to="/Electrical/Parameter1" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter1') |
| | | }}</router-link> |
| | | <!-- <router-link to="/Electrical/Parameter2" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter2') |
| | | }}</router-link> --> |
| | | <router-link to="/Electrical/Positioning1" tag="el-button" type="text" active-class="blue-button">{{ |
| | | $t('Positioning1') |
| | | }}</router-link> |
| | | <router-link to="/Electrical/Positioning2" tag="el-button" type="text" active-class="blue-button">{{ |
| | | $t('Positioning2') |
| | | }}</router-link> |
| | | <router-link to="/Electrical/ManualonePosition" tag="el-button" type="text" active-class="blue-button">{{ |
| | | $t('ManualonePosition') |
| | | }}</router-link> |
| | | <router-link to="/Electrical/ManualonePosition2" tag="el-button" type="text" active-class="blue-button">{{ |
| | | $t('ManualonePosition2') |
| | | }}</router-link> |
| | | <router-link to="/Electrical/AutomaticParameterSetting" tag="el-button" type="text" active-class="blue-button">{{ |
| | | $t('AutomaticParameterSetting') |
| | | }}</router-link> |
| | | <router-link to="/Electrical/ManualJog" tag="el-button" type="text" active-class="blue-button">{{ |
| | | $t('ManualJog') |
| | | }}</router-link> |
| | | </el-breadcrumb> |
| | | |
| | | <el-row :gutter="20"> |
| | | <el-col :span="12" v-for="(dataGroup, groupIndex) in jsonData" :key="groupIndex"> |
| | | <el-card class="json-block" style="width:485px;"> |
| | | <div v-for="(item, itemIndex) in dataGroup" :key="itemIndex" class="item-container"> |
| | | <div class="item-row"> |
| | | <span class="name" style="width:100px;">{{ item.name }}</span> |
| | | <el-input style="width:250px;" v-if="item.state != 0 && item.type === '0'" v-model="item.value" |
| | | class="input-box"></el-input> |
| | | </div> |
| | | </div> |
| | | <div class="button-row" style="display: flex; justify-content: space-between;"> |
| | | <div v-for="(item, itemIndex) in dataGroup" :key="itemIndex"> |
| | | <el-button v-if="item.button && item.button.state != 0" :name="item.button.name" v-model="item.button.value" |
| | | :class="{ 'action-button': true, 'error-button': item.button.name === '故障' && item.button.value === 1 }" |
| | | @click="updateButtonValue(dataGroup, itemIndex); submitDataToBackend(item.button.name);">{{ |
| | | item.button.name }}</el-button> |
| | | </div> |
| | | </div> |
| | | </el-card> |
| | | </el-col> |
| | | </el-row> |
| | | <!-- <el-button @click="submitDataToBackend">提交数据到后端</el-button> --> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | import LanguageMixin from '../../lang/LanguageMixin' |
| | | import data from '../../configuration/Manualoneposition2' |
| | | import { throttle } from 'lodash'; |
| | | let socket; |
| | | export default { |
| | | name: "ManualonePosition2", |
| | | mixins: [LanguageMixin], |
| | | data () { |
| | | return { |
| | | jsonData: data // 加载整个data.json文件作为jsonData |
| | | } |
| | | }, |
| | | created () { |
| | | this.initWebSocket(); |
| | | // console.log('jsonData:', this.jsonData); |
| | | |
| | | }, |
| | | methods: { |
| | | updateButtonValue (dataGroup, itemIndex) { |
| | | // 将当前按钮的值设为1 |
| | | |
| | | this.$set(dataGroup[itemIndex].button, 'value', 1); |
| | | |
| | | |
| | | |
| | | }, |
| | | submitDataToBackend (currentButtonName) { |
| | | if (currentButtonName === 'A01翻转启动') { |
| | | const data = []; |
| | | |
| | | for (let i = 0; i < 1; i++) { |
| | | const inputData = this.jsonData[i].filter(item => item.type === '0').map(item => { |
| | | return { value: item.value }; |
| | | }); |
| | | |
| | | const values = inputData.map(item => item.value); |
| | | |
| | | data.push(values); |
| | | } |
| | | |
| | | |
| | | |
| | | const jsonObject = { data }; |
| | | |
| | | // 提交数据到后端 |
| | | const jsonString = JSON.stringify(jsonObject); |
| | | console.log('所有Type为0的value:', jsonString); |
| | | socket?.send(jsonString); |
| | | |
| | | } |
| | | |
| | | if (currentButtonName === 'A02翻转启动') { |
| | | const data = []; |
| | | |
| | | for (let i = 1; i < 2; i++) { |
| | | const inputData = this.jsonData[i].filter(item => item.type === '0').map(item => { |
| | | return { value: item.value }; |
| | | }); |
| | | |
| | | const values = inputData.map(item => item.value); |
| | | data.unshift([]); |
| | | data.push(values); |
| | | } |
| | | |
| | | |
| | | |
| | | const jsonObject = { data }; |
| | | |
| | | // 提交数据到后端 |
| | | const jsonString = JSON.stringify(jsonObject); |
| | | console.log('所有Type为0的value:', jsonString); |
| | | socket?.send(jsonString); |
| | | |
| | | } |
| | | |
| | | if (currentButtonName === '故障') { |
| | | |
| | | const data2 = []; |
| | | const resetButtonValues = this.jsonData.map(item => { |
| | | const buttonItem = item.find(subItem => subItem.button && subItem.button.name === '故障'); |
| | | return buttonItem ? buttonItem.button.value : null; |
| | | }).filter(value => value !== null); |
| | | |
| | | // 将得到的值添加到 data 数组中 |
| | | data2.push(...resetButtonValues); |
| | | data2.unshift([], []); |
| | | const jsonObject2 = { data2 }; |
| | | |
| | | // 提交数据到后端 |
| | | const jsonString2 = JSON.stringify(jsonObject2); |
| | | console.log('所有故障的value:', jsonString2); |
| | | socket?.send(jsonString2); |
| | | |
| | | |
| | | } |
| | | |
| | | if (currentButtonName === '复位') { |
| | | |
| | | const data2 = []; |
| | | const resetButtonValues = this.jsonData.map(item => { |
| | | const buttonItem = item.find(subItem => subItem.button && subItem.button.name === '复位'); |
| | | return buttonItem ? buttonItem.button.value : null; |
| | | }).filter(value => value !== null); |
| | | |
| | | // 将得到的值添加到 data 数组中 |
| | | data2.push(...resetButtonValues); |
| | | data2.unshift([], [], []); |
| | | const jsonObject2 = { data2 }; |
| | | |
| | | // 提交数据到后端 |
| | | const jsonString2 = JSON.stringify(jsonObject2); |
| | | console.log('所有Type为0的value:', jsonString2); |
| | | socket?.send(jsonString2); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | }, |
| | | |
| | | |
| | | initWebSocket () { |
| | | |
| | | let viewname = "ManualonePosition2"; |
| | | |
| | | if (typeof WebSocket === "undefined") { |
| | | console.log("您的浏览器不支持WebSocket"); |
| | | } else { |
| | | let socketUrl = "ws://" + "localhost:8888" + "/springboot-vue3/api/talk/" + viewname; |
| | | |
| | | if (socket != null) { |
| | | socket.close(); |
| | | socket = null; |
| | | } |
| | | |
| | | // 开启一个websocket服务 |
| | | socket = new WebSocket(socketUrl); |
| | | |
| | | // 打开事件 |
| | | socket.onopen = function () { |
| | | console.log("websocket已打开"); |
| | | }; |
| | | |
| | | // 收到消息 |
| | | socket.onmessage = (msg) => { |
| | | if (!msg.data) { |
| | | return; // 如果收到空数据,则直接返回,不执行后续逻辑 |
| | | } |
| | | |
| | | let obj = JSON.parse(msg.data); |
| | | console.log(obj) |
| | | const jsonData2 = this.jsonData; |
| | | |
| | | const handleMouseMove = throttle(function (event) { |
| | | const inputBox = document.querySelectorAll('.el-card__body'); |
| | | const target = event.target; |
| | | if (inputBox && Array.from(inputBox).every(box => !box.contains(target))) { |
| | | // 执行更新逻辑 |
| | | for (let i = 0; i < 2; i++) { |
| | | jsonData2[i].forEach((item, index) => { |
| | | if (typeof item.value !== 'undefined' && typeof obj[`zuhe${i + 1}`][0][index] !== 'undefined') { |
| | | item.value = obj[`zuhe${i + 1}`][0][index]; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | jsonData2.forEach((item) => { |
| | | item.forEach((subItem) => { |
| | | if (subItem.sending === 4) { |
| | | subItem.value = obj.shishi1[0][0]; |
| | | } |
| | | if (subItem.sending === 5) { |
| | | subItem.value = obj.shishi1[0][1]; |
| | | } |
| | | if (subItem.sending === 6) { |
| | | subItem.value = obj.shishi1[0][2]; |
| | | } |
| | | if (subItem.sending === 7) { |
| | | subItem.value = obj.shishi1[0][3]; |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | // 遍历guzhang数组 |
| | | for (let i = 0; i < obj.guzhang[0].length; i++) { |
| | | const guzhangValue = obj.guzhang[0][i]; |
| | | |
| | | // 查找jsonData2中带有"button"的对象,并且name等于"故障" |
| | | for (let j = 0; j < jsonData2.length; j++) { |
| | | const section = jsonData2[j]; |
| | | |
| | | for (let k = 0; k < section.length; k++) { |
| | | const item = section[k]; |
| | | |
| | | if (item.button && item.button.name === "故障") { |
| | | // 更新value属性 |
| | | item.button.value = guzhangValue; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | }, 200); |
| | | |
| | | document.addEventListener('mouseover', handleMouseMove); |
| | | }; |
| | | |
| | | |
| | | |
| | | |
| | | // 关闭事件 |
| | | socket.onclose = function () { |
| | | console.log("websocket已关闭"); |
| | | }; |
| | | |
| | | // 发生错误事件 |
| | | socket.onerror = function () { |
| | | console.log("websocket发生了错误"); |
| | | }; |
| | | |
| | | } |
| | | }, |
| | | send () { |
| | | |
| | | |
| | | socket?.send(JSON.stringify(this.messagepack)); |
| | | } |
| | | |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .item-row { |
| | | display: flex; |
| | | align-items: center; |
| | | margin-bottom: 2px; |
| | | /* 调整每个项目之间的间距 */ |
| | | } |
| | | |
| | | .action-button { |
| | | margin-right: 10px; |
| | | background: #66b1ff; |
| | | color: #FFF; |
| | | } |
| | | |
| | | .blue-button { |
| | | background-color: skyblue; |
| | | } |
| | | <template>
|
| | | <div class="app">
|
| | | <el-breadcrumb separator-class="el-icon-arrow-right" class="el-breadcrumb">
|
| | | <router-link to="/Electrical/alarm" tag="el-button" type="text" active-class="blue-button">{{ $t('Alarm')
|
| | | }}</router-link>
|
| | | <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State')
|
| | | }}</router-link>
|
| | | <router-link to="/Electrical/Action" tag="el-button" type="text" active-class="blue-button">{{ $t('Action')
|
| | | }}</router-link>
|
| | | <router-link to="/Electrical/Parameter" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter')
|
| | | }}</router-link>
|
| | | <router-link to="/Electrical/Sign" tag="el-button" type="text" active-class="blue-button">{{ $t('Sign')
|
| | | }}</router-link>
|
| | | <router-link to="/Electrical/Servomanual" tag="el-button" type="text" active-class="blue-button">{{
|
| | | $t('ServoManual')
|
| | | }}</router-link>
|
| | | </el-breadcrumb>
|
| | |
|
| | | <el-breadcrumb separator-class="el-icon-arrow-right" class="el-breadcrumb">
|
| | |
|
| | | <router-link to="/Electrical/Servomanualone" tag="el-button" type="text" active-class="blue-button">{{
|
| | | $t('Servomanualone')
|
| | | }}</router-link>
|
| | | <router-link to="/Electrical/Parameter1" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter1')
|
| | | }}</router-link>
|
| | | <!-- <router-link to="/Electrical/Parameter2" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter2')
|
| | | }}</router-link> -->
|
| | | <router-link to="/Electrical/Positioning1" tag="el-button" type="text" active-class="blue-button">{{
|
| | | $t('Positioning1')
|
| | | }}</router-link>
|
| | | <router-link to="/Electrical/Positioning2" tag="el-button" type="text" active-class="blue-button">{{
|
| | | $t('Positioning2')
|
| | | }}</router-link>
|
| | | <router-link to="/Electrical/ManualonePosition" tag="el-button" type="text" active-class="blue-button">{{
|
| | | $t('ManualonePosition')
|
| | | }}</router-link>
|
| | | <router-link to="/Electrical/ManualonePosition2" tag="el-button" type="text" active-class="blue-button">{{
|
| | | $t('ManualonePosition2')
|
| | | }}</router-link>
|
| | | <router-link to="/Electrical/AutomaticParameterSetting" tag="el-button" type="text" active-class="blue-button">{{
|
| | | $t('AutomaticParameterSetting')
|
| | | }}</router-link>
|
| | | <router-link to="/Electrical/ManualJog" tag="el-button" type="text" active-class="blue-button">{{
|
| | | $t('ManualJog')
|
| | | }}</router-link>
|
| | | </el-breadcrumb>
|
| | |
|
| | | <el-row :gutter="20">
|
| | | <el-col :span="12" v-for="(dataGroup, groupIndex) in jsonData" :key="groupIndex">
|
| | | <el-card class="json-block" style="width:485px;">
|
| | | <div v-for="(item, itemIndex) in dataGroup" :key="itemIndex" class="item-container">
|
| | | <div class="item-row">
|
| | | <span class="name" style="width:100px;">{{ item.name }}</span>
|
| | | <el-input style="width:250px;" v-if="item.state != 0 && item.type === '0'" v-model="item.value"
|
| | | class="input-box"></el-input>
|
| | | </div>
|
| | | </div>
|
| | | <div class="button-row" style="display: flex; justify-content: space-between;">
|
| | | <div v-for="(item, itemIndex) in dataGroup" :key="itemIndex">
|
| | | <el-button v-if="item.button && item.button.state != 0" :name="item.button.name" v-model="item.button.value"
|
| | | :class="{ 'action-button': true, 'error-button': item.button.name === '故障' && item.button.value === 1 }"
|
| | | @click="updateButtonValue(dataGroup, itemIndex); submitDataToBackend(item.button.name);">{{
|
| | | item.button.name }}</el-button>
|
| | | </div>
|
| | | </div>
|
| | | </el-card>
|
| | | </el-col>
|
| | | </el-row>
|
| | | <!-- <el-button @click="submitDataToBackend">提交数据到后端</el-button> -->
|
| | | </div>
|
| | | </template>
|
| | |
|
| | | <script>
|
| | | import LanguageMixin from '../../lang/LanguageMixin'
|
| | | import data from '../../configuration/Manualoneposition2'
|
| | | import { throttle } from 'lodash';
|
| | | let socket;
|
| | | export default {
|
| | | name: "ManualonePosition2",
|
| | | mixins: [LanguageMixin],
|
| | | data () {
|
| | | return {
|
| | | jsonData: data // 加载整个data.json文件作为jsonData
|
| | | }
|
| | | },
|
| | | created () {
|
| | | this.initWebSocket();
|
| | | // console.log('jsonData:', this.jsonData); |
| | |
|
| | | },
|
| | | methods: {
|
| | | updateButtonValue (dataGroup, itemIndex) {
|
| | | // 将当前按钮的值设为1
|
| | |
|
| | | this.$set(dataGroup[itemIndex].button, 'value', 1);
|
| | |
|
| | |
|
| | |
|
| | | },
|
| | | submitDataToBackend (currentButtonName) {
|
| | | if (currentButtonName === 'A01翻转启动') {
|
| | | const data = [];
|
| | |
|
| | | for (let i = 0; i < 1; i++) {
|
| | | const inputData = this.jsonData[i].filter(item => item.type === '0').map(item => {
|
| | | return { value: item.value };
|
| | | });
|
| | |
|
| | | const values = inputData.map(item => item.value);
|
| | |
|
| | | data.push(values);
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | const jsonObject = { data };
|
| | |
|
| | | // 提交数据到后端
|
| | | const jsonString = JSON.stringify(jsonObject);
|
| | | console.log('所有Type为0的value:', jsonString);
|
| | | socket?.send(jsonString);
|
| | |
|
| | | }
|
| | |
|
| | | if (currentButtonName === 'A02翻转启动') {
|
| | | const data = [];
|
| | |
|
| | | for (let i = 1; i < 2; i++) {
|
| | | const inputData = this.jsonData[i].filter(item => item.type === '0').map(item => {
|
| | | return { value: item.value };
|
| | | });
|
| | |
|
| | | const values = inputData.map(item => item.value);
|
| | | data.unshift([]);
|
| | | data.push(values);
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | const jsonObject = { data };
|
| | |
|
| | | // 提交数据到后端
|
| | | const jsonString = JSON.stringify(jsonObject);
|
| | | console.log('所有Type为0的value:', jsonString);
|
| | | socket?.send(jsonString);
|
| | |
|
| | | }
|
| | |
|
| | | if (currentButtonName === '故障') {
|
| | |
|
| | | const data2 = [];
|
| | | const resetButtonValues = this.jsonData.map(item => {
|
| | | const buttonItem = item.find(subItem => subItem.button && subItem.button.name === '故障');
|
| | | return buttonItem ? buttonItem.button.value : null;
|
| | | }).filter(value => value !== null);
|
| | |
|
| | | // 将得到的值添加到 data 数组中
|
| | | data2.push(...resetButtonValues);
|
| | | data2.unshift([], []);
|
| | | const jsonObject2 = { data2 };
|
| | |
|
| | | // 提交数据到后端
|
| | | const jsonString2 = JSON.stringify(jsonObject2);
|
| | | console.log('所有故障的value:', jsonString2);
|
| | | socket?.send(jsonString2);
|
| | |
|
| | |
|
| | | }
|
| | |
|
| | | if (currentButtonName === '复位') {
|
| | |
|
| | | const data2 = [];
|
| | | const resetButtonValues = this.jsonData.map(item => {
|
| | | const buttonItem = item.find(subItem => subItem.button && subItem.button.name === '复位');
|
| | | return buttonItem ? buttonItem.button.value : null;
|
| | | }).filter(value => value !== null);
|
| | |
|
| | | // 将得到的值添加到 data 数组中
|
| | | data2.push(...resetButtonValues);
|
| | | data2.unshift([], [], []);
|
| | | const jsonObject2 = { data2 };
|
| | |
|
| | | // 提交数据到后端
|
| | | const jsonString2 = JSON.stringify(jsonObject2);
|
| | | console.log('所有Type为0的value:', jsonString2);
|
| | | socket?.send(jsonString2);
|
| | |
|
| | |
|
| | | }
|
| | |
|
| | | if (currentButtonName === '回零') {
|
| | |
|
| | | const data2 = [];
|
| | | const resetButtonValues = this.jsonData.map(item => {
|
| | | const buttonItem = item.find(subItem => subItem.button && subItem.button.name === '回零');
|
| | | return buttonItem ? buttonItem.button.value : null;
|
| | | }).filter(value => value !== null);
|
| | |
|
| | | // 将得到的值添加到 data 数组中
|
| | | data2.push(...resetButtonValues);
|
| | | data2.unshift([], [], [], []);
|
| | | const jsonObject2 = { data2 };
|
| | |
|
| | | // 提交数据到后端
|
| | | const jsonString2 = JSON.stringify(jsonObject2);
|
| | | console.log('所有Type为0的value:', jsonString2);
|
| | | socket?.send(jsonString2);
|
| | |
|
| | |
|
| | | }
|
| | |
|
| | |
|
| | | },
|
| | |
|
| | |
|
| | | initWebSocket () {
|
| | |
|
| | | let viewname = "ManualonePosition2";
|
| | |
|
| | | if (typeof WebSocket === "undefined") {
|
| | | console.log("您的浏览器不支持WebSocket");
|
| | | } else {
|
| | | let socketUrl = "ws://" + "localhost:8888" + "/springboot-vue3/api/talk/" + viewname;
|
| | |
|
| | | if (socket != null) {
|
| | | socket.close();
|
| | | socket = null;
|
| | | }
|
| | |
|
| | | // 开启一个websocket服务
|
| | | socket = new WebSocket(socketUrl);
|
| | |
|
| | | // 打开事件
|
| | | socket.onopen = function () {
|
| | | console.log("websocket已打开");
|
| | | };
|
| | |
|
| | | // 收到消息
|
| | | socket.onmessage = (msg) => {
|
| | | if (!msg.data) {
|
| | | return; // 如果收到空数据,则直接返回,不执行后续逻辑
|
| | | }
|
| | |
|
| | | let obj = JSON.parse(msg.data);
|
| | | // console.log(obj)
|
| | | const jsonData2 = this.jsonData;
|
| | |
|
| | | const handleMouseMove = throttle(function (event) {
|
| | | const inputBox = document.querySelectorAll('.el-card__body');
|
| | | const target = event.target;
|
| | | if (inputBox && Array.from(inputBox).every(box => !box.contains(target))) {
|
| | | // 执行更新逻辑
|
| | | for (let i = 0; i < 2; i++) {
|
| | | jsonData2[i].forEach((item, index) => {
|
| | | if (typeof item.value !== 'undefined' && typeof obj[`zuhe${i + 1}`][0][index] !== 'undefined') {
|
| | | item.value = obj[`zuhe${i + 1}`][0][index];
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | jsonData2.forEach((item) => {
|
| | | item.forEach((subItem) => {
|
| | | if (subItem.sending === 4) {
|
| | | subItem.value = obj.shishi1[0][0];
|
| | | }
|
| | | if (subItem.sending === 5) {
|
| | | subItem.value = obj.shishi1[0][1];
|
| | | }
|
| | | if (subItem.sending === 6) {
|
| | | subItem.value = obj.shishi1[0][2];
|
| | | }
|
| | | if (subItem.sending === 7) {
|
| | | subItem.value = obj.shishi1[0][3];
|
| | | }
|
| | | });
|
| | | });
|
| | |
|
| | | // 遍历guzhang数组
|
| | | for (let i = 0; i < obj.guzhang[0].length; i++) {
|
| | | const guzhangValue = obj.guzhang[0][i];
|
| | |
|
| | | // 查找jsonData2中带有"button"的对象,并且name等于"故障"
|
| | | for (let j = 0; j < jsonData2.length; j++) {
|
| | | const section = jsonData2[j];
|
| | |
|
| | | for (let k = 0; k < section.length; k++) {
|
| | | const item = section[k];
|
| | |
|
| | | if (item.button && item.button.name === "故障") {
|
| | | // 更新value属性
|
| | | item.button.value = guzhangValue;
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | |
|
| | | }
|
| | | }, 200);
|
| | |
|
| | | document.addEventListener('mouseover', handleMouseMove);
|
| | | };
|
| | |
|
| | |
|
| | |
|
| | |
|
| | | // 关闭事件
|
| | | socket.onclose = function () {
|
| | | console.log("websocket已关闭");
|
| | | };
|
| | |
|
| | | // 发生错误事件
|
| | | socket.onerror = function () {
|
| | | console.log("websocket发生了错误");
|
| | | };
|
| | |
|
| | | }
|
| | | },
|
| | | send () {
|
| | |
|
| | |
|
| | | socket?.send(JSON.stringify(this.messagepack));
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | </script>
|
| | |
|
| | | <style scoped>
|
| | | .item-row {
|
| | | display: flex;
|
| | | align-items: center;
|
| | | margin-bottom: 2px;
|
| | | /* 调整每个项目之间的间距 */
|
| | | }
|
| | |
|
| | | .action-button {
|
| | | margin-right: 10px;
|
| | | background: #66b1ff;
|
| | | color: #FFF;
|
| | | }
|
| | |
|
| | | .blue-button {
|
| | | background-color: skyblue;
|
| | | }
|
| | | </style> |
| | |
| | | }}</router-link>
|
| | | <router-link to="/Electrical/Sign" tag="el-button" type="text" active-class="blue-button">{{ $t('Sign')
|
| | | }}</router-link>
|
| | | <router-link to="/Electrical/Servomanual" tag="el-button" type="text" active-class="blue-button">{{
|
| | | $t('ServoManual')
|
| | | }}</router-link>
|
| | | <router-link to="/Electrical/Servomanual" tag="el-button" type="text" active-class="blue-button">{{ $t('Servo Manual')
|
| | | }}</router-link>
|
| | | </el-breadcrumb>
|
| | |
|
| | | <div>Parameter</div>
|
| | |
|
| | | <el-form label-width="100px" style="display: flex; flex-wrap: wrap;" :model="messagepack.data">
|
| | | <div id="btn_div">
|
| | | <el-button type="primary" @click="send()" id="xiafa" :disabled="isButtonDisabled">{{ $t('Distribute parameters')
|
| | | }}</el-button>
|
| | | <!-- <el-button type="primary" @click="send()" id="xiafa" :disabled="isButtonDisabled">{{ $t('Distribute parameters')
|
| | | }}</el-button> -->
|
| | |
|
| | | </div>
|
| | | <div class="kuai_div" v-for="(item, index) in record.xyData" :key="index">
|
| | | <div class="kuai_div" v-for="(item, index) in jsonData" :key="index">
|
| | | <el-input style="width: 280px; border:none;" class="in_mc" v-model="item.name" readonly></el-input>
|
| | |
|
| | | <span style="margin-right: 5px; width: 50px;">{{ item.value }}</span>
|
| | | <span style="margin-right: 5px; font-size: 14px;color: red;">|</span>
|
| | | <input type="number" style="width: 43px; margin-right: 5px; margin-top: 5px; font-size: 16px;">
|
| | | <span style="margin-right: 5px; width: 50px;">{{ item.unit }}</span>
|
| | | <!-- <span style="margin-right: 5px; width: 50px;">{{ item.value }}</span> -->
|
| | | <!-- <span style="margin-right: 5px; font-size: 14px;color: red;">|</span> -->
|
| | | <el-input v-model="item.value" type="number"
|
| | | style="width: 143px; margin-right: 5px; margin-top: 5px; font-size: 16px;border:none" class="input-box"
|
| | | @keyup.enter.native="send"></el-input>
|
| | | <span style="margin-right: 5px; width: 50px;" >{{ item.unit }}</span>
|
| | |
|
| | | </div>
|
| | | </el-form>
|
| | |
| | | let socket;
|
| | | import LanguageMixin from '../../lang/LanguageMixin'
|
| | | import data from '../../configuration/Parameter'
|
| | | import { throttle } from 'lodash';
|
| | | export default {
|
| | | name: "Parameter",
|
| | | mixins: [LanguageMixin],
|
| | | data () {
|
| | | return {
|
| | | jsonData: data,
|
| | | |
| | | dialogVisible: true,
|
| | | password: '',
|
| | | activeButton: '',
|
| | | record: {
|
| | | params: [100, 200, 10, 10, 10, 10],
|
| | | xyData: [
|
| | |
|
| | | ],
|
| | | canshu: []
|
| | | },
|
| | | |
| | | messagepack: {
|
| | | data: { taskname: "" }
|
| | | },
|
| | |
| | | this.initWebSocket();
|
| | | this.isButtonDisabled = true;
|
| | |
|
| | |
|
| | | },
|
| | | methods: {
|
| | | showdata () {
|
| | | |
| | |
|
| | | },
|
| | |
|
| | |
|
| | | setActiveButton (buttonName) {
|
| | |
| | | }
|
| | |
|
| | | let obj = JSON.parse(msg.data);
|
| | |
|
| | |
|
| | | // console.log(obj);
|
| | | const jsonData2=this.jsonData;
|
| | | // console.log(jsonData2);
|
| | | const handleMouseMove = throttle(function (event) {
|
| | | const inputBox = document.querySelectorAll('.input-box');
|
| | | const target = event.target;
|
| | | if (inputBox && Array.from(inputBox).every(box => !box.contains(target))) {
|
| | | if (obj.params && obj.state) {
|
| | |
|
| | |
|
| | | this.record.params[0] = obj.params[0];
|
| | | this.record.state = obj.state[0];
|
| | | |
| | | if (obj.state && obj.state.length > 0) {
|
| | | let isButtonDisabled = this.record.state.includes(1);
|
| | | this.isButtonDisabled = isButtonDisabled;
|
| | |
|
| | | // console.log( Array.isArray(jsonData2));
|
| | | |
| | | |
| | | // 将 obj 中的 params 值更新到 jsonData 中的 value 中
|
| | | for (let i = 0; i < obj.params[0].length; i++) {
|
| | | jsonData2[i].value = obj.params[0][i];
|
| | | }
|
| | |
|
| | |
|
| | | this.record.xyData = this.jsonData.para;
|
| | |
|
| | | for (let a = 0; a < this.record.xyData.length; a++) {
|
| | | this.record.xyData[a].value = this.record.params[0][a];
|
| | |
|
| | | }
|
| | |
|
| | | this.record.xyData = this.jsonData.para.filter(item => {
|
| | | return item.state != 0;
|
| | | }
|
| | |
|
| | | );
|
| | | const language = this.$i18n.locale;
|
| | | if (language === 'en-US') {
|
| | | this.replaceChineseWithEnglish();
|
| | | } else {
|
| | | this.localizedRoles = [...this.record.xyData];
|
| | | }
|
| | | |
| | | |
| | | }
|
| | | }
|
| | | this.$forceUpdate();
|
| | | this.replaceChineseWithEnglish();
|
| | | };
|
| | | // this.$forceUpdate();
|
| | | // this.replaceChineseWithEnglish();
|
| | | }
|
| | | }, 200);
|
| | |
|
| | | document.addEventListener('mouseover', handleMouseMove);
|
| | | |
| | | };
|
| | |
|
| | | // 关闭事件
|
| | | socket.onclose = function () {
|
| | |
| | | }
|
| | | },
|
| | | send () {
|
| | | this.messagepack.data = this.record.xyData.map((item) => parseInt(item.value2)); // 转换为整数数组
|
| | | //console.log(this.messagepack);
|
| | | this.messagepack.data = this.jsonData.map((item) => parseInt(item.value)); // 转换为整数数组
|
| | | console.log(this.messagepack);
|
| | | socket?.send(JSON.stringify(this.messagepack));
|
| | | },
|
| | | handleChange (index, value) {
|
| | |
| | | //语言转换
|
| | | replaceChineseWithEnglish () {
|
| | | const translation = this.$t('langparameter');
|
| | | this.record.xyData = this.record.xyData.map(item => { return { name: translation[item.name] || item.name, value: item.value, unit: item.unit }; });
|
| | | this.jsonData.para = this.jsonData.para.map(item => { return { name: translation[item.name] || item.name, value: item.value, unit: item.unit }; });
|
| | | //console.log(translation);
|
| | | },
|
| | | }
|
| | |
| | | border: 1px solid black;
|
| | | border: none;
|
| | | }
|
| | | .special-class{
|
| | |
|
| | | .special-class {}
|
| | |
|
| | | }
|
| | |
|
| | | .in_mc {
|
| | |
|
| | |
| | | import data from '../../configuration/parameter2' |
| | | let socket; |
| | | export default { |
| | | destroyed() { |
| | | socket.close(); |
| | | }, |
| | | name: "Parameter2", |
| | | mixins: [LanguageMixin], |
| | | data() { |
| | |
| | | socket.onerror = function () { |
| | | console.log("websocket发生了错误"); |
| | | }; |
| | | |
| | | |
| | | } |
| | | }, |
| | |
| | | background-color: red; |
| | | } |
| | | .yellow-button{ |
| | | background-color: yellow; |
| | | background-color: blue; |
| | | } |
| | | |
| | | </style> |
| | |
| | | import LanguageMixin from '../../lang/LanguageMixin' |
| | | import data from '../../configuration/ServoManualone' |
| | | import { throttle } from 'lodash'; |
| | | |
| | | let socket; |
| | | export default { |
| | | name: "ServoManualone", |
| | | mixins: [LanguageMixin], |
| | | |
| | | data() { |
| | | return { |
| | | jsonData: data , |
| | |
| | | // console.log('jsonData:', this.jsonData); |
| | | |
| | | }, |
| | | |
| | | methods: { |
| | | |
| | | |
| | | updateButtonValue(dataGroup, itemIndex) { |
| | | // 将当前按钮的值设为1 |
| | |
| | | } |
| | | |
| | | let obj = JSON.parse(msg.data); |
| | | // console.log(obj) |
| | | console.log(obj) |
| | | const jsonData2 = this.jsonData; |
| | | |
| | | const handleMouseMove = throttle(function(event) { |
New file |
| | |
| | | package com.example.springboot.component;
|
| | |
|
| | | import cn.hutool.json.JSONArray;
|
| | | import cn.hutool.json.JSONObject;
|
| | | import org.apache.commons.io.FileUtils;
|
| | |
|
| | | import java.io.*;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.List;
|
| | |
|
| | | public class PLCManualJog extends Thread {
|
| | | String name = "";
|
| | | Integer count = 0;
|
| | |
|
| | | public static String readFileToString(String filePath) throws IOException {
|
| | | File file = new File(filePath);
|
| | | return FileUtils.readFileToString(file, "UTF-8");
|
| | | }
|
| | |
|
| | | public void readValue() {
|
| | | String str = "";
|
| | | BufferedReader bufferedReader = null;
|
| | | FileInputStream fileInputStream;
|
| | | try {
|
| | | // 从文件中读取字节数据存入 fileInputStream
|
| | | fileInputStream = new FileInputStream("CanadaMes-ui/src/configuration/address.json");
|
| | | // 读取 fileInputStream 中字节并将其解码为字符
|
| | | InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "utf-8");
|
| | | // 提高读取效率,在 BufferedReader 内包装 InputStreamReader
|
| | | bufferedReader = new BufferedReader(inputStreamReader);
|
| | | String line = null;
|
| | | // 将 bufferedReader 内容一行一行赋值给str
|
| | | while ((line = bufferedReader.readLine()) != null) {
|
| | | str += line;
|
| | | }
|
| | |
|
| | | // 将str字符串格式转为json
|
| | | JSONObject jsonObject = new JSONObject(str);
|
| | |
|
| | | // 获取json中的值
|
| | | JSONArray address = jsonObject.getJSONArray("address");
|
| | | for (int i = 0; i < address.size(); i++) {
|
| | | JSONObject ress = (JSONObject) address.get(i);
|
| | |
|
| | | this.name = ress.getStr("name");
|
| | | this.count = ress.getInt("count");
|
| | |
|
| | | }
|
| | |
|
| | | } catch (FileNotFoundException e) {
|
| | | e.printStackTrace();
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void run() {
|
| | | while (this != null) {
|
| | | try {
|
| | | Thread.sleep(500);
|
| | |
|
| | | } catch (InterruptedException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | // this.readValue();
|
| | | // String PlcAddress = this.name;
|
| | | // Integer Plccount = this.count;
|
| | |
|
| | | // System.out.println(stt);
|
| | | List<Boolean> arraylist = S7control.getinstance().ReadBits("DB101.0.0", 16);
|
| | | List<Boolean> arraylist2 = S7control.getinstance().ReadBits("DB101.2.6", 8);
|
| | | List<Boolean> arraylist3 = S7control.getinstance().ReadBits("DB101.5.2", 2);
|
| | | // Boolean[] values1 = { false, true, true, true, false, false, true, false,
|
| | | // false, true, true, true, false, false,
|
| | | // true, false };
|
| | | // List<Boolean> arraylist = new ArrayList<>(Arrays.asList(values1));
|
| | | // Boolean[] values2 = { false, true, true, true, false, false, true, false };
|
| | | // List<Boolean> arraylist2 = new ArrayList<>(Arrays.asList(values2));
|
| | | // Boolean[] values3 = { false, false };
|
| | | // List<Boolean> arraylist3 = new ArrayList<>(Arrays.asList(values3));
|
| | |
|
| | | arraylist.addAll(arraylist2);
|
| | | arraylist.addAll(arraylist3);
|
| | |
|
| | | JSONObject jsonObject = new JSONObject();
|
| | |
|
| | | short[] params = new short[arraylist.size()];
|
| | | for (int i = 0; i < arraylist.size(); i++) {
|
| | | boolean value = arraylist.get(i);
|
| | | params[i] = value ? (short) 1 : (short) 0;
|
| | | }
|
| | |
|
| | | jsonObject.append("params", params);
|
| | |
|
| | | WebSocketServer sendwServer = WebSocketServer.sessionMap.get("ManualJog");
|
| | | if (sendwServer != null) {
|
| | | sendwServer.sendMessage(jsonObject.toString());
|
| | | }
|
| | |
|
| | | WebSocketServer webSocketServer = WebSocketServer.sessionMap.get("ManualJog");
|
| | |
|
| | | if (webSocketServer != null) {
|
| | | String addressList1 = "DB101.0.0";
|
| | | String addressList2 = "DB101.2.6";
|
| | | String addressList3 = "DB101.5.2";
|
| | |
|
| | | List<String> messages = webSocketServer.getMessages();
|
| | | if (!messages.isEmpty()) {
|
| | | // 将最后一个消息转换为整数类型的列表
|
| | | String lastMessage = messages.get(messages.size() - 1);
|
| | | // System.out.println("messages:" + messages);
|
| | | String[] parts = lastMessage.split(",");
|
| | | List<Integer> messageValues = new ArrayList<>();
|
| | | for (String part : parts) {
|
| | | try {
|
| | | // 使用正则表达式清除非数字字符
|
| | | String cleanedPart = part.replaceAll("[^0-9-]", "");
|
| | | Integer value = Integer.parseInt(cleanedPart.trim());
|
| | | messageValues.add(value);
|
| | | } catch (NumberFormatException e) {
|
| | | // 如果无法解析为整数类型,则忽略该部分
|
| | | // e.printStackTrace();
|
| | | }
|
| | |
|
| | | }
|
| | | // 将消息值转换为布尔列表
|
| | | List<Boolean> messageBooleans = new ArrayList<>();
|
| | | for (Integer value : messageValues) {
|
| | | messageBooleans.add(value == 1 ? true : false);
|
| | | }
|
| | | // System.out.println(messageBooleans);
|
| | | List<Boolean> bolList = new ArrayList<>();
|
| | | List<Boolean> bolList2 = new ArrayList<>();
|
| | | List<Boolean> bolList3 = new ArrayList<>();
|
| | |
|
| | | for (int i = 0; i < 16 && i < messageBooleans.size(); i++) {
|
| | | bolList.add(messageBooleans.get(i));
|
| | | }
|
| | |
|
| | | for (int i = 16; i < 24 && i < messageBooleans.size(); i++) {
|
| | | bolList2.add(messageBooleans.get(i));
|
| | | }
|
| | |
|
| | | for (int i = 24; i < 26 && i < messageBooleans.size(); i++) {
|
| | | bolList3.add(messageBooleans.get(i));
|
| | | }
|
| | |
|
| | | // System.out.println(bolList);
|
| | | // System.out.println(bolList2);
|
| | | // System.out.println(bolList3);
|
| | | if (!bolList.isEmpty()) {
|
| | | S7control.getinstance().WriteBit(addressList1, bolList);
|
| | | System.out.println("messageValue:" + bolList + " written to PLC at address " + addressList1);
|
| | | }
|
| | | if (!bolList2.isEmpty()) {
|
| | | S7control.getinstance().WriteBit(addressList2, bolList2);
|
| | | System.out.println("messageValue:" + bolList2 + " written to PLC at address " + addressList2);
|
| | | }
|
| | | if (!bolList3.isEmpty()) {
|
| | | S7control.getinstance().WriteBit(addressList3, bolList3);
|
| | | System.out.println("messageValue:" + bolList3 + " written to PLC at address " + addressList3);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | JSONObject jsonObject = new JSONObject(str); |
| | | |
| | | // 获取json中的值 |
| | | JSONArray address = jsonObject.getJSONArray("ServoManualone"); |
| | | JSONArray address = jsonObject.getJSONArray("ManualonePosition"); |
| | | for (int i = 0; i < address.size(); i++) { |
| | | JSONObject ress = (JSONObject) address.get(i); |
| | | |
| | |
| | | addresses.add("DB100.20"); |
| | | addresses.add("DB103.52"); |
| | | List<Short> arraylist = S7control.getinstance().readWords(addresses); |
| | | // System.out.println(arraylist); |
| | | // System.out.println(arraylist); |
| | | |
| | | List<String> addresses2 = new ArrayList<>(); |
| | | addresses2.add("DB100.110"); |
| | |
| | | List<Short> arraylist7 = S7control.getinstance().ReadWord("DB103.48", 1); |
| | | List<Short> arraylist8 = S7control.getinstance().ReadWord("DB103.50", 1); |
| | | List<String> addresses9 = new ArrayList<>(); |
| | | addresses9.add("DB104.24"); |
| | | addresses9.add("DB104.26"); |
| | | addresses9.add("DB104.20"); |
| | | addresses9.add("DB104.22"); |
| | | addresses9.add("DB104.28"); |
| | | addresses9.add("DB104.30"); |
| | | List<Short> arraylist9 = S7control.getinstance().readWords(addresses9); |
| | | addresses9.add("DB104.1.2"); |
| | | addresses9.add("DB104.1.3"); |
| | | addresses9.add("DB104.1.6"); |
| | | addresses9.add("DB104.1.7"); |
| | | // addresses9.add("DB104.28"); |
| | | // addresses9.add("DB104.30"); |
| | | List<Boolean> arraylist9 = S7control.getinstance().readBits(addresses9); |
| | | short[] params2 = new short[arraylist9.size()]; |
| | | for (int i = 0; i < arraylist9.size(); i++) { |
| | | boolean value = arraylist9.get(i); |
| | | params2[i] = value ? (short) 1 : (short) 0; |
| | | } |
| | | // List<Short> arraylist9 = S7control.getinstance().readWords(addresses9); |
| | | arraylist5.addAll(arraylist6); |
| | | arraylist5.addAll(arraylist7); |
| | | arraylist5.addAll(arraylist8); |
| | |
| | | jsonObject.append("zuhe3", arraylist3); |
| | | jsonObject.append("zuhe4", arraylist4); |
| | | jsonObject.append("shishi1", arraylist5); |
| | | jsonObject.append("guzhang", arraylist9); |
| | | jsonObject.append("guzhang", params2); |
| | | // jsonObject.append("weihuiling", arraylist8); |
| | | |
| | | WebSocketServer sendwServer = WebSocketServer.sessionMap.get("ManualonePosition"); |
New file |
| | |
| | | package com.example.springboot.component;
|
| | |
|
| | | import cn.hutool.json.JSONArray;
|
| | | import cn.hutool.json.JSONObject;
|
| | | import org.apache.commons.io.FileUtils;
|
| | |
|
| | | import java.io.*;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.List;
|
| | |
|
| | | public class PlcManualonePosition2 extends Thread {
|
| | | String name = "";
|
| | | Integer count = 0;
|
| | |
|
| | | public static String readFileToString(String filePath) throws IOException {
|
| | | File file = new File(filePath);
|
| | | return FileUtils.readFileToString(file, "UTF-8");
|
| | | }
|
| | |
|
| | | public void readValue() {
|
| | | String str = "";
|
| | | BufferedReader bufferedReader = null;
|
| | | FileInputStream fileInputStream;
|
| | | try {
|
| | | // 从文件中读取字节数据存入 fileInputStream
|
| | | fileInputStream = new FileInputStream("CanadaMes-ui/src/configuration/address.json");
|
| | | // 读取 fileInputStream 中字节并将其解码为字符
|
| | | InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "utf-8");
|
| | | // 提高读取效率,在 BufferedReader 内包装 InputStreamReader
|
| | | bufferedReader = new BufferedReader(inputStreamReader);
|
| | | String line = null;
|
| | | // 将 bufferedReader 内容一行一行赋值给str
|
| | | while ((line = bufferedReader.readLine()) != null) {
|
| | | str += line;
|
| | | }
|
| | |
|
| | | // 将str字符串格式转为json
|
| | | JSONObject jsonObject = new JSONObject(str);
|
| | |
|
| | | // 获取json中的值
|
| | | JSONArray address = jsonObject.getJSONArray("ServoManualone");
|
| | | for (int i = 0; i < address.size(); i++) {
|
| | | JSONObject ress = (JSONObject) address.get(i);
|
| | |
|
| | | this.name = ress.getStr("name");
|
| | | this.count = ress.getInt("count");
|
| | |
|
| | | }
|
| | |
|
| | | } catch (FileNotFoundException e) {
|
| | | e.printStackTrace();
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void run() {
|
| | | while (this != null) {
|
| | | try {
|
| | | Thread.sleep(500);
|
| | |
|
| | | } catch (InterruptedException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | // this.readValue();
|
| | | // String PlcAddress = this.name;
|
| | | // Integer Plccount = this.count;
|
| | |
|
| | | List<String> addresses = new ArrayList<>();
|
| | | addresses.add("DB100.16");
|
| | | addresses.add("DB100.116");
|
| | | addresses.add("DB103.20");
|
| | | List<Short> arraylist = S7control.getinstance().readWords(addresses);
|
| | | // System.out.println(arraylist);
|
| | |
|
| | | List<String> addresses2 = new ArrayList<>();
|
| | | addresses2.add("DB100.192");
|
| | | addresses2.add("DB100.118");
|
| | | addresses2.add("DB103.22");
|
| | | List<Short> arraylist2 = S7control.getinstance().readWords(addresses2);
|
| | |
|
| | | List<String> addresses9 = new ArrayList<>();
|
| | |
|
| | |
|
| | |
|
| | | addresses9.add("DB104.1.2");
|
| | | addresses9.add("DB104.1.3");
|
| | | List<Boolean> arraylist9 = S7control.getinstance().readBits(addresses9);
|
| | | short[] params2 = new short[arraylist9.size()];
|
| | | for (int i = 0; i < arraylist9.size(); i++) {
|
| | | boolean value = arraylist9.get(i);
|
| | | params2[i] = value ? (short) 1 : (short) 0;
|
| | | }
|
| | |
|
| | | JSONObject jsonObject = new JSONObject();
|
| | | // System.out.println(arraylist);
|
| | | jsonObject.append("zuhe1", arraylist);
|
| | | jsonObject.append("zuhe2", arraylist2);
|
| | | jsonObject.append("guzhang", params2);
|
| | | // jsonObject.append("weihuiling", arraylist8);
|
| | |
|
| | | WebSocketServer sendwServer = WebSocketServer.sessionMap.get("ManualonePosition2");
|
| | | if (sendwServer != null) {
|
| | | sendwServer.sendMessage(jsonObject.toString());
|
| | | }
|
| | |
|
| | | WebSocketServer webSocketServer = WebSocketServer.sessionMap.get("ManualonePosition2");
|
| | | if (webSocketServer != null) {
|
| | | List<String> messages = webSocketServer.getMessages();
|
| | | List<String> waddresses1 = new ArrayList<>();
|
| | | waddresses1.add("DB100.108");
|
| | | waddresses1.add("DB100.20");
|
| | | waddresses1.add("DB103.52");
|
| | |
|
| | | List<String> waddresses2 = new ArrayList<>();
|
| | | waddresses2.add("DB100.110");
|
| | | waddresses2.add("DB100.176");
|
| | | waddresses2.add("DB103.54");
|
| | |
|
| | | // 故障地址
|
| | | List<String> waddresses3 = new ArrayList<>();
|
| | | waddresses3.add("DB103.242");
|
| | | waddresses3.add("DB103.248");
|
| | |
|
| | | // 复位地址
|
| | | List<String> waddresses4 = new ArrayList<>();
|
| | | waddresses4.add("DB101.3.6");
|
| | | waddresses4.add("DB101.4.1");
|
| | |
|
| | | // 回零地址
|
| | | List<String> waddresses5 = new ArrayList<>();
|
| | | waddresses5.add("DB101.3.7");
|
| | | waddresses5.add("DB101.4.2");
|
| | |
|
| | | if (!messages.isEmpty()) {
|
| | | // 将最后一个消息转换为 short 类型的列表
|
| | | String lastMessage = messages.get(messages.size() - 1);
|
| | | // System.out.println("lastMessage:" + lastMessage);
|
| | | JSONArray messageArray = new JSONArray(lastMessage);
|
| | |
|
| | | // A01下发
|
| | | if (messageArray.getJSONArray(0).size() > 0) {
|
| | | JSONArray jsonArray = messageArray.getJSONArray(0);
|
| | | List<Short> sValue = new ArrayList<>();
|
| | | for (int i = 0; i < jsonArray.size(); i++) {
|
| | | Object value = jsonArray.get(i);
|
| | | if (value != null && !value.toString().equals("null")) {
|
| | | try {
|
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", "");
|
| | | short val = Short.parseShort(cleanedValue.trim());
|
| | | sValue.add(val);
|
| | | System.out.println("messageValue:" + Arrays.asList(val) + " added to the list");
|
| | | } catch (NumberFormatException e) {
|
| | | // 如果无法解析为 short 类型,则忽略该部分
|
| | | System.err.println("Could not parse value: " + value);
|
| | | }
|
| | | }
|
| | | }
|
| | | if (!sValue.isEmpty()) {
|
| | | S7control.getinstance().WriteWord(waddresses1, sValue);
|
| | | System.out.println("Values " + sValue + " written to PLC at address " + waddresses1);
|
| | | }
|
| | | }
|
| | |
|
| | | // A02下发
|
| | | if (messageArray.getJSONArray(1).size() > 0) {
|
| | | JSONArray jsonArray = messageArray.getJSONArray(1);
|
| | | List<Short> sValue2 = new ArrayList<>();
|
| | | for (int i = 0; i < jsonArray.size(); i++) {
|
| | | Object value = jsonArray.get(i);
|
| | | if (value != null && !value.toString().equals("null")) {
|
| | | try {
|
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", "");
|
| | | short val = Short.parseShort(cleanedValue.trim());
|
| | | sValue2.add(val);
|
| | | System.out.println("messageValue:" + Arrays.asList(val) + " added to the list");
|
| | | } catch (NumberFormatException e) {
|
| | | // 如果无法解析为 short 类型,则忽略该部分
|
| | | System.err.println("Could not parse value: " + value);
|
| | | }
|
| | | }
|
| | | }
|
| | | if (!sValue2.isEmpty()) {
|
| | | S7control.getinstance().WriteWord(waddresses2, sValue2);
|
| | | System.out.println("Values " + sValue2 + " written to PLC at address " + waddresses2);
|
| | | }
|
| | | }
|
| | |
|
| | | // 写入故障地址
|
| | | if (messageArray.getJSONArray(2).size() > 0) {
|
| | | JSONArray jsonArray = messageArray.getJSONArray(2);
|
| | | List<Short> sValue2 = new ArrayList<>();
|
| | | for (int i = 0; i < jsonArray.size(); i++) {
|
| | | Object value = jsonArray.get(i);
|
| | | if (value != null && !value.toString().equals("null")) {
|
| | | try {
|
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", "");
|
| | | short val = Short.parseShort(cleanedValue.trim());
|
| | | sValue2.add(val);
|
| | | System.out.println("messageValue:" + Arrays.asList(val) + " added to the list");
|
| | | } catch (NumberFormatException e) {
|
| | | // 如果无法解析为 short 类型,则忽略该部分
|
| | | System.err.println("Could not parse value: " + value);
|
| | | }
|
| | | }
|
| | | }
|
| | | if (!sValue2.isEmpty()) {
|
| | | S7control.getinstance().WriteWord(waddresses3, sValue2);
|
| | | System.out.println("Values " + sValue2 + " written to PLC at address " + waddresses3);
|
| | | }
|
| | | }
|
| | |
|
| | | // 写入复位地址
|
| | | if (messageArray.getJSONArray(3).size() > 0) {
|
| | | JSONArray jsonArray = messageArray.getJSONArray(3);
|
| | | List<Short> sValue2 = new ArrayList<>();
|
| | | List<Boolean> messageBooleans = new ArrayList<>();
|
| | | for (int i = 0; i < jsonArray.size(); i++) {
|
| | | Object value = jsonArray.get(i);
|
| | | if (value != null && !value.toString().equals("null")) {
|
| | | try {
|
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", "");
|
| | | short val = Short.parseShort(cleanedValue.trim());
|
| | | sValue2.add(val);
|
| | | // 将消息值转换为布尔列表
|
| | | for (short values : sValue2) {
|
| | | messageBooleans.add(values == 1 ? true : false);
|
| | | }
|
| | | System.out.println("messageValue:" + Arrays.asList(val) + " added to the list");
|
| | | } catch (NumberFormatException e) {
|
| | | // 如果无法解析为 short 类型,则忽略该部分
|
| | | System.err.println("Could not parse value: " + value);
|
| | | }
|
| | | }
|
| | | }
|
| | | if (!messageBooleans.isEmpty()) {
|
| | | S7control.getinstance().WriteBit(waddresses4, messageBooleans);
|
| | | System.out.println("Values " + messageBooleans + " written to PLC at address " + waddresses4);
|
| | | }
|
| | | }
|
| | |
|
| | | // 写入回零地址
|
| | | if (messageArray.getJSONArray(4).size() > 0) {
|
| | | JSONArray jsonArray = messageArray.getJSONArray(4);
|
| | | List<Short> sValue2 = new ArrayList<>();
|
| | | List<Boolean> messageBooleans = new ArrayList<>();
|
| | | for (int i = 0; i < jsonArray.size(); i++) {
|
| | | Object value = jsonArray.get(i);
|
| | | if (value != null && !value.toString().equals("null")) {
|
| | | try {
|
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", "");
|
| | | short val = Short.parseShort(cleanedValue.trim());
|
| | | sValue2.add(val);
|
| | | // 将消息值转换为布尔列表
|
| | | for (short values : sValue2) {
|
| | | messageBooleans.add(values == 1 ? true : false);
|
| | | }
|
| | | System.out.println("messageValue:" + Arrays.asList(val) + " added to the list");
|
| | | } catch (NumberFormatException e) {
|
| | | // 如果无法解析为 short 类型,则忽略该部分
|
| | | System.err.println("Could not parse value: " + value);
|
| | | }
|
| | | }
|
| | | }
|
| | | if (!messageBooleans.isEmpty()) {
|
| | | S7control.getinstance().WriteBit(waddresses5, messageBooleans);
|
| | | System.out.println("Values " + messageBooleans + " written to PLC at address " + waddresses5);
|
| | | }
|
| | | }
|
| | |
|
| | | // 清空消息列表
|
| | | webSocketServer.clearMessages();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | this.readValue(); |
| | | String PlcAddress = this.name; |
| | | Integer Plccount = this.count; |
| | | // this.readValue(); |
| | | // String PlcAddress = this.name; |
| | | // Integer Plccount = this.count; |
| | | |
| | | // System.out.println(stt); |
| | | // List<Short> arraylist = S7control.getinstance().ReadWord("DB100.0", 12); |
| | | // List<Short> state = S7control.getinstance().ReadWord("DB103.0", 10); |
| | | Short[] values1 = { 1231, 1, 1, 1, 1, 1, 2, 33, 2, 3, 4, 5 }; |
| | | List<Short> arraylist = new ArrayList<>(Arrays.asList(values1)); |
| | | List<Short> arraylist = S7control.getinstance().ReadWord("DB100.0", 72); |
| | | List<Short> state = S7control.getinstance().ReadWord("DB103.0", 10); |
| | | // Short[] values1 = { 1231, 1, 1, 1, 1, 1, 2, 33, 2, 3, 4, 5 ,1231, 1, 1, 1, 1, 1, 2, 33, 2, 3, 4, 5 }; |
| | | // List<Short> arraylist = new ArrayList<>(Arrays.asList(values1)); |
| | | |
| | | Short[] values2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
| | | List<Short> state = new ArrayList<>(Arrays.asList(values2)); |
| | | // Short[] values2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
| | | // List<Short> state = new ArrayList<>(Arrays.asList(values2)); |
| | | |
| | | // Boolean[] values = { false, true, true, true, true, true, true, true, true, |
| | | // true, true, true, true, true, true, true, true, true, true, true, true, true, |
| | |
| | | } |
| | | |
| | | // 将消息值写入 PLC |
| | | // S7control.getinstance().WriteWord(addressList, messageValues); |
| | | S7control.getinstance().WriteWord(addressList, messageValues); |
| | | System.out.println("messageValues:" + messageValues); |
| | | System.out.println("addressList:" + addressList); |
| | | // 清空消息列表 |
| | |
| | | // Integer Plccount = this.count; |
| | | |
| | | // System.out.println(stt); |
| | | List<Short> arraylist = S7control.getinstance().ReadWord("DB100.0", 12); |
| | | List<Short> fanzhuan1 = S7control.getinstance().ReadWord("DB100.8", 1); |
| | | List<Short> xiaoche1 = S7control.getinstance().ReadWord("DB100.12", 1); |
| | | List<String> addresses = new ArrayList<>(); |
| | | addresses.add("DB100.0"); |
| | | addresses.add("DB100.2"); |
| | | addresses.add("DB100.4"); |
| | | addresses.add("DB100.6"); |
| | | addresses.add("DB100.26"); |
| | | addresses.add("DB100.28"); |
| | | addresses.add("DB100.30"); |
| | | addresses.add("DB100.32"); |
| | | addresses.add("DB100.34"); |
| | | addresses.add("DB100.36"); |
| | | addresses.add("DB100.38"); |
| | | addresses.add("DB100.40"); |
| | | List<Short> arraylist = S7control.getinstance().readWords(addresses); |
| | | |
| | | List<Short> fanzhuan1 = S7control.getinstance().ReadWord("DB100.8", 1); |
| | | List<Short> xiaoche1 = S7control.getinstance().ReadWord("DB100.12", 1); |
| | | // Short[] values1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; |
| | | // List<Short> arraylist = new ArrayList<>(Arrays.asList(values1)); |
| | | // Short[] fanzhuan = { 4 }; |
| | |
| | | // new short[]{0,0, 0, 0, 0, 0, 0, 0, 0, 0} |
| | | |
| | | jsonObject.append("params", arraylist); |
| | | jsonObject.append("fanzhuan", fanzhuan1); |
| | | jsonObject.append("xiaoche", xiaoche1); |
| | | jsonObject.append("fanzhuan", fanzhuan1); |
| | | jsonObject.append("xiaoche", xiaoche1); |
| | | |
| | | WebSocketServer sendwServer = WebSocketServer.sessionMap.get("Parameter1"); |
| | | if (sendwServer != null) { |
| | |
| | | WebSocketServer webSocketServer = WebSocketServer.sessionMap.get("Parameter1"); |
| | | if (webSocketServer != null) { |
| | | List<String> messages = webSocketServer.getMessages(); |
| | | String addressList1 = "DB100.0"; |
| | | List<String> waddresses1 = new ArrayList<>(); |
| | | waddresses1.add("DB100.0"); |
| | | waddresses1.add("DB100.2"); |
| | | waddresses1.add("DB100.4"); |
| | | waddresses1.add("DB100.6"); |
| | | waddresses1.add("DB100.26"); |
| | | waddresses1.add("DB100.28"); |
| | | waddresses1.add("DB100.30"); |
| | | waddresses1.add("DB100.32"); |
| | | waddresses1.add("DB100.34"); |
| | | waddresses1.add("DB100.36"); |
| | | waddresses1.add("DB100.38"); |
| | | waddresses1.add("DB100.40"); |
| | | |
| | | String addressList2 = "DB100.8"; |
| | | String addressList3 = "DB100.12"; |
| | | |
| | |
| | | try { |
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", ""); |
| | | short sValue = Short.parseShort(cleanedValue.trim()); |
| | | S7control.getinstance().WriteWord(addressList1, Arrays.asList(sValue)); |
| | | S7control.getinstance().WriteWord(addressList2, Arrays.asList(sValue)); |
| | | System.out |
| | | .println("messageValue:" + Arrays.asList(sValue) + " written to PLC at address " + addressList3); |
| | | .println("messageValue:" + Arrays.asList(sValue) + " written to PLC at address " + addressList2); |
| | | } catch (NumberFormatException e) { |
| | | // 如果无法解析为 short 类型,则忽略该部分 |
| | | System.err.println("Could not parse value: " + value); |
| | |
| | | try { |
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", ""); |
| | | short sValue = Short.parseShort(cleanedValue.trim()); |
| | | S7control.getinstance().WriteWord(addressList2, Arrays.asList(sValue)); |
| | | S7control.getinstance().WriteWord(addressList3, Arrays.asList(sValue)); |
| | | System.out |
| | | .println("messageValue:" + Arrays.asList(sValue) + " written to PLC at address " + addressList2); |
| | | .println("messageValue:" + Arrays.asList(sValue) + " written to PLC at address " + addressList3); |
| | | } catch (NumberFormatException e) { |
| | | // 如果无法解析为 short 类型,则忽略该部分 |
| | | System.err.println("Could not parse value: " + value); |
| | |
| | | |
| | | // 写入第三个地址 |
| | | if (!mergedList.isEmpty()) { |
| | | S7control.getinstance().WriteWord(addressList3, mergedList); |
| | | System.out.println("messageValue:" + mergedList + " written to PLC at address " + addressList1); |
| | | S7control.getinstance().WriteWord(waddresses1, mergedList); |
| | | System.out.println("messageValue:" + mergedList + " written to PLC at address " + waddresses1); |
| | | } |
| | | |
| | | // 清空消息列表 |
| | |
| | | // addressList1.add("DB103.172~185"); |
| | | // addressList1.add("DB103.200~213"); |
| | | // addressList1.add("DB103.228~241"); |
| | | addressList1.add("DB103.40"); |
| | | addressList1.add("DB103.58"); |
| | | addressList1.add("DB103.72"); |
| | | addressList1.add("DB103.86"); |
| | | addressList1.add("DB103.100"); |
| | | addressList1.add("DB103.114"); |
| | | addressList1.add("DB103.128"); |
| | | addressList1.add("DB103.142"); |
| | | addressList1.add("DB103.156"); |
| | | addressList1.add("DB103.184"); |
| | | addressList1.add("DB103.212"); |
| | | addressList1.add("DB103.44");//D01 |
| | | addressList1.add("DB103.58");//D02 |
| | | addressList1.add("DB103.72");//D03 |
| | | addressList1.add("DB103.86");//D04 |
| | | addressList1.add("DB103.100");//D05 |
| | | addressList1.add("DB103.114");//D06 |
| | | addressList1.add("DB103.128");//A01 |
| | | addressList1.add("DB103.156");//A01 2 |
| | | addressList1.add("DB103.142");//A02 |
| | | addressList1.add("DB103.212");//B01 |
| | | addressList1.add("DB103.184");//B02 |
| | | |
| | | |
| | | List<String> paramlist = S7control.getinstance().readStrings(addressList1); |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | List<String> addresses = new ArrayList<>(); |
| | | addresses.add("DB103.25"); |
| | | addresses.add("DB100.144"); |
| | | |
| | | addresses.add("DB100.184"); |
| | | addresses.add("DB100.186"); |
| | | addresses.add("DB100.180"); |
| | | addresses.add("DB100.182"); |
| | | |
| | | List<Short> arraylist = S7control.getinstance().readWords(addresses); |
| | | |
| | | // String rangeAddress = "DB100.148-161"; |
| | | String rangeAddress = "DB100.148"; |
| | | int insertIndex = 2; |
| | | insertDataToList(arraylist, rangeAddress, insertIndex); |
| | | |
| | | |
| | | List<String> addresses2 = new ArrayList<>(); |
| | | addresses2.add("DB103.26"); |
| | | addresses2.add("DB100.188"); |
| | | addresses2.add("DB100.190"); |
| | | addresses2.add("DB100.146"); |
| | | // addresses2.add("DB100.162-175"); |
| | | List<Short> arraylist2 = S7control.getinstance().readWords(addresses2); |
| | | // String rangeAddress2 = "DB100.148-161"; |
| | | String rangeAddress2 = "DB100.162"; |
| | | int insertIndex2 = 4; |
| | | insertDataToList(arraylist2, rangeAddress2, insertIndex2); |
| | | // System.out.println(arraylist2); |
| | | List<String> addresses3 = new ArrayList<>(); |
| | | addresses3.add("DB103.42"); |
| | | List<Short> arraylist3 = S7control.getinstance().readWords(addresses3); |
| | | |
| | | List<String> addresses4 = new ArrayList<>(); |
| | | addresses4.add("DB103.46"); |
| | | List<Short> arraylist4 = S7control.getinstance().readWords(addresses4); |
| | | |
| | | List<Short> arraylist5 = S7control.getinstance().ReadWord("DB103.27", 2); |
| | | List<Short> arraylist6 = S7control.getinstance().ReadWord("DB103.29", 2); |
| | | List<String> addresses7 = new ArrayList<>(); |
| | | addresses7.add("DB104.24"); |
| | | addresses7.add("DB104.26"); |
| | | addresses7.add("DB104.20"); |
| | | addresses7.add("DB104.22"); |
| | | addresses7.add("DB104.28"); |
| | | addresses7.add("DB104.30"); |
| | | List<Short> arraylist7 = S7control.getinstance().readWords(addresses7); |
| | | |
| | | |
| | | List<String> addresses8 = new ArrayList<>(); |
| | | addresses8.add("DB101.3.7"); |
| | | addresses8.add("DB101.4.2"); |
| | | addresses8.add("DB101.4.5"); |
| | | addresses8.add("DB101.4.7"); |
| | | List<Boolean> arraylist8 = S7control.getinstance().readBits(addresses8); |
| | | short[] params = new short[arraylist8.size()]; |
| | | for (int i = 0; i < arraylist8.size(); i++) { |
| | | boolean value = arraylist8.get(i); |
| | | params[i] = value ? (short) 1 : (short) 0; |
| | | } |
| | | |
| | | |
| | | // Short[] values1 = { 1, 2, 3, 4, 5, 6, 7}; |
| | | // List<Short> arraylist = new ArrayList<>(Arrays.asList(values1)); |
| | | // Short[] values2 = { 1, 2, 3, 4, 5}; |
| | | // List<Short> arraylist2 = new ArrayList<>(Arrays.asList(values2)); |
| | | // List<String> addresses = new ArrayList<>(); |
| | | // addresses.add("DB103.25"); |
| | | // addresses.add("DB100.144"); |
| | | // |
| | | // Short[] values3 = {1}; |
| | | // List<Short> arraylist3 = new ArrayList<>(Arrays.asList(values3)); |
| | | // Short[] values4 = {2}; |
| | | // List<Short> arraylist4 = new ArrayList<>(Arrays.asList(values4)); |
| | | // Short[] values5 = {3,3}; |
| | | // List<Short> arraylist5 = new ArrayList<>(Arrays.asList(values5)); |
| | | // Short[] values6 = { 4,4}; |
| | | // List<Short> arraylist6 = new ArrayList<>(Arrays.asList(values6)); |
| | | // Short[] values7 = { 1,1,1,1,1,1}; |
| | | // List<Short> arraylist7 = new ArrayList<>(Arrays.asList(values7)); |
| | | // Short[] values8 = { 1,1,1,1,1,1}; |
| | | // List<Short> arraylist8 = new ArrayList<>(Arrays.asList(values8)); |
| | | // addresses.add("DB100.184"); |
| | | // addresses.add("DB100.186"); |
| | | // addresses.add("DB100.180"); |
| | | // addresses.add("DB100.182"); |
| | | // |
| | | // List<Short> arraylist = S7control.getinstance().readWords(addresses); |
| | | // |
| | | //// String rangeAddress = "DB100.148-161"; |
| | | // String rangeAddress = "DB100.148"; |
| | | // int insertIndex = 2; |
| | | // insertDataToList(arraylist, rangeAddress, insertIndex); |
| | | // |
| | | // |
| | | // List<String> addresses2 = new ArrayList<>(); |
| | | // addresses2.add("DB103.26"); |
| | | // addresses2.add("DB100.188"); |
| | | // addresses2.add("DB100.190"); |
| | | // addresses2.add("DB100.146"); |
| | | //// addresses2.add("DB100.162-175"); |
| | | // List<Short> arraylist2 = S7control.getinstance().readWords(addresses2); |
| | | //// String rangeAddress2 = "DB100.148-161"; |
| | | // String rangeAddress2 = "DB100.162"; |
| | | // int insertIndex2 = 4; |
| | | // insertDataToList(arraylist2, rangeAddress2, insertIndex2); |
| | | //// System.out.println(arraylist2); |
| | | // List<String> addresses3 = new ArrayList<>(); |
| | | // addresses3.add("DB103.42"); |
| | | // List<Short> arraylist3 = S7control.getinstance().readWords(addresses3); |
| | | // |
| | | // List<String> addresses4 = new ArrayList<>(); |
| | | // addresses4.add("DB103.46"); |
| | | // List<Short> arraylist4 = S7control.getinstance().readWords(addresses4); |
| | | // |
| | | // List<Short> arraylist5 = S7control.getinstance().ReadWord("DB103.27", 2); |
| | | // List<Short> arraylist6 = S7control.getinstance().ReadWord("DB103.29", 2); |
| | | // List<String> addresses7 = new ArrayList<>(); |
| | | // addresses7.add("DB104.1.4"); |
| | | // addresses7.add("DB104.1.5"); |
| | | // addresses7.add("DB104.1.2"); |
| | | // addresses7.add("DB104.1.3"); |
| | | // addresses7.add("DB104.1.6"); |
| | | // addresses7.add("DB104.1.7"); |
| | | // List<Boolean> arraylist7 = S7control.getinstance().readBits(addresses7); |
| | | // |
| | | // |
| | | // short[] params2 = new short[arraylist7.size()]; |
| | | // for (int i = 0; i < arraylist7.size(); i++) { |
| | | // boolean value = arraylist7.get(i); |
| | | // params2[i] = value ? (short) 1 : (short) 0; |
| | | // } |
| | | // |
| | | // List<String> addresses8 = new ArrayList<>(); |
| | | // addresses8.add("DB101.3.7"); |
| | | // addresses8.add("DB101.4.2"); |
| | | // addresses8.add("DB101.4.5"); |
| | | // addresses8.add("DB101.4.7"); |
| | | // List<Boolean> arraylist8 = S7control.getinstance().readBits(addresses8); |
| | | // short[] params = new short[arraylist8.size()]; |
| | | // for (int i = 0; i < arraylist8.size(); i++) { |
| | | // boolean value = arraylist8.get(i); |
| | | // params[i] = value ? (short) 1 : (short) 0; |
| | | // } |
| | | |
| | | |
| | | Short[] values1 = { 1, 2, 3, 4, 5, 6, 7}; |
| | | List<Short> arraylist = new ArrayList<>(Arrays.asList(values1)); |
| | | Short[] values2 = { 1, 2, 3, 4, 5}; |
| | | List<Short> arraylist2 = new ArrayList<>(Arrays.asList(values2)); |
| | | |
| | | Short[] values3 = {1}; |
| | | List<Short> arraylist3 = new ArrayList<>(Arrays.asList(values3)); |
| | | Short[] values4 = {2}; |
| | | List<Short> arraylist4 = new ArrayList<>(Arrays.asList(values4)); |
| | | Short[] values5 = {3,3}; |
| | | List<Short> arraylist5 = new ArrayList<>(Arrays.asList(values5)); |
| | | Short[] values6 = { 4,4}; |
| | | List<Short> arraylist6 = new ArrayList<>(Arrays.asList(values6)); |
| | | Short[] values7 = { 1,1,1,1,1,1}; |
| | | List<Short> arraylist7 = new ArrayList<>(Arrays.asList(values7)); |
| | | Short[] values8 = { 1,1,1,1,1,1}; |
| | | List<Short> arraylist8 = new ArrayList<>(Arrays.asList(values8)); |
| | | |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | |
| | | jsonObject.append("zuhe4", arraylist4); |
| | | jsonObject.append("zuhe5", arraylist5); |
| | | jsonObject.append("zuhe6", arraylist6); |
| | | jsonObject.append("guzhang", arraylist7); |
| | | jsonObject.append("weihuiling", params); |
| | | // jsonObject.append("guzhang", params2); |
| | | // jsonObject.append("weihuiling", params); |
| | | |
| | | |
| | | |
| | |
| | | }
|
| | |
|
| | | // 调用方法,进行赋值
|
| | | this.readValue();
|
| | | String PlcAddress = this.name;
|
| | | Integer Plccount = this.count;
|
| | | // this.readValue();
|
| | | // String PlcAddress = this.name;
|
| | | // Integer Plccount = this.count;
|
| | | // System.out.println(PlcAddress);
|
| | |
|
| | | List<Boolean> paramlist = S7control.getinstance().ReadBits("DB2.0.0", 26);
|
| | | List<Boolean> paramlist = S7control.getinstance().ReadBits("DB2.0.0", 26);
|
| | | // Boolean[] values = { false, true, true, true, true, true, true, true, true,
|
| | | // true, true, true, true, true, true, true, true, true, true, true, true, true, true,
|
| | | // true, false, true };
|
| | |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | this.readValue(); |
| | | String PlcAddress = this.name; |
| | | Integer Plccount = this.count; |
| | | // this.readValue(); |
| | | // String PlcAddress = this.name; |
| | | // Integer Plccount = this.count; |
| | | |
| | | // 根据地址读取PCL数据 |
| | | // List<Boolean> plclist = S7control.getinstance().ReadBits("DB104.0.0", 71); |
| | | List<Boolean> plclist = S7control.getinstance().ReadBits(PlcAddress, Plccount); |
| | | List<Boolean> plclist = S7control.getinstance().ReadBits("DB104.0.0", 71); |
| | | // List<Boolean> plclist = S7control.getinstance().ReadBits(PlcAddress, Plccount); |
| | | // System.out.println(plclist); |
| | | // Boolean[] values = { false, false, true, false, true, false, true, false, |
| | | // true, false, true, false, true, false, |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | this.readValue(); |
| | | String PlcAddress = this.name; |
| | | Integer Plccount = this.count; |
| | | // this.readValue(); |
| | | // String PlcAddress = this.name; |
| | | // Integer Plccount = this.count; |
| | | // System.out.println(PlcAddress); |
| | | |
| | | List<Boolean> plclist = S7control.getinstance().ReadBits(PlcAddress, Plccount); |
| | | // List<Boolean> plclist2 = S7control.getinstance().ReadBits("DB102.5.5", 13); |
| | | // List<Boolean> plclist = S7control.getinstance().ReadBits(PlcAddress, Plccount); |
| | | List<Boolean> plclist = S7control.getinstance().ReadBits("DB102.0.0", 64); |
| | | |
| | | // Boolean[] values = { true, true, true, true, true, false, true, false, |
| | | // true, false, true, false, true, false, |
| | | // true, false, true, false, true, false, true, false, true, false, true, false, |
| | | // true, false, true, false, true, |
| | | // false, true, false, true, false, |
| | | // true, false, true, false, true, false, true, false, null, |
| | | // true, false, |
| | | // true, false, true, false, true, false, |
| | | // true, false, true, false, true, }; |
| | | // List<Boolean> plclist = new ArrayList<>(Arrays.asList(values)); |
| | | // Boolean[] values = { true, true, true, true, true, false, true, false, |
| | | // true, false, true, false, true, false, |
| | | // true, false, true, false, true, false, true, false, true, false, true, false, |
| | | // true, false, true, false, true, |
| | | // false, true, false, true, false, |
| | | // true, false, true, false, true, false, true, false, null, |
| | | // true, false, |
| | | // true, false, true, false, true, false, |
| | | // true, false, true, false, true, }; |
| | | // List<Boolean> plclist = new ArrayList<>(Arrays.asList(values)); |
| | | |
| | | if (plclist != null) { |
| | | // 将获取的布尔类型转换为整数类型 |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | this.readValue(); |
| | | String PlcAddress = this.name; |
| | | Integer Plccount = this.count; |
| | | // this.readValue(); |
| | | // String PlcAddress = this.name; |
| | | // Integer Plccount = this.count; |
| | | // System.out.println(PlcAddress); |
| | | |
| | | List<Short> plclist = S7control.getinstance().ReadWord("DB103.0", 10); |
| | | List<Short> plclist = S7control.getinstance().ReadWord("DB103.0", 44); |
| | | // Short[] values = { 0, 1, 1, 0, 1, 0, 1, 0, |
| | | // 1, 0, }; |
| | | // List<Short> plclist = new ArrayList<>(Arrays.asList(values)); |
| | |
| | | import com.example.springboot.component.PlcParameter2; |
| | | import com.example.springboot.component.PlcParameter1; |
| | | import com.example.springboot.component.PlcServoManualone; |
| | | import com.example.springboot.component.PLCAutomaticParameterSetting; |
| | | import com.example.springboot.component.PlcManualonePosition; |
| | | import com.example.springboot.component.PlcManualonePosition2; |
| | | import com.example.springboot.component.PLCManualJog; |
| | | |
| | | @Component |
| | | @Order(1) |
| | |
| | | |
| | | // new PlcHold().start(); |
| | | |
| | | // new Plcaction().start(); |
| | | new Plcaction().start(); |
| | | // |
| | | // new Plchome().start(); |
| | | // |
| | | // new PlcParameter().start(); |
| | | new PlcParameter().start(); |
| | | // |
| | | // new Plcalarm().start(); |
| | | //new Plcalarm().start(); |
| | | // |
| | | // new Plcsign().start(); |
| | | new Plcsign().start(); |
| | | // |
| | | // new Plcstate().start(); |
| | | new Plcstate().start(); |
| | | new PlcPositioning1().start(); |
| | | new PlcPositioning2().start(); |
| | | new PlcParameter2().start(); |
| | | new PlcParameter1().start(); |
| | | new PLCAutomaticParameterSetting().start(); |
| | | |
| | | new PlcManualonePosition().start(); |
| | | new PlcManualonePosition2().start(); |
| | | new PlcServoManualone().start(); |
| | | new PLCManualJog().start(); |
| | | } |
| | | } |