示例#1
0
        private AllVoltageValue AllVoltageValuefromBytes(byte[] arr, int size)
        {
            AllVoltageValue str = new AllVoltageValue();
            IntPtr          ptr = Marshal.AllocHGlobal(size);

            SwapIt(typeof(VoltageValue), arr, 0);
            Marshal.Copy(arr, 0, ptr, size);
            str = (AllVoltageValue)Marshal.PtrToStructure(ptr, str.GetType());
            Marshal.FreeHGlobal(ptr);

            //str.VoltageVan = ChangeEndian_32Bit(str.VoltageVan);
            //str.VoltageVbn = ChangeEndian_32Bit(str.VoltageVbn);
            //str.VoltageVcn = ChangeEndian_32Bit(str.VoltageVcn);
            //str.VoltageVavg = ChangeEndian_32Bit(str.VoltageVavg);

            return(str);
        }
示例#2
0
        public int ReadVoltageValue()
        {
            int result = 0;

            result = ReadHoldingRegister(new ReadHoldingRequest(_TransactionID, 0, 6, 1, 3, 11044, 1));
            if (result < 0)
            {
                return(-1);
            }

            result = ReadHoldingRegister(new ReadHoldingRequest(_TransactionID, 0, 6, 1, 3, 11291, 2));
            if (result > 0)
            {
                _AllVoltageValueStruct = (AllVoltageValue)AllVoltageValuefromBytes(_RecvData, Marshal.SizeOf(_AllVoltageValueStruct));
            }
            else
            {
                return(-2);
            }

            result = ReadHoldingRegister(new ReadHoldingRequest(_TransactionID, 0, 6, 1, 3, 11101, 8));
            if (result > 0)
            {
                _VoltageValueStruct = (VoltageValue)VoltageValuefromBytes(_RecvData, Marshal.SizeOf(_VoltageValueStruct));
            }
            else
            {
                return(-3);
            }

            #region 테스트 시 작성됨
            //result = ReadHoldingRegister(new ReadHoldingRequest(_TransactionID, 0, 6, 1, 3, 1, 1));
            //if (result > 0)
            //{
            //    //result = ReadHoldingRegister(new ReadHoldingRequest(_TransactionID, 0, 6, 1, 3, 11001, 1));
            //    //result = ReadHoldingRegister(new ReadHoldingRequest(_TransactionID, 0, 6, 1, 3, 11002, 1));
            //    result = ReadHoldingRegister(new ReadHoldingRequest(_TransactionID, 0, 6, 1, 3, 11044, 1));
            //    result = ReadHoldingRegister(new ReadHoldingRequest(_TransactionID, 0, 6, 1, 3, 11045, 1));
            //    if (result > 0)
            //    {
            //        result = ReadHoldingRegister(new ReadHoldingRequest(_TransactionID, 0, 6, 1, 3, 11291, 2));
            //        if (result > 0)
            //        {
            //            _AllVoltageValueStruct = (AllVoltageValue)AllVoltageValuefromBytes(_RecvData, Marshal.SizeOf(_AllVoltageValueStruct));
            //        }
            //        result = ReadHoldingRegister(new ReadHoldingRequest(_TransactionID, 0, 6, 1, 3, 11101, 8));

            //        if (result > 0)
            //        {
            //            _VoltageValueStruct = (VoltageValue)VoltageValuefromBytes(_RecvData, Marshal.SizeOf(_VoltageValueStruct));
            //        }
            //        else
            //        {
            //            result = -2;
            //        }
            //    }
            //    else
            //    {
            //        result = -1;
            //    }
            //}
            //else
            //{
            //    result = -3;
            //}
            #endregion
            return(result);
        }