• 大小: 50KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-28
  • 语言: Java
  • 标签:

资源简介

dlt645-2007电能表协议解析源码+串口编程源码,利用串口编程直接与电能表通信,Java源码

资源截图

代码片段和文件信息

import java.io.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * Created by WuSong
 * 2017-05-02
 */
public class AgreementDemo {
    public void analysis(String command) throws Exception {
        String[] commands=command.trim().split(“ “);
        List list =new ArrayList();
        for (int i = 0; i             if (!commands[i].equalsIgnoreCase(“FE“)){
                list.add(commands[i]);
            }
        }
        //解析报文格式
        String[] newCommands=list.toArray(new String[list.size()]);
        /*for (int i = 0; i < newCommands.length; i++) {
            //System.out.println(Integer.parseInt(newCommands[newCommands.length-1]));
            System.out.print(newCommands[i]+“ “);
        }*/

        if (newCommands.length<16||newCommands.length>22||Integer.parseInt(newCommands[0])!=68||Integer.parseInt(newCommands[newCommands.length-1])!=16){
            System.err.print(“非法帧,无法解析!“);
            return;
        }else {

            System.out.println(“您的输入:“ + command);
            System.out.println(“原始地址:“ + list);
            System.out.println(“帧起始符:“ + newCommands[0]);
            System.out.println(“电表地址:“ + Byte.parseByte(newCommands[6]) + Byte.parseByte(newCommands[5]) + Byte.parseByte(newCommands[4]) + Byte.parseByte(newCommands[3]) + Byte.parseByte(newCommands[2]) + Byte.parseByte(newCommands[1]));
            System.out.println(“控制域:“ + newCommands[8]);
            System.out.println(“数据域长度:“ + newCommands[9]);
            System.out.println(“校验码:“ + newCommands[newCommands.length - 2]);
            System.out.println(“停止位:“ + newCommands[newCommands.length - 1]);

            //int DTID=newCommands[newCommands.length - 2 - newCommands[9]];
            //解析数据标识
            List list2 = new ArrayList();
            for (int i = 0; i < 4; i++) {
                list2.add(Integer.toHexString(Integer.parseInt(newCommands[newCommands.length - 3 - i-(Integer.parseInt(newCommands[9]16)-4)] 16) - 51));
            }
            String[] DTID = list2.toArray(new String[list2.size()]);
            StringBuffer sbr = new StringBuffer();
            for (int i = 0; i < DTID.length; i++) {
                if (DTID[i].length() == 1) {
                    DTID[i] = String.format(“%02d“ Integer.parseInt(DTID[i]));
                }else if (DTID[i].length() == 8){
                    DTID[i] = “FF“;
                }
                sbr.append(DTID[i]);
            }

            //InputStream is=this.getClass().getClassLoader().getResourceAsStream(“resource/config.properties“);
            //加载文件,取值
            InputStream is = new BufferedInputStream(new FileInputStream(“src/config.properties“));
            InputStreamReader isr = new InputStreamReader(is “GBK“);
            Properties properties = new Properties();
            try {
          

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件         28  2017-05-09 17:43  Agreement_wu\.git\COMMIT_EDITMSG

     文件        312  2017-05-09 17:42  Agreement_wu\.git\config

     文件         73  2017-05-05 09:36  Agreement_wu\.git\description

     文件        121  2017-05-09 17:43  Agreement_wu\.git\FETCH_HEAD

     文件         23  2017-05-05 09:36  Agreement_wu\.git\HEAD

     文件        478  2017-05-05 09:36  Agreement_wu\.git\hooks\applypatch-msg.sample

     文件        896  2017-05-05 09:36  Agreement_wu\.git\hooks\commit-msg.sample

     文件        189  2017-05-05 09:36  Agreement_wu\.git\hooks\post-update.sample

     文件        424  2017-05-05 09:36  Agreement_wu\.git\hooks\pre-applypatch.sample

     文件       1642  2017-05-05 09:36  Agreement_wu\.git\hooks\pre-commit.sample

     文件       1348  2017-05-05 09:36  Agreement_wu\.git\hooks\pre-push.sample

     文件       4951  2017-05-05 09:36  Agreement_wu\.git\hooks\pre-rebase.sample

     文件        544  2017-05-05 09:36  Agreement_wu\.git\hooks\pre-receive.sample

     文件       1239  2017-05-05 09:36  Agreement_wu\.git\hooks\prepare-commit-msg.sample

     文件       3610  2017-05-05 09:36  Agreement_wu\.git\hooks\update.sample

     文件        437  2017-05-09 17:43  Agreement_wu\.git\index

     文件        240  2017-05-05 09:36  Agreement_wu\.git\info\exclude

     文件        323  2017-05-09 17:43  Agreement_wu\.git\logs\HEAD

     文件        323  2017-05-09 17:43  Agreement_wu\.git\logs\refs\heads\master

     文件        433  2017-05-09 17:44  Agreement_wu\.git\logs\refs\remotes\origin\master

     文件       2599  2017-05-05 09:37  Agreement_wu\.git\objects\14\0afd426a32cd787a1eacbe008d5c06a6f5c1f7

     文件        972  2017-05-05 09:37  Agreement_wu\.git\objects\2c\64901d2b747cb5c7c3f71e90c95e1ea648d82d

     文件        164  2017-05-09 17:43  Agreement_wu\.git\objects\33\b2e42705becf5cc09cd5315e8ab75ef07557db

     文件        128  2017-05-05 09:39  Agreement_wu\.git\objects\40\84a2d6552e07d165987fb237d69932b03fb61e

     文件        196  2017-05-09 17:43  Agreement_wu\.git\objects\58\9f5069bb12bc9223d9c23767350d33b6d7ff5f

     文件         82  2017-05-05 09:39  Agreement_wu\.git\objects\74\75067238de5d4395049fd9a4c8a70deb3deea8

     文件       1688  2017-05-05 09:37  Agreement_wu\.git\objects\77\59d8043d9891cd2098a5c405aa2988122902c1

     文件         54  2017-05-05 09:39  Agreement_wu\.git\objects\7b\aacf35ece4de30faec1627be54a3e023714ef4

     文件        126  2017-05-05 09:38  Agreement_wu\.git\objects\84\4f8e8266500bc37d0ce7d00946cf9e96e61680

     文件        510  2017-05-05 09:37  Agreement_wu\.git\objects\95\adf7912e4f9a10e9aba9843e57dee89ae27fca

............此处省略71个文件信息

评论

共有 条评论

相关资源