| package com.dy.pipirrComCreator.p206V1; | 
|   | 
| import com.dy.common.mw.protocol.p206V1.parse.global.GlCreate; | 
| import com.dy.common.util.ByteUtil; | 
| import com.dy.common.util.ByteUtilUnsigned; | 
| import com.dy.common.util.IPUtils; | 
| import com.dy.common.util.NumUtil; | 
|   | 
| /** | 
|  * @Author: liurunyu | 
|  * @Date: 2025/5/7 11:25 | 
|  * @Description | 
|  */ | 
| public class P206V1Cd3C extends P206V1Cd { | 
|   | 
|     public static final String ComCode = "3C" ; | 
|   | 
|     public String checkParams(String ...params){ | 
|         if(params.length != 1){ | 
|             return "只有自报周期一个参数" ; | 
|         } | 
|         if(!NumUtil.isPlusIntNumber(params[0])){ | 
|             return "自报周期必须是正整数" ; | 
|         } | 
|         int cycle = Integer.parseInt(params[0]) ; | 
|         if(cycle < 1 || cycle > 32767){ | 
|             return "自报周期必须在1-32767之间" ; | 
|         } | 
|         return null ; | 
|     } | 
|     public String helpInfo() { | 
|         return ComCode + " *...*[Enter](设置自报周期)" ; | 
|     } | 
|     /** | 
|      * 构造命令数据(十六进制) | 
|      * @return 字符串 | 
|      * @throws Exception 异常 | 
|      */ | 
|     public String hex(String rtuAddr, String ...params) throws Exception { | 
|         byte[] bytes = bs(rtuAddr, params) ; | 
|         return ByteUtil.bytes2Hex(bytes, false) ; | 
|     } | 
|   | 
|     /** | 
|      * 构造命令数据(字节数组) | 
|      * @return 字节数组 | 
|      * @throws Exception 异常 | 
|      */ | 
|     public byte[] bs(String rtuAddr, String ...params) throws Exception { | 
|         byte[] bytes = createHead(rtuAddr, ComCode, P206V1Cd.CTRL); | 
|   | 
|         byte n = 0 ; | 
|         byte[] bs = new byte[10]; | 
|         ByteUtilUnsigned.short2Bytes_LE(bs, Short.parseShort(params[0]), n); | 
|         n += 2; | 
|         GlCreate.createPw(bs, n); | 
|         n += 2; | 
|         GlCreate.createTp(bs, n); | 
|   | 
|         bytes = ByteUtil.bytesMerge(bytes, bs); | 
|   | 
|         GlCreate.createLen(bytes);//长度放字节数组中 | 
|   | 
|         byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC和尾叠加字节数组中 | 
|   | 
|         bytes = ByteUtil.bytesMerge(bytes, bsTail) ; | 
|   | 
|         return bytes ; | 
|     } | 
|   | 
|     public static void main(String[] args) throws Exception { | 
|         String[] ps = new String[]{"1.2.3.4", "123"} ; | 
|         new P206V1Cd3C().hex("530115059980", ps) ; | 
|     } | 
| } |