| | |
| | | |
| | | } |
| | | |
| | | |
| | | //一次读取行为 |
| | | String once(){ |
| | | //按照配置读数据 |
| | |
| | | String flag=null; |
| | | String messsage="000000000000000000"; |
| | | EPlcType ePlcType=null; |
| | | if(this.machineID==4){ |
| | | ePlcType=EPlcType.S1500; |
| | | }else if(this.machineID==6){ |
| | | if(this.functionType==10){ |
| | | ePlcType=EPlcType.S200_SMART; |
| | | }else{ |
| | | }else if(this.functionType==11){ |
| | | ePlcType=EPlcType.S1500; |
| | | }else if(this.functionType==12){ |
| | | ePlcType=EPlcType.S1200; |
| | | }else{ |
| | | return ""; |
| | | } |
| | | S7control s7=new S7control(ePlcType, ip, port, 0, 0); |
| | | //List<Integer> word=s7.readWord("DB34.122", 1); |
| | | List<Integer> listWord=s7.readWord(this.remarks,(this.readSize/2)); |
| | | if(listWord==null){ |
| | | System.out.println("notread"); |
| | | return ""; |
| | | } |
| | | for(int i=0;i<listWord.size();i++){ |
| | | //System.out.println("i "+listWord.size()+" "+messsage); |
| | | messsage+=HexUtil.intTo2ByteHex(listWord.get(i)); |
| | | } |
| | | |
| | | //System.out.println(messsage); |
| | | //System.out.println(ip+" "+s7.readWord("DB34.122", 1)); |
| | | //数据库 |
| | | DBHelper db=DBHelper.getDBHelper("mes"); |
| | | try{ |
| | |
| | | //得到存储过程返回的值,数组第一个为地址,第二个为值 |
| | | int resultsLength=results.length; |
| | | int resultsSize=resultsLength/2; |
| | | |
| | | for(int i=1;i<resultsSize+1;i++){ |
| | | int addressIndex=(i-1)*2; |
| | | int valueIndex=i*2-1; |
| | | s7.writeWord(results[addressIndex],Integer.valueOf(results[valueIndex]));//参数组写入 |
| | | } |
| | | // if(results.length==2){ |
| | | // s7.writeWord(results[0],Integer.valueOf(results[1]) ); |
| | | // } |
| | | // if(results.length==4){ |
| | | // s7.writeWord(results[0],Integer.valueOf(results[1]));//配方 |
| | | // s7.writeWord(results[2],Integer.valueOf(results[3]));//速度 |
| | | // } |
| | | List<Integer> listWord2=s7.readWord(this.remarks,(this.readSize/2)); |
| | | System.out.println(listWord2.size()); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | catch(Exception e){ |
| | | e.printStackTrace(); |