/// <summary>
 /// 分析地址的方法,允许派生类里进行重写操作
 /// </summary>
 /// <param name="address">地址信息</param>
 /// <returns>解析后的数据信息</returns>
 protected virtual OperateResult <MelsecMcDataType, int> McAnalysisAddress(string address)
 {
     return(MelsecHelper.McAnalysisAddress(address));
 }
Ejemplo n.º 2
0
        private byte[] ReadByCommand(byte[] command)
        {
            if (command[2] == 0x01)
            {
                // 位读取
                ushort length     = ByteTransform.TransUInt16(command, 8);
                int    startIndex = (command[6] * 65536 + command[5] * 256 + command[4]);

                if (command[7] == MelsecMcDataType.M.DataCode)
                {
                    byte[] buffer = mBuffer.GetBytes(startIndex, length);
                    return(MelsecHelper.TransBoolArrayToByteData(buffer));
                }
                else if (command[7] == MelsecMcDataType.X.DataCode)
                {
                    byte[] buffer = xBuffer.GetBytes(startIndex, length);
                    return(MelsecHelper.TransBoolArrayToByteData(buffer));
                }
                else if (command[7] == MelsecMcDataType.Y.DataCode)
                {
                    byte[] buffer = yBuffer.GetBytes(startIndex, length);
                    return(MelsecHelper.TransBoolArrayToByteData(buffer));
                }
                else
                {
                    throw new Exception(StringResources.Language.NotSupportedDataType);
                }
            }
            else
            {
                // 字读取
                ushort length     = ByteTransform.TransUInt16(command, 8);
                int    startIndex = (command[6] * 65536 + command[5] * 256 + command[4]);
                if (command[7] == MelsecMcDataType.M.DataCode)
                {
                    bool[] buffer = mBuffer.GetBytes(startIndex, length * 16).Select(m => m != 0x00).ToArray( );
                    return(SoftBasic.BoolArrayToByte(buffer));
                }
                else if (command[7] == MelsecMcDataType.X.DataCode)
                {
                    bool[] buffer = xBuffer.GetBytes(startIndex, length * 16).Select(m => m != 0x00).ToArray( );
                    return(SoftBasic.BoolArrayToByte(buffer));
                }
                else if (command[7] == MelsecMcDataType.Y.DataCode)
                {
                    bool[] buffer = yBuffer.GetBytes(startIndex, length * 16).Select(m => m != 0x00).ToArray( );
                    return(SoftBasic.BoolArrayToByte(buffer));
                }
                else if (command[7] == MelsecMcDataType.D.DataCode)
                {
                    return(dBuffer.GetBytes(startIndex * 2, length * 2));
                }
                else if (command[7] == MelsecMcDataType.W.DataCode)
                {
                    return(wBuffer.GetBytes(startIndex * 2, length * 2));
                }
                else
                {
                    throw new Exception(StringResources.Language.NotSupportedDataType);
                }
            }
        }