コード例 #1
0
        public bool ContainsAddress(string address)
        {
            byte?address10 = NewModuleAbstract.HexToByte(address);

            if (address10 != null)
            {
                return(ContainsAddress((byte)address10));
            }
            return(false);
        }
コード例 #2
0
        public bool DeleteModule(string address)
        {
            byte?address10 = NewModuleAbstract.HexToByte(address);

            if (address10 != null)
            {
                return(DeleteModule((byte)address10));
            }
            return(false);
        }
コード例 #3
0
        public bool AddModule(string address, NewModuleAbstract module)
        {
            byte?address10 = NewModuleAbstract.HexToByte(address);

            if (address10 != null)
            {
                return(AddModule((byte)address10, module));
            }
            return(false);
        }
コード例 #4
0
        private string GetFf()
        {
            //Возвращает подстроку FF в команде $AA2
            //--var b = (byte) ((ClassAbstractAdamModule.HexToByte(_dataFormat) ?? 0) +
            //--                (_checkSumStatus ? Math.Pow(2, 6) : 0) + (_integrationTime ? Math.Pow(2, 7) : 0));
            //--return ClassAbstractAdamModule.ByteToHex(b);

            var b = (byte)((NewModuleAbstract.HexToByte(_dataFormat) ?? 0) +
                           (_checkSumStatus ? Math.Pow(2, 6) : 0) + (_integrationTime ? Math.Pow(2, 7) : 0));

            return(NewModuleAbstract.ByteToHex(b));
        }
コード例 #5
0
        private void tbAddress_Validating(object sender, CancelEventArgs e)
        {
            //byte? address10 = ClassAbstractAdamModule.HexToByte(tbAddress.Text);
            byte?address10 = NewModuleAbstract.HexToByte(tbAddress.Text);

            if (address10 != null)
            {
                tbAddress.Text   = (tbAddress.Text.Length == 1) ? '0' + tbAddress.Text.ToUpper() : tbAddress.Text.ToUpper();
                tbAddress10.Text = address10.ToString();
                tbCommand.Text   = GetCommandString();
            }
            else
            {
                MessageBox.Show(@"Адрес должен быть 16-ричным числом от 00 до FF");
                tbAddress.SelectionStart  = 0;
                tbAddress.SelectionLength = tbAddress.Text.Length;
                e.Cancel = true;
            }
        }
コード例 #6
0
        private string GetChannelValue(byte channel)
        {
            //Генерирует случайное значение канала в зависимости от свойст устройства и канала

            //if ((channel == 7) && ((DateTime.Now.Second % 2) == 1)) return "+888888";
            /*(((DateTime.Now.Millisecond % 256) == ClassAbstractAdamModule.HexToByte(_address)) && */
            if ((DateTime.Now.Millisecond % 10) == channel)
            {
                return("+888888");
            }

            //--byte? a = ClassAbstractAdamModule.HexToByte(_address);
            byte?  a     = NewModuleAbstract.HexToByte(_address);
            double value = GetValue(3, 20 * (a != null ? (byte)a : 0) + 1, 2.5 * channel);

            switch (_dataFormat)
            {
            case "0":     // Engineering units
                switch (_channels[channel].InputRange)
                {
                case "02":         // +-100 mV
                    value = 200 * value - 100;
                    break;

                case "03":         // +-500 m
                    value = 1000 * value - 500;
                    break;

                case "04":         // +-1 V
                    value = 2 * value - 1;
                    break;

                case "05":         // +-2.5 mV
                    value = 5 * value - 2.5;
                    break;

                case "07":         // +4 ~ 20 mA
                    value = 16 * value + 4;
                    break;

                case "08":         // +-10 V
                    value = 20 * value - 10;
                    break;

                case "09":         // +-5 V
                    value = 10 * value - 5;
                    break;

                case "0D":         // +-20 mA
                    value = 40 * value - 20;
                    break;

                case "0E":         // Type J Thermocouple 0 ~ 760 C
                    value = 760 * value;
                    break;

                case "0F":         // Type K Thermocouple 0 ~1370 C
                    value = 1370 * value;
                    break;

                case "10":         // Type T Thermocouple -100 ~ 400 C
                    value = 500 * value - 100;
                    break;

                case "11":         // Type E Thermocouple 0 ~ 1000 C
                    value = 1000 * value;
                    break;

                case "12":         // Type R Thermocouple 500 ~ 1750 C
                    value = 1250 * value + 500;
                    break;

                case "13":         // Type S Thermocouple 500 ~ 1750 C
                    value = 1250 * value + 500;
                    break;

                case "14":         // Type B Thermocouple 500 ~ 1800 C
                    value = 1300 * value + 500;
                    break;
                }
                break;

            case "1":     // % of FSR
            case "2":     // two's complement of hexadecimal
                switch (_channels[channel].InputRange)
                {
                case "02":         // +-100 mV
                case "03":         // +-500 m
                case "04":         // +-1 V
                case "05":         // +-2.5 mV
                case "08":         // +-10 V
                case "09":         // +-5 V
                case "0D":         // +-20 mA
                    value = 200 * value - 100;
                    break;

                case "07":         // +4 ~ 20 mA
                case "0E":         // Type J Thermocouple 0 ~ 760 C
                case "0F":         // Type K Thermocouple 0 ~1370 C
                case "10":         // Type T Thermocouple -100 ~ 400 C
                case "11":         // Type E Thermocouple 0 ~ 1000 C
                case "12":         // Type R Thermocouple 500 ~ 1750 C
                case "13":         // Type S Thermocouple 500 ~ 1750 C
                case "14":         // Type B Thermocouple 500 ~ 1800 C
                    value = 100 * value;
                    break;
                }
                break;
            }
            string stVal = "";

            switch (_dataFormat)
            {
            case "0":     // Engineering units
                stVal = (value >= 0) ? "+" + value : value.ToString();
                stVal = stVal.Substring(0, 7).Replace(",", ".");
                if (stVal.IndexOf(".") == -1)
                {
                    stVal = stVal + ".";
                }
                while (stVal.Length < 7)
                {
                    stVal = stVal + "0";
                }
                break;

            case "1":     // % of FSR
                value = Math.Round(value, 2);
                stVal = (value >= 0) ? "+" + value : value.ToString();
                stVal = stVal.Replace(",", ".");
                int i = stVal.IndexOf(".");
                if (i == -1)
                {
                    stVal = stVal + ".";
                    i     = stVal.Length;
                }
                for (; i <= 5; i++)
                {
                    stVal = stVal.Substring(0, 1) + "0" + stVal.Substring(1);
                }
                while (stVal.Length <= 7)
                {
                    stVal = stVal + "0";
                }
                break;

            case "2":     // two's complement of hexadecimal
                var val = (int)Math.Round(327.67 * value);
                if (val < 0)
                {
                    val = (int)Math.Pow(16, 4) - val;
                }
                stVal = Convert.ToString(val, 16);
                break;
            }
            return(stVal);
        }