using System;
using System.Collections.Generic;
namespace MCProtocol
{
internal class Frame
{
private struct CompleteCode
{
public const int NoData = 0xF000;
public const int InvalidData = 0xF001;
}
private const byte _PCNo = 0xff;
private const byte _IONo_L = 0xff;//0x03ff
private const byte _IONo_H = 0x03;//0x03ff
private const byte _CPUTimer_L = 0x10;//0x0010
private const byte _CPUTimer_H = 0x00;
private const int _receiceDataMinimumBytes = 11;
private readonly byte _networkNo = 0x00;
private readonly byte _stationNo = 0x00;
public readonly int MaximumWords = 960;
public Frame3E(int networkNo = 0, int stationNo = 0)
{
_networkNo = (byte)networkNo;
_stationNo = (byte)stationNo;
}
private byte[] CreateFrame(int mainCmd, int subCmd, int address, byte deviceCode, int size, IReadOnlyCollection<byte> data)
{
int dataLength = 12 + data.Count;
var frame = new List<byte>()
{
0x50, 0x00, //3E Frame
_networkNo,
_PCNo,
_IONo_L,
_IONo_H,
_stationNo,
(byte)(dataLength % 256),
(byte)(dataLength / 256),
_CPUTimer_L , _CPUTimer_H,
(byte)mainCmd, (byte)(mainCmd &g

该代码定义了一个内部类Frame,用于创建和解析特定格式的数据帧。主要方法包括创建读写词帧(ReadWordsFrame,WriteWordsFrame)、读写位帧(ReadBitFrame,WriteBitFrame)以及解析返回帧。类中包含常量定义了帧结构的各个部分,如网络号、站号、地址等,并有用于验证接收数据完整性的方法。
最低0.47元/天 解锁文章
1023

被折叠的 条评论
为什么被折叠?



