private byte[] WriteByMessage(byte[] packCommand)
 {
     if (packCommand[22] == 0x02)
     {
         // 字写入
         int count = ByteTransform.TransInt16(packCommand, 23);
         int startIndex = (packCommand[28] * 65536 + packCommand[29] * 256 + packCommand[30]) / 8;
         byte[] data = ByteTransform.TransByte(packCommand, 35, count);
         switch (packCommand[27])
         {
             case 0x81: inputBuffer.SetBytes(data, startIndex); break;
             case 0x82: outputBuffer.SetBytes(data, startIndex); break;
             case 0x83: memeryBuffer.SetBytes(data, startIndex); break;
             case 0x84: dbBlockBuffer.SetBytes(data, startIndex); break;
             default: throw new Exception(StringResources.Language.NotSupportedDataType);
         }
         return SoftBasic.HexStringToBytes("03 00 00 16 02 F0 80 32 03 00 00 00 01 00 02 00 01 00 00 05 01 FF");
     }
     else
     {
         // 位写入
         int startIndex = packCommand[28] * 65536 + packCommand[29] * 256 + packCommand[30];
         bool value = packCommand[35] != 0x00;
         switch (packCommand[27])
         {
             case 0x81: inputBuffer.SetBool(value, startIndex); break;
             case 0x82: outputBuffer.SetBool(value, startIndex); break;
             case 0x83: memeryBuffer.SetBool(value, startIndex); break;
             case 0x84: dbBlockBuffer.SetBool(value, startIndex); break;
             default: throw new Exception(StringResources.Language.NotSupportedDataType);
         }
         return SoftBasic.HexStringToBytes("03 00 00 16 02 F0 80 32 03 00 00 00 01 00 02 00 01 00 00 05 01 FF");
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 读取设备的short类型的数组
        /// </summary>
        /// <param name="address">起始地址</param>
        /// <param name="length">数组长度</param>
        /// <returns>带成功标志的结果数据对象</returns>
        public OperateResult <short[]> ReadInt16(string address, ushort length)
        {
            OperateResult <byte[]> read = Read(address, (ushort)(length * WordLength));

            if (!read.IsSuccess)
            {
                return(OperateResult.CreateFailedResult <short[]>(read));
            }
            return(OperateResult.CreateSuccessResult(ByteTransform.TransInt16(read.Content, 0, length)));
        }
Esempio n. 3
0
 /// <summary>
 /// 读取PLC的short类型的数组 -> Read an array of the short type of the PLC
 /// </summary>
 /// <param name="address">节点的名称 -> Name of the node </param>
 /// <param name="length">数组长度 -> Array length </param>
 /// <returns>带有结果对象的结果数据 -> Result data with result info </returns>
 /// <example>
 /// 以下为三菱的连接对象示例,其他的设备读写情况参照下面的代码:
 /// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Core\NetworkDeviceBase.cs" region="ReadInt16Array" title="Int16类型示例" />
 /// </example>
 public override OperateResult <short[]> ReadInt16(string address, ushort length)
 {
     return(ByteTransformHelper.GetResultFromBytes(Read(address, length), m => ByteTransform.TransInt16(m, 0, length)));
 }
Esempio n. 4
0
 /// <summary>
 /// 读取设备的short类型的数组
 /// </summary>
 /// <param name="address">起始地址</param>
 /// <param name="length">数组长度</param>
 /// <returns>带成功标志的结果数据对象</returns>
 /// <example>
 /// 以下为三菱的连接对象示例,其他的设备读写情况参照下面的代码:
 /// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Core\NetworkDeviceBase.cs" region="ReadInt16Array" title="Int16类型示例" />
 /// </example>
 public virtual OperateResult <short[]> ReadInt16(string address, ushort length)
 {
     return(ByteTransformHelper.GetResultFromBytes(Read(address, (ushort)(length * WordLength)), m => ByteTransform.TransInt16(m, 0, length)));
 }