zoukankan      html  css  js  c++  java
  • 成功

    byte[] RxBuffer;
    int length = 12; //结构体长度
    void pt_DataReceived(object sender, PortDataReciveEventArgs e)
    {
    int loopIndex = 0;
    byte[] data = new byte[length];
    byte[] totaldata;
    //如果上次接收有剩余的数据,拼接到e.Data最前面,清空剩余数组
    if (RxBuffer!=null)
    {
    totaldata = new byte[e.Data.Length + RxBuffer.Length];
    Buffer.BlockCopy(RxBuffer, 0, totaldata, 0, RxBuffer.Length);
    Buffer.BlockCopy(e.Data, 0, totaldata, RxBuffer.Length, e.Data.Length);
    RxBuffer = null;
    }
    else
    {
    totaldata = e.Data;
    }

    int loopnum = totaldata.Length / length;//循环次数
    int remainnum = totaldata.Length % length;//剩余个数

    SampRepInfor samp = new SampRepInfor();
    DataTable newTable;
    byte[] redata=new byte[remainnum];//剩余数据

    if (totaldata.Length>= length)
    {
    while (loopIndex < loopnum)
    {
    Buffer.BlockCopy(totaldata, loopIndex*length, data, 0, data.Length);
    UI.UIAction(() =>
    {
    samp = BytesToParaHelper.BytesToPara(data);
    newTable = dt.Copy();
    Table = ParaToDataTableHelper.ConvertToDataTable(samp, newTable);
    dt = newTable.Copy();
    });
    loopIndex++;
    }

    if (remainnum > 0)//存在剩余数据,存入剩余数组中
    {
    Buffer.BlockCopy(totaldata, loopnum * length, redata, 0, remainnum);
    RxBuffer = redata;//放入剩余数据
    }
    }

    }

  • 相关阅读:
    BugReport-仿微信app
    成长、责任、和公司的关系
    团队如何做决定
    课堂练习
    课堂练习
    NABCD model
    课堂练习
    日程管理测试用例
    测试
    Bug报告
  • 原文地址:https://www.cnblogs.com/MiLu/p/6644317.html
Copyright © 2011-2022 走看看