| | |
| | | "address": "DB100.0", |
| | | "count": 3, |
| | | "unit": "°", |
| | | "value": "" |
| | | "value": "", |
| | | "min": 0, |
| | | "max": 100 |
| | | }, |
| | | { |
| | | "name": "A01行走低速角度", |
| | |
| | | "address": "DB100.0", |
| | | "unit": "°", |
| | | "type": "0", |
| | | "value": "" |
| | | "value": "", |
| | | "min": 0, |
| | | "max": 100 |
| | | }, |
| | | { |
| | | "name": "A01输送接片角度", |
| | |
| | | "unit": "°", |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | | "value": "" |
| | | "value": "", |
| | | "min": 0, |
| | | "max": 100 |
| | | }, |
| | | { |
| | | "name": "A01笼子角度", |
| | |
| | | "unit": "°", |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | | "value": "" |
| | | "value": "", |
| | | "min": 0, |
| | | "max": 100 |
| | | } |
| | | ], |
| | | [ |
| | |
| | | "unit": "°", |
| | | "address": "DB100.0", |
| | | "count": 3, |
| | | "value": "" |
| | | "value": "", |
| | | "min": 0, |
| | | "max": 100 |
| | | }, |
| | | { |
| | | "name": "A02行走低速角度", |
| | |
| | | "unit": "°", |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | | "value": "" |
| | | "value": "", |
| | | "min": 0, |
| | | "max": 100 |
| | | }, |
| | | { |
| | | "name": "A02输送接片角度", |
| | |
| | | "unit": "°", |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | | "value": "" |
| | | "value": "", |
| | | "min": 0, |
| | | "max": 100 |
| | | }, |
| | | { |
| | | "name": "A02笼子角度", |
| | |
| | | "unit": "°", |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | | "value": "" |
| | | "value": "", |
| | | "min": 0, |
| | | "max": 100 |
| | | } |
| | | ], |
| | | [ |
| | |
| | | "unit": "m/min", |
| | | "address": "DB100.0", |
| | | "count": 3, |
| | | "value": "" |
| | | "value": "", |
| | | "min": 0, |
| | | "max": 100 |
| | | } |
| | | ], |
| | | [ |
| | |
| | | "unit": "m/min", |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | | "value": "" |
| | | "value": "", |
| | | "min": 0, |
| | | "max": 100 |
| | | } |
| | | ], |
| | | [ |
| | |
| | | "unit": "m/min", |
| | | "address": "DB100.0", |
| | | "type": "0", |
| | | "value": "" |
| | | "value": "", |
| | | "min": 0, |
| | | "max": 100 |
| | | } |
| | | ], |
| | | [ |
| | |
| | | "type": "0", |
| | | "unit": "m/min", |
| | | "count":3, |
| | | "value":0 |
| | | "value":0, |
| | | "min": 0, |
| | | "max": 1000 |
| | | }, |
| | | { |
| | | "name": "高速线速度", |
| | |
| | | "sending": 0, |
| | | "type": "0", |
| | | "unit": "m/min", |
| | | "value":0 |
| | | "value":0, |
| | | "min": 0, |
| | | "max": 100 |
| | | }, |
| | | { |
| | | "name": "低速线速度", |
| | |
| | | "sending": 0, |
| | | "type": "0", |
| | | "unit": "m/min", |
| | | "value":0 |
| | | "value":0, |
| | | "min": 0, |
| | | "max": 100 |
| | | }, |
| | | { |
| | | "name": "手动速度", |
| | |
| | | "sending": 0, |
| | | "type": "0", |
| | | "unit": "m/min", |
| | | "value":0 |
| | | "value":0, |
| | | "min": 0, |
| | | "max": 100 |
| | | } |
| | | |
| | | |
| | |
| | | "type": "0", |
| | | "unit": "m/min", |
| | | "count":3, |
| | | "value":0 |
| | | "value":0, |
| | | "min": 0, |
| | | "max": 100 |
| | | }, |
| | | { |
| | | "name": "高速线速度", |
| | |
| | | "sending": 0, |
| | | "unit": "m/min", |
| | | "type": "0", |
| | | "value":0 |
| | | "value":0, |
| | | "min": 0, |
| | | "max": 100 |
| | | }, |
| | | { |
| | | "name": "低速线速度", |
| | |
| | | "sending": 0, |
| | | "unit": "m/min", |
| | | "type": "0", |
| | | "value":0 |
| | | "value":0, |
| | | "min": 0, |
| | | "max": 100 |
| | | }, |
| | | { |
| | | "name": "手动速度", |
| | |
| | | "sending": 0, |
| | | "unit": "m/min", |
| | | "type": "0", |
| | | "value":0 |
| | | "value":0, |
| | | "min": 0, |
| | | "max": 100 |
| | | } |
| | | |
| | | |
| | |
| | | "type": "0", |
| | | "unit": "m/min", |
| | | "count":3, |
| | | "value":0 |
| | | "value":0, |
| | | "min": 0, |
| | | "max": 100 |
| | | }, |
| | | { |
| | | "name": "高速线速度", |
| | |
| | | "sending": 0, |
| | | "type": "0", |
| | | "unit": "m/min", |
| | | "value":0 |
| | | "value":0, |
| | | "min": 0, |
| | | "max": 100 |
| | | }, |
| | | { |
| | | "name": "低速线速度", |
| | |
| | | "sending": 0, |
| | | "type": "0", |
| | | "unit": "m/min", |
| | | "value":0 |
| | | "value":0, |
| | | "min": 0, |
| | | "max": 100 |
| | | }, |
| | | { |
| | | "name": "手动速度", |
| | |
| | | "sending": 0, |
| | | "type": "0", |
| | | "unit": "m/min", |
| | | "value":0 |
| | | "value":0, |
| | | "min": 0, |
| | | "max": 100 |
| | | } |
| | | |
| | | |
| | |
| | | "unit": "mm/S", |
| | | |
| | | "count":3, |
| | | "value":0 |
| | | "value":0, |
| | | "min": 0, |
| | | "max": 100 |
| | | } |
| | | |
| | | |
| | |
| | | "sending": 0, |
| | | "unit": "mm/S", |
| | | "type": "0", |
| | | "value":0 |
| | | "value":0, |
| | | "min": 0, |
| | | "max": 100 |
| | | } |
| | | |
| | | |
| | |
| | | "sending": 0, |
| | | "type": "0", |
| | | "unit": "mm", |
| | | "value":"0" |
| | | "value":"0", |
| | | "min": 0, |
| | | "max": 100 |
| | | |
| | | }], |
| | | [{ |
| | |
| | | <div v-for="(item, itemIndex) in dataGroup" :key="itemIndex" class="item-container"> |
| | | <div class="item-row"> |
| | | <span class="name" style="width:250px;">{{ item.name }}</span> |
| | | <el-input v-if="item.type === '0'" v-model="item.value" class="input-box" |
| | | @keyup.enter.native="submitDataToBackend"></el-input> |
| | | <el-input v-if="item.type === '0'" |
| | | v-model="item.value" |
| | | class="input-box" |
| | | :oninput="`value=value.replace(/^0|[^0-9]/g,'');if(value<`+item.min+`){value=`+item.value+`}else if(value>`+item.max+`){value=`+item.value+`}`" |
| | | @keyup.enter.native="submitDataToBackend"> |
| | | </el-input> |
| | | |
| | | <span v-if="item.unit" :name="item.unit" >{{ item.unit }}</span> |
| | | |
| | | |
| | | |
| | | </div> |
| | | </div> |
| | |
| | | updateButtonValue (dataGroup, itemIndex) { |
| | | this.$set(dataGroup[itemIndex].button, 'value', 1); // 点击按钮后将值改为1 |
| | | }, |
| | | checkInputValue() { |
| | | if (this.item.value < this.item.min || this.item.value > this.item.max) { |
| | | this.item.value = ''; // 清空输入框的值 |
| | | } |
| | | }, |
| | | submitDataToBackend () { |
| | | const inputData = this.jsonData.map(dataGroup => { |
| | | return dataGroup.map(item => { |
| | |
| | | </el-breadcrumb> |
| | | |
| | | <el-row :gutter="40" > |
| | | <el-col :span="16" v-for="(dataGroup, groupIndex) in jsonData" :key="groupIndex"> |
| | | <el-col :span="26" v-for="(dataGroup, groupIndex) in jsonData" :key="groupIndex"> |
| | | <el-card class="json-block" style="width:100%;"> |
| | | |
| | | <div class="button-row" style="display: flex; justify-content: flex-start;flex-wrap:wrap;"> |
| | | <div v-for="(item, itemIndex) in dataGroup" :key="itemIndex" style="margin: 10px;"> |
| | | <el-button v-if="item.button" :name="item.button.name" |
| | | <el-button v-if="item.button" :name="item.button.name" style='width:200px;' |
| | | :class="{ 'dow': false, 'op': item.button.value === 1 }" class="action-button" |
| | | @click="updateButtonValue(dataGroup, itemIndex); submitDataToBackend();">{{ |
| | | item.button.name |
| | |
| | |
|
| | | }
|
| | |
|
| | | if (currentButtonName === '回零' || currentButtonName === 'Zero') {
|
| | | if (currentButtonName === '回零' || currentButtonName === 'Home') {
|
| | |
|
| | | const data2 = [];
|
| | | const resetButtonValues = this.jsonData.map(item => {
|
| | | const buttonItem = item.find(subItem => subItem.button && ['回零', 'Zero'].includes(subItem.button.name));
|
| | | const buttonItem = item.find(subItem => subItem.button && ['回零', 'Home'].includes(subItem.button.name));
|
| | |
|
| | | return buttonItem ? buttonItem.button.value : null;
|
| | | }).filter(value => value !== null);
|
| | |
| | |
|
| | | }
|
| | |
|
| | | if (currentButtonName === '回零' || currentButtonName === 'Zero') {
|
| | | if (currentButtonName === '回零' || currentButtonName === 'Home') {
|
| | |
|
| | | const data2 = [];
|
| | | const resetButtonValues = this.jsonData.map(item => {
|
| | | const buttonItem = item.find(subItem => subItem.button && ['回零', 'Zero'].includes(subItem.button.name));
|
| | | const buttonItem = item.find(subItem => subItem.button && ['回零', 'Home'].includes(subItem.button.name));
|
| | |
|
| | | return buttonItem ? buttonItem.button.value : null;
|
| | | }).filter(value => value !== null);
|
| | |
| | | |
| | | const parms = obj.params; |
| | | |
| | | console.log(obj); |
| | | // console.log(obj); |
| | | |
| | | // const handleMouseMove = throttle(function(event) { |
| | | // const inputBox = document.querySelectorAll('.id'); |
| | |
| | | |
| | | }, |
| | | submitDataToBackend(currentButtonName) { |
| | | |
| | | //A01半自动启动提交 |
| | | if (currentButtonName === 'A01半自动启动' ||currentButtonName === 'A01 Semi-Auto Start') { |
| | | const data = []; |
| | | let jsonObject; |
| | | |
| | | |
| | | const values = [this.jsonData[0][10].button.value] |
| | | |
| | | if (currentButtonName === 'A01半自动启动' || currentButtonName === 'A01 Semi-Auto Start') { |
| | | const values = [this.jsonData[0][10].button.value]; |
| | | data.push(values); |
| | | |
| | | |
| | | data.unshift([], [],[],[], [],[],[], []); |
| | | |
| | | |
| | | const jsonObject = { data }; |
| | | |
| | | // 提交数据到后端 |
| | | const jsonString = JSON.stringify(jsonObject); |
| | | console.log('所有Type为0的value:', jsonString); |
| | | socket?.send(jsonString); |
| | | |
| | | jsonObject = { data }; |
| | | } |
| | | //A02半自动启动 提交 |
| | | |
| | | if (currentButtonName === 'A02半自动启动' ||currentButtonName === 'A02 Semi-Auto Start') { |
| | | const data2 = []; |
| | | |
| | | const values2 = [this.jsonData[1][8].button.value] |
| | | |
| | | data2.push(values2); |
| | | |
| | | data2.unshift([],[], [],[],[], [],[],[], []); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | const jsonObject = { data:data2 }; |
| | | |
| | | // 提交数据到后端 |
| | | const jsonString = JSON.stringify(jsonObject); |
| | | console.log('所有Type为0的value:', jsonString); |
| | | socket?.send(jsonString); |
| | | |
| | | const values2 = [this.jsonData[1][8].button.value]; |
| | | data.push(values2); |
| | | data.unshift([],[], [],[],[], [],[],[], []); |
| | | jsonObject = { data }; |
| | | } |
| | | |
| | | //复位提交 |
| | | |
| | | if (currentButtonName === '复位' || currentButtonName === 'Reset') { |
| | | const data2 = []; |
| | | const resetButtonValues = this.jsonData.map(item => { |
| | | const buttonItem = item.find(subItem => subItem.button && ['复位', 'Reset'].includes(subItem.button.name)); |
| | | const resetButtonValues = this.jsonData |
| | | .map(item => item.find(subItem => subItem.button && ['复位', 'Reset'].includes(subItem.button.name))) |
| | | .filter(value => value !== null) |
| | | .map(item => item.button.value); |
| | | |
| | | |
| | | return buttonItem ? buttonItem.button.value : null; |
| | | }).filter(value => value !== null); |
| | | |
| | | // 将得到的值添加到 data 数组中 |
| | | data2.push(resetButtonValues.flat()); |
| | | |
| | | // 在 data2 数组前面添加两个空数组 |
| | | data2.unshift([], []); |
| | | data2.push([], [], [], [], []); |
| | | |
| | | // 创建 jsonObject2 对象,并添加 data2 属性 |
| | | const jsonObject2 = { data: data2 }; |
| | | |
| | | // 提交数据到后端 |
| | | const jsonString2 = JSON.stringify(jsonObject2); |
| | | console.log('所有Type为0的value:', jsonString2); |
| | | socket?.send(jsonString2); |
| | | // setTimeout(()=> |
| | | // window.location.reload(),2000 |
| | | // ) |
| | | |
| | | data.push(resetButtonValues.flat()); |
| | | data.unshift([], []); |
| | | data.push([], [], [], [], []); |
| | | jsonObject = { data }; |
| | | } |
| | | ////回零提交 |
| | | |
| | | if (currentButtonName === '回零' || currentButtonName === 'Home') { |
| | | const data3 = []; |
| | | const resetButtonValues3 = this.jsonData.map(item => { |
| | |
| | | data3.push([], [], [], []); |
| | | |
| | | // 创建 jsonObject3 对象,并添加 data3 属性 |
| | | const jsonObject3 = { data: data3 }; |
| | | jsonObject = { data: data3 }; |
| | | |
| | | // 提交数据到后端 |
| | | const jsonString3 = JSON.stringify(jsonObject3); |
| | | console.log('回零:', jsonString3); |
| | | socket?.send(jsonString3); |
| | | // setTimeout(()=> |
| | | // window.location.reload(),2000 |
| | | // ) |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | //A01半自动提交 |
| | | |
| | | if (currentButtonName === 'A01半自动' || currentButtonName === 'A01 Semi-Auto' ) { |
| | | const elements = document.getElementsByClassName('special-class'); |
| | | const data = []; |
| | |
| | | |
| | | |
| | | |
| | | const jsonObject = { data }; |
| | | jsonObject = { data }; |
| | | |
| | | // 提交数据到后端 |
| | | const jsonString = JSON.stringify(jsonObject); |
| | | console.log('所有Type为0的value:', jsonString); |
| | | socket?.send(jsonString); |
| | | |
| | | } |
| | | |
| | |
| | | data.unshift([],[],[],[],[],[],[]); |
| | | |
| | | |
| | | const jsonObject = { data }; |
| | | jsonObject = { data }; |
| | | |
| | | // 提交数据到后端 |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | const jsonString = JSON.stringify(jsonObject); |
| | | console.log('所有Type为0的value:', jsonString); |
| | | socket?.send(jsonString); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | }, |
| | | |
| | | |
| | | initWebSocket () { |
| | | |
| | |
| | | } |
| | | |
| | | let obj = JSON.parse(msg.data); |
| | | console.log(obj) |
| | | // console.log(obj) |
| | | const weihuiling=obj.weihuiling; |
| | | const jsonData2 = this.jsonData; |
| | | |
| | |
| | | // 设置token |
| | | setToken(res.data.Authorization); |
| | | this.$router.push('/layout') |
| | | this.$message.success('登录成功'); |
| | | this.$message.success(this.$t('loginSuccess')); |
| | | }); |
| | | }) |
| | | }, |
| | |
| | | }
|
| | | }
|
| | |
|
| | | //写入Word
|
| | | //不连续地址 写入Word
|
| | | public void WriteWordToPLC(JSONArray messageArray, List<String> addresses, int index) {
|
| | | try {
|
| | | if (messageArray.getJSONArray(index).size() > 0) {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | public void WriteWordsToPLC(JSONArray jsonArray, String address,int index) {
|
| | | if (jsonArray.getJSONArray(index).size() > 0) {
|
| | | Object value = jsonArray.getJSONArray(index).get(0);
|
| | | if (value != null && !value.toString().equals("null")) {
|
| | | try {
|
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", "");
|
| | | short sValue = Short.parseShort(cleanedValue.trim());
|
| | | S7control.getinstance().WriteWord(address, Arrays.asList(sValue));
|
| | | System.out.println("messageValue:" + Arrays.asList(sValue) + " written to PLC at address " + address);
|
| | | } catch (NumberFormatException e) {
|
| | | // 如果无法解析为 short 类型,则忽略该部分
|
| | | System.err.println("Could not parse value: " + value);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | //写入String
|
| | | public void writeStringToPLC(JSONArray messageArray, String addresses, int index) {
|
| | | try {
|
| | |
| | | import java.util.List; |
| | | |
| | | public class PLCAutomaticParameterSetting 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(); |
| | | } |
| | | } |
| | | |
| | | // 创建一个自定义的 S7 控制器消息处理器对象 |
| | | MessageHandler customS7Control = new MessageHandler(); |
| | | @Override |
| | | public void run() { |
| | | while (this != null) { |
| | |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // this.readValue(); |
| | | // String PlcAddress = this.name; |
| | | // Integer Plccount = this.count; |
| | | |
| | | |
| | | // System.out.println(stt); |
| | | List<Short> arraylist = S7control.getinstance().ReadWord("DB100.120", 8); |
| | |
| | | } |
| | | System.out.println(messageArray); |
| | | // 写入第一个地址 |
| | | if (messageArray.getJSONArray(2).size() > 0) { |
| | | Object value = messageArray.getJSONArray(2).get(0); |
| | | if (value != null && !value.toString().equals("null")) { |
| | | try { |
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", ""); |
| | | short sValue = Short.parseShort(cleanedValue.trim()); |
| | | S7control.getinstance().WriteWord(addressList2, Arrays.asList(sValue)); |
| | | System.out |
| | | .println("messageValue:" + Arrays.asList(sValue) + " written to PLC at address " + addressList2); |
| | | } catch (NumberFormatException e) { |
| | | // 如果无法解析为 short 类型,则忽略该部分 |
| | | System.err.println("Could not parse value: " + value); |
| | | } |
| | | } |
| | | } |
| | | customS7Control.WriteWordsToPLC(messageArray, addressList2,2); |
| | | |
| | | // 写入第二个地址 |
| | | if (messageArray.getJSONArray(3).size() > 0) { |
| | | Object value = messageArray.getJSONArray(3).get(0); |
| | | if (value != null && !value.toString().equals("null")) { |
| | | try { |
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", ""); |
| | | short sValue = Short.parseShort(cleanedValue.trim()); |
| | | S7control.getinstance().WriteWord(addressList3, Arrays.asList(sValue)); |
| | | System.out |
| | | .println("messageValue:" + Arrays.asList(sValue) + " written to PLC at address " + addressList3); |
| | | } catch (NumberFormatException e) { |
| | | // 如果无法解析为 short 类型,则忽略该部分 |
| | | System.err.println("Could not parse value: " + value); |
| | | } |
| | | } |
| | | } |
| | | customS7Control.WriteWordsToPLC(messageArray, addressList3,3); |
| | | |
| | | |
| | | // 写入第三个地址 |
| | | if (messageArray.getJSONArray(4).size() > 0) { |
| | | Object value = messageArray.getJSONArray(4).get(0); |
| | | if (value != null && !value.toString().equals("null")) { |
| | | try { |
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", ""); |
| | | short sValue = Short.parseShort(cleanedValue.trim()); |
| | | S7control.getinstance().WriteWord(addressList4, Arrays.asList(sValue)); |
| | | System.out |
| | | .println("messageValue:" + Arrays.asList(sValue) + " written to PLC at address " + addressList4); |
| | | } catch (NumberFormatException e) { |
| | | // 如果无法解析为 short 类型,则忽略该部分 |
| | | System.err.println("Could not parse value: " + value); |
| | | } |
| | | } |
| | | } |
| | | customS7Control.WriteWordsToPLC(messageArray, addressList4,4); |
| | | |
| | | |
| | | // 写入第四个地址 |
| | | if (!mergedList.isEmpty()) { |
| | |
| | | } |
| | | |
| | | // 写入第伍个地址 |
| | | if (messageArray.getJSONArray(8).size() > 0) { |
| | | Object value = messageArray.getJSONArray(8).get(0); |
| | | if (value != null && !value.toString().equals("null")) { |
| | | try { |
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", ""); |
| | | short sValue = Short.parseShort(cleanedValue.trim()); |
| | | S7control.getinstance().WriteWord(addressList22, Arrays.asList(sValue)); |
| | | System.out |
| | | .println("messageValue:" + Arrays.asList(sValue) + " written to PLC at address " + addressList2); |
| | | } catch (NumberFormatException e) { |
| | | // 如果无法解析为 short 类型,则忽略该部分 |
| | | System.err.println("Could not parse value: " + value); |
| | | } |
| | | } |
| | | } |
| | | customS7Control.WriteWordsToPLC(messageArray, addressList22,8); |
| | | |
| | | |
| | | // 写入第六个地址 |
| | | if (messageArray.getJSONArray(9).size() > 0) { |
| | | Object value = messageArray.getJSONArray(9).get(0); |
| | | if (value != null && !value.toString().equals("null")) { |
| | | try { |
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", ""); |
| | | short sValue = Short.parseShort(cleanedValue.trim()); |
| | | S7control.getinstance().WriteWord(addressList33, Arrays.asList(sValue)); |
| | | System.out |
| | | .println("messageValue:" + Arrays.asList(sValue) + " written to PLC at address " + addressList3); |
| | | } catch (NumberFormatException e) { |
| | | // 如果无法解析为 short 类型,则忽略该部分 |
| | | System.err.println("Could not parse value: " + value); |
| | | } |
| | | } |
| | | } |
| | | customS7Control.WriteWordsToPLC(messageArray, addressList33,9); |
| | | |
| | | // 写入第七个地址 |
| | | if (!mergedList2.isEmpty()) { |
| | |
| | | }
|
| | |
|
| | |
|
| | |
|
| | |
|
| | | @Override
|
| | | public void run() {
|
| | | while (this != null) {
|
| | |
| | | List<String> addressList21 = Arrays.asList(config.getProperty("PLCManualJog.button").split(","));
|
| | |
|
| | |
|
| | |
|
| | |
|
| | | List<Boolean> arraylist = S7control.getinstance().readBits(addressList21);
|
| | |
|
| | | // Boolean[] values1 = { 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));
|
| | |
|
| | |
|
| | |
|
| | | JSONObject jsonObject = new JSONObject();
|
| | |
| | | // WebSocketServer webSocketServer = WebSocketServer.sessionMap.get("ManualJog");
|
| | |
|
| | | if (webserver != null) {
|
| | |
|
| | |
|
| | |
|
| | | List<String> messages = webserver.getMessages();
|
| | |
| | | } |
| | | |
| | | |
| | | |
| | | // 创建一个自定义的 S7 控制器消息处理器对象 |
| | | MessageHandler customS7Control = new MessageHandler(); |
| | | |
| | | |
| | | |
| | | |
| | | public static class PLCBooleanConverter { |
| | |
| | | return binaryShortArray; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | |
| | | // 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); |
| | | customS7Control.WriteWordToPLC(messageArray, waddresses1, 0); |
| | | |
| | | |
| | | System.out.println("Values " + sValue + " written to PLC at address " + waddresses1); |
| | | } |
| | | } |
| | | |
| | | // 写入A02 |
| | | customS7Control.WriteWordToPLC(messageArray, waddresses2, 1); |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | // 写入B01 |
| | | 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); |
| | | } |
| | | } |
| | | customS7Control.WriteWordToPLC(messageArray, waddresses3, 2); |
| | | |
| | | // 写入B02 |
| | | if (messageArray.getJSONArray(3).size() > 0) { |
| | | JSONArray jsonArray = messageArray.getJSONArray(3); |
| | | 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(waddresses4, sValue2); |
| | | customS7Control.WriteWordToPLC(messageArray, waddresses4, 3); |
| | | |
| | | System.out.println("Values " + sValue2 + " written to PLC at address " + waddresses4); |
| | | } |
| | | } |
| | | |
| | | // 写入故障地址 |
| | | if (messageArray.getJSONArray(4).size() > 0) { |
| | | JSONArray jsonArray = messageArray.getJSONArray(4); |
| | | 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(waddresses5, sValue2); |
| | | System.out.println("Values " + sValue2 + " written to PLC at address " + waddresses5); |
| | | } |
| | | } |
| | | |
| | | customS7Control.writeBitToPLC(messageArray, waddresses5, 4); |
| | | |
| | | |
| | | // 写入复位地址 |
| | | if (messageArray.getJSONArray(5).size() > 0) { |
| | | JSONArray jsonArray3 = messageArray.getJSONArray(5); |
| | | List<Boolean> sValue3 = new ArrayList<>(); |
| | | for (int i = 0; i < jsonArray3.size(); i++) { |
| | | Object value = jsonArray3.get(i); |
| | | if (value != null && !value.toString().equals("null")) { |
| | | try { |
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", ""); |
| | | boolean val = "1".equals(cleanedValue.trim()); |
| | | sValue3.add(val); |
| | | System.out.println("messageValue: " + Arrays.asList(val) + " added to the list"); |
| | | } catch (NumberFormatException e) { |
| | | // 如果无法解析为 boolean 类型,则忽略该部分 |
| | | System.err.println("Could not parse value: " + value); |
| | | } |
| | | } |
| | | } |
| | | if (!sValue3.isEmpty()) { |
| | | S7control.getinstance().WriteBit(waddresses6, sValue3); |
| | | System.out.println("Values " + sValue3 + " written to PLC at address " + waddresses6); |
| | | } |
| | | } |
| | | customS7Control.writeBitToPLC(messageArray, waddresses6, 5); |
| | | |
| | | // 写入回零地址 |
| | | if (messageArray.getJSONArray(6).size() > 0) { |
| | | JSONArray jsonArray3 = messageArray.getJSONArray(6); |
| | | List<Boolean> sValue3 = new ArrayList<>(); |
| | | for (int i = 0; i < jsonArray3.size(); i++) { |
| | | Object value = jsonArray3.get(i); |
| | | if (value != null && !value.toString().equals("null")) { |
| | | try { |
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", ""); |
| | | boolean val = "1".equals(cleanedValue.trim()); |
| | | sValue3.add(val); |
| | | System.out.println("messageValue: " + Arrays.asList(val) + " added to the list"); |
| | | } catch (NumberFormatException e) { |
| | | // 如果无法解析为 boolean 类型,则忽略该部分 |
| | | System.err.println("Could not parse value: " + value); |
| | | } |
| | | } |
| | | } |
| | | if (!sValue3.isEmpty()) { |
| | | S7control.getinstance().WriteBit(waddresses7, sValue3); |
| | | System.out.println("Values " + sValue3 + " written to PLC at address " + waddresses7); |
| | | } |
| | | } |
| | | |
| | | customS7Control.writeBitToPLC(messageArray, waddresses7, 6); |
| | | //A01启动 |
| | | customS7Control.writeBitToPLC( messageArray, A01start,7); |
| | | //A02启动 |
| | | customS7Control.writeBitToPLC( messageArray, A02start,8); |
| | | //B01启动 |
| | | customS7Control.writeBitToPLC( messageArray,B01start,9); |
| | | //B02启动 |
| | | customS7Control.writeBitToPLC( messageArray, B02start,10); |
| | | |
| | | // 清空消息列表 |
| | | webserver.clearMessages(); |
| | | } |
| | | }} |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | |
|
| | |
|
| | | MessageHandler customS7Control = new MessageHandler();
|
| | |
|
| | | public static class PLCBooleanConverter {
|
| | |
|
| | | public static short[] convertListsToBinaryShortArray(List<Boolean>... lists) {
|
| | |
| | | return binaryShortArray;
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | |
|
| | | @Override
|
| | |
| | | }
|
| | |
|
| | |
|
| | |
|
| | | //A01启动地址
|
| | | List<String> A01start = Arrays.asList(config.getProperty("mlp2.A01start"));
|
| | | //A02启动地址
|
| | | List<String> A02start = Arrays.asList(config.getProperty("mlp2.A02start"));
|
| | |
|
| | |
|
| | |
|
| | | List<Boolean> A01readstart = S7control.getinstance().readBits(A01start);
|
| | |
| | | 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);
|
| | | customS7Control.WriteWordToPLC(messageArray, waddresses1, 0);
|
| | |
|
| | | 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);
|
| | | customS7Control.WriteWordToPLC(messageArray, waddresses2, 1);
|
| | |
|
| | | 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);
|
| | | }
|
| | | }
|
| | | customS7Control.WriteWordToPLC(messageArray, waddresses3, 2);
|
| | |
|
| | |
|
| | | // 写入复位地址
|
| | | if (messageArray.getJSONArray(3).size() > 0) {
|
| | | JSONArray jsonArray3 = messageArray.getJSONArray(3);
|
| | | List<Boolean> sValue3 = new ArrayList<>();
|
| | | for (int i = 0; i < jsonArray3.size(); i++) {
|
| | | Object value = jsonArray3.get(i);
|
| | | if (value != null && !value.toString().equals("null")) {
|
| | | try {
|
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", "");
|
| | | boolean val = "1".equals(cleanedValue.trim());
|
| | | sValue3.add(val);
|
| | | System.out.println("messageValue: " + Arrays.asList(val) + " added to the list");
|
| | | } catch (NumberFormatException e) {
|
| | | // 如果无法解析为 boolean 类型,则忽略该部分
|
| | | System.err.println("Could not parse value: " + value);
|
| | | }
|
| | | }
|
| | | }
|
| | | if (!sValue3.isEmpty()) {
|
| | | S7control.getinstance().WriteBit(waddresses4, sValue3);
|
| | | System.out.println("Values " + sValue3 + " written to PLC at address " + waddresses4);
|
| | | }
|
| | | }
|
| | | customS7Control.writeBitToPLC(messageArray, waddresses4, 3);
|
| | |
|
| | |
|
| | | // 写入回零地址
|
| | | if (messageArray.getJSONArray(4).size() > 0) {
|
| | | JSONArray jsonArray3 = messageArray.getJSONArray(4);
|
| | | List<Boolean> sValue3 = new ArrayList<>();
|
| | | for (int i = 0; i < jsonArray3.size(); i++) {
|
| | | Object value = jsonArray3.get(i);
|
| | | if (value != null && !value.toString().equals("null")) {
|
| | | try {
|
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", "");
|
| | | boolean val = "1".equals(cleanedValue.trim());
|
| | | sValue3.add(val);
|
| | | System.out.println("messageValue: " + Arrays.asList(val) + " added to the list");
|
| | | } catch (NumberFormatException e) {
|
| | | // 如果无法解析为 boolean 类型,则忽略该部分
|
| | | System.err.println("Could not parse value: " + value);
|
| | | }
|
| | | }
|
| | | }
|
| | | if (!sValue3.isEmpty()) {
|
| | | S7control.getinstance().WriteBit(waddresses5, sValue3);
|
| | | System.out.println("Values " + sValue3 + " written to PLC at address " + waddresses5);
|
| | | }
|
| | | }
|
| | |
|
| | | customS7Control.writeBitToPLC(messageArray, waddresses5, 4);
|
| | |
|
| | | customS7Control.writeBitToPLC( messageArray, A01start,5);
|
| | | customS7Control.writeBitToPLC( messageArray, A02start,6);
|
| | |
| | | import java.util.List; |
| | | |
| | | public class PlcParameter1 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(); |
| | | } |
| | | } |
| | | MessageHandler customS7Control = new MessageHandler(); |
| | | |
| | | @Override |
| | | public void run() { |
| | |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // this.readValue(); |
| | | // String PlcAddress = this.name; |
| | | // Integer Plccount = this.count; |
| | | |
| | | |
| | | // System.out.println(stt); |
| | | List<String> addresses = new ArrayList<>(); |
| | |
| | | } |
| | | |
| | | // 写入第一个地址 |
| | | if (messageArray.getJSONArray(3).size() > 0) { |
| | | Object value = messageArray.getJSONArray(3).get(0); |
| | | if (value != null && !value.toString().equals("null")) { |
| | | try { |
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", ""); |
| | | short sValue = Short.parseShort(cleanedValue.trim()); |
| | | S7control.getinstance().WriteWord(addressList2, Arrays.asList(sValue)); |
| | | System.out |
| | | .println("messageValue:" + Arrays.asList(sValue) + " written to PLC at address " + addressList2); |
| | | } catch (NumberFormatException e) { |
| | | // 如果无法解析为 short 类型,则忽略该部分 |
| | | System.err.println("Could not parse value: " + value); |
| | | } |
| | | } |
| | | } |
| | | customS7Control.WriteWordsToPLC(messageArray, addressList2, 3); |
| | | |
| | | |
| | | // 写入第二个地址 |
| | | if (messageArray.getJSONArray(4).size() > 0) { |
| | | Object value = messageArray.getJSONArray(4).get(0); |
| | | if (value != null && !value.toString().equals("null")) { |
| | | try { |
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", ""); |
| | | short sValue = Short.parseShort(cleanedValue.trim()); |
| | | S7control.getinstance().WriteWord(addressList3, Arrays.asList(sValue)); |
| | | System.out |
| | | .println("messageValue:" + Arrays.asList(sValue) + " written to PLC at address " + addressList3); |
| | | } catch (NumberFormatException e) { |
| | | // 如果无法解析为 short 类型,则忽略该部分 |
| | | System.err.println("Could not parse value: " + value); |
| | | } |
| | | } |
| | | } |
| | | customS7Control.WriteWordsToPLC(messageArray, addressList3, 4); |
| | | |
| | | |
| | | // 写入第三个地址 |
| | | if (!mergedList.isEmpty()) { |
| | |
| | | |
| | | |
| | | public class PlcParameter2 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; |
| | | } |
| | | // 创建一个自定义的 S7 控制器消息处理器对象 |
| | | MessageHandler customS7Control = new MessageHandler(); |
| | | |
| | | // 将str字符串格式转为json |
| | | JSONObject jsonObject = new JSONObject(str); |
| | | |
| | | // 获取json中的值 |
| | | JSONArray address = jsonObject.getJSONArray("Positioning1"); |
| | | 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() { |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | // 手动状态地址 |
| | | // id |
| | | List<String> addressList1 = new ArrayList<>(); |
| | | |
| | | addressList1.add("DB103.44");//D01 |
| | |
| | | List<String> paramlist = S7control.getinstance().readStrings(addressList1); |
| | | |
| | | |
| | | //清除ID地址 |
| | | //手动状态 |
| | | List<String> addresses = new ArrayList<>(); |
| | | addresses.add("DB103.0"); |
| | | addresses.add("DB103.2"); |
| | |
| | | List<Short> data = S7control.getinstance().readWords(addresses); |
| | | |
| | | |
| | | //id |
| | | //清除id |
| | | List<String> addressList0 = new ArrayList<>(); |
| | | |
| | | addressList0.add("DB101.9.2"); |
| | |
| | | addressList3.add("DB103.270"); |
| | | |
| | | |
| | | |
| | | |
| | | List<String> niuanaddressList3 = new ArrayList<>(); |
| | | |
| | | niuanaddressList3.add("DB101.10.4"); |
| | | List<Boolean> anniuread = S7control.getinstance().readBits(niuanaddressList3); |
| | | |
| | | |
| | | |
| | | List<String> data3 = S7control.getinstance().readStrings(addressList3); |
| | |
| | | |
| | | |
| | | // |
| | | |
| | | |
| | | |
| | | // |
| | |
| | | String lastMessage = messages.get(messages.size() - 1); |
| | | // System.out.println("lastMessage:" + lastMessage); |
| | | JSONArray messageArray = new JSONArray(lastMessage); |
| | | |
| | | if (messageArray.getJSONArray(0).size() > 0) { |
| | | JSONArray jsonArray3 = messageArray.getJSONArray(0); |
| | | List<Boolean> sValue3 = new ArrayList<>(); |
| | | for (int i = 0; i < jsonArray3.size(); i++) { |
| | | Object value = jsonArray3.get(i); |
| | | if (value != null && !value.toString().equals("null")) { |
| | | try { |
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", ""); |
| | | boolean val = "1".equals(cleanedValue.trim()); |
| | | sValue3.add(val); |
| | | System.out.println("messageValue: " + Arrays.asList(val) + " added to the list"); |
| | | } catch (NumberFormatException e) { |
| | | // 如果无法解析为 boolean 类型,则忽略该部分 |
| | | System.err.println("Could not parse value: " + value); |
| | | } |
| | | } |
| | | } |
| | | if (!sValue3.isEmpty()) { |
| | | S7control.getinstance().WriteBit(addressList, sValue3); |
| | | System.out.println("Values " + sValue3 + " written to PLC at address " + addressList); |
| | | } |
| | | } |
| | | // 将布尔列表写入 PLC |
| | | if (messageArray.getJSONArray(1).size() > 0) { |
| | | JSONArray jsonArray3 = messageArray.getJSONArray(1); |
| | | List<Boolean> sValue3 = new ArrayList<>(); |
| | | for (int i = 0; i < jsonArray3.size(); i++) { |
| | | Object value = jsonArray3.get(i); |
| | | if (value != null && !value.toString().equals("null")) { |
| | | try { |
| | | String cleanedValue = value.toString().replaceAll("[^0-9-]", ""); |
| | | boolean val = "1".equals(cleanedValue.trim()); |
| | | sValue3.add(val); |
| | | System.out.println("messageValue: " + Arrays.asList(val) + " added to the list"); |
| | | } catch (NumberFormatException e) { |
| | | // 如果无法解析为 boolean 类型,则忽略该部分 |
| | | System.err.println("Could not parse value: " + value); |
| | | } |
| | | } |
| | | } |
| | | if (!sValue3.isEmpty()) { |
| | | S7control.getinstance().WriteBit(niuanaddressList3, sValue3); |
| | | |
| | | System.out.println("Values " + sValue3 + " written to PLC at address " + sValue3); |
| | | } |
| | | } |
| | | //清除ID |
| | | customS7Control.writeBitToPLC(messageArray, addressList, 0); |
| | | //急停 |
| | | customS7Control.writeBitToPLC(messageArray, niuanaddressList3, 1); |
| | | |
| | | |
| | | // 清空消息列表 |
| | |
| | | import org.apache.commons.io.FileUtils;
|
| | |
|
| | | public class PlcPositioning1 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("Positioning1");
|
| | | for (int i = 0; i < address.size(); i++) {
|
| | | JSONObject ress = (JSONObject) address.get(i);
|
| | |
|
| | | this.name = ress.getStr("name");
|
| | | this.count = ress.getInt("count");
|
| | | System.out.println("messageValues:" + this.name);
|
| | | System.out.println("messageValues:" + this.count);
|
| | | }
|
| | |
|
| | | } catch (FileNotFoundException e) {
|
| | | e.printStackTrace();
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void run() {
|
| | |
| | | } catch (InterruptedException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | // this.readValue();
|
| | | // String PlcAddress = this.name;
|
| | | // Integer Plccount = this.count;
|
| | |
|
| | |
|
| | | // System.out.println(stt);
|
| | | //存片格 出片格读取
|
| | |
| | | import java.util.List;
|
| | |
|
| | | public class PlcPositioning2 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("Positioning2");
|
| | | for (int i = 0; i < address.size(); i++) {
|
| | | JSONObject ress = (JSONObject) address.get(i);
|
| | |
|
| | | this.name = ress.getStr("name");
|
| | | this.count = ress.getInt("count");
|
| | | System.out.println("messageValues:" + this.name);
|
| | | System.out.println("messageValues:" + this.count);
|
| | | }
|
| | |
|
| | | } catch (FileNotFoundException e) {
|
| | | e.printStackTrace();
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void run() {
|
| | |
| | | } |
| | | |
| | | |
| | | |
| | | //A01组合中地址表集合 |
| | | List<String> addresses = Arrays.asList(config.getProperty("A01.addresses").split(",")); |
| | | //System.out.println(addresses); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | // Short[] values1 = { 1, 2, 3, 4, 5, 6, 7}; |
| | | // List<Short> arraylist = new ArrayList<>(Arrays.asList(values1)); |
| | | // Short[] values2 = { 1, 2, 3, 4, 5}; |
| | |
| | | jsonObject.append("resumeTasks", resumeTask); |
| | | |
| | | |
| | | |
| | | // WebSocketServer sendwServer = WebSocketServer.sessionMap.get("ServoManualone"); |
| | | // if (sendwServer != null) { |
| | | // sendwServer.sendMessage(jsonObject.toString()); |
| | |
| | | // 写入AO1组合 |
| | | customS7Control.WriteWordToPLC(messageArray, addresses,0); |
| | | |
| | | //A01半自动启动 |
| | | customS7Control.writeBitToPLC( messageArray, A01start,8); |
| | | |
| | | |
| | | // 写入AO2组合 |
| | | customS7Control.WriteWordToPLC(messageArray, addresses2,1); |
| | | //A02半自动启动 |
| | | |
| | | customS7Control.writeBitToPLC( messageArray, A02start,9); |
| | | |
| | | |
| | | |
| | | // 复位按钮写入 |
| | |
| | | |
| | | //A01半自动 |
| | | customS7Control.writeBitToPLC( messageArray, A01Bstart,6); |
| | | |
| | | //A02半自动 |
| | | customS7Control.writeBitToPLC( messageArray, A02Bstart,7); |
| | | //A01半自动启动 |
| | | customS7Control.writeBitToPLC(messageArray, A01start, 8); |
| | | //A02半自动启动 |
| | | customS7Control.writeBitToPLC(messageArray, A02start, 9); |
| | | |
| | | |
| | | |
| | |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | |
| | | } |
| | | |
| | | } |
| | | // 将获取的布尔类型转换为整数类型 |
| | | List<Integer> Intlist = new ArrayList<>(); |
| | | for (Boolean value : plclist) { |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | |
|
| | |
|
| | |
|
| | | #PLCManualJog--------------------------
|
| | |
|
| | |
|
| | |
|
| | |
| | | #id
|
| | | Parameter2.id=DB103.44,DB103.58,DB103.72,DB103.86,DB103.100,DB103.114,DB103.128,DB103.142,DB103.156,DB103.184,DB103.212
|
| | |
|
| | | #清除id
|
| | | #state
|
| | | Parameter2.state=DB103.0,DB103.2,DB103.12,DB103.14,DB103.16,DB103.18,DB103.8,DB103.10,DB103.4,DB103.6
|
| | |
|
| | |
|
| | |
|
| | | #手动状态
|
| | | #清除id
|
| | | Parameter2.cleanid=DB101.9.2,DB101.9.3,DB101.9.4,DB101.9.5,DB101.9.6,DB101.9.7,DB101.10.0,DB101.10.1,DB101.10.2,DB101.10.3
|
| | | #扫码枪
|
| | | Parameter2.scanner=DB103.256,DB103.270
|
| | |
|
| | | #急停
|
| | | Parameter2.stop=DB101.10.4
|
| | |
|
| | | #当前格子
|
| | | Parameter2.Currentcell=DB103.32,DB103.34,DB103.36,DB103.40
|
| | |
|