Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override byte[] ConvertToBytes(object obj)
        {
            XD221ModbusConfigObject mpo = obj as XD221ModbusConfigObject;

            if (obj == null)
            {
                throw new ArgumentException("not XD221ModbusParamObject argument");
            }

            return(mpo.ToBytes());
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bs"></param>
        /// <returns></returns>
        static public XD221ModbusConfigObject Parse(byte[] bs)
        {
            if (bs.Length == 7)
            {
                int begin     = GetModbusWord(bs, 0);
                int wordCount = GetModbusWord(bs, 2);
                int byteCount = bs[4];
                // TODO: wordindex converter
                //
                XD221ConfigDefine ci = XD221ConfigDefineCollection.Find(begin + 1);

                // TODO: ci == null
                //
                IBytesConverter         ibc = BytesConverterManager.CreateBytesConverter(ci.Converter, null);
                object                  obj = ibc.ConvertToObject(bs);
                XD221ModbusConfigObject mpo = new XD221ModbusConfigObject(ci.Name, obj);
                return(mpo);
            }
            return(null);
        }
Exemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="bytes"></param>
 /// <returns></returns>
 public override object ConvertToObject(byte[] bytes)
 {
     return(XD221ModbusConfigObject.Parse(bytes));
 }
Exemplo n.º 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="bs"></param>
        /// <returns></returns>
        public static XD221ModbusConfigObject Parse(byte[] bs)
        {
            if (bs.Length == 7)
            {
                int begin = GetModbusWord(bs, 0);
                int wordCount = GetModbusWord(bs, 2);
                int byteCount = bs[4];
                // TODO: wordindex converter
                //
                XD221ConfigDefine ci = XD221ConfigDefineCollection.Find(begin + 1);

                // TODO: ci == null
                //
                IBytesConverter ibc = BytesConverterManager.CreateBytesConverter(ci.Converter, null);
                object obj = ibc.ConvertToObject(bs);
                XD221ModbusConfigObject mpo = new XD221ModbusConfigObject(ci.Name, obj);
                return mpo;
            }
            return null;
        }