Exemplo n.º 1
0
 public FakePotentiometerSource(AnalogOutput output, double defaultPotMaxAngle)
 {
     m_defaultPotMaxAngle = defaultPotMaxAngle;
     m_potMaxAngle        = defaultPotMaxAngle;
     m_output             = output;
     m_initOutput         = false;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Refresh Modules's Safety column value
        /// </summary>
        private void RefreshSafetySetting()
        {
            int iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx];

            if (!m_adamSocket.Configuration().OUT_GetSafetyEnable(m_idxID, out m_bIsEnableSafetyFcn))
            {
                StatusBar_IO.Text += "OUT_GetSafetyEnable(Error:" + m_adamSocket.Modbus().LastError.ToString() + ") Failed! ";
            }
            if (m_bIsEnableSafetyFcn)
            {
                ushort[] o_usValues;
                string[] strSafetyValue;
                if (m_adamSocket.AnalogOutput().GetSafetyValues(m_idxID, iChannelTotal, out o_usValues))
                {
                    m_usAOSafetyVals = o_usValues;
                    strSafetyValue   = new string[iChannelTotal];
                    for (int i = 0; i < iChannelTotal; i++)
                    {
                        listViewChInfo.Items[i].SubItems[6].Text = AnalogOutput.GetScaledValue(this.m_usRanges[i], m_usAOSafetyVals[i]).ToString("0.000;-0.000");  //moduify "Safety" column
                    }
                }
                else
                {
                    StatusBar_IO.Text += "GetSafetyValues(Error:" + m_adamSocket.Modbus().LastError.ToString() + ") Failed! ";
                }
            }
            else
            {
                for (int i = 0; i < iChannelTotal; i++)
                {
                    listViewChInfo.Items[i].SubItems[6].Text = "Disable";  //moduify "Safety" column
                }
            }
        }
Exemplo n.º 3
0
        public Form1()
        {
            InitializeComponent();

            int iIdx;

            m_bStart   = false;                      // the action stops at the beginning
            m_szIP     = "172.18.3.200";             // modbus slave IP address
            m_iPort    = 502;                        // modbus TCP port is 502
            adamModbus = new AdamSocket();
            adamModbus.SetTimeout(1000, 1000, 1000); // set timeout for TCP

            m_Adam6000Type = Adam6000Type.Adam6024;  // the sample is for ADAM-6050

            // modbus current list view item
            m_iAiTotal = AnalogInput.GetChannelTotal(m_Adam6000Type);
            m_iDiTotal = DigitalInput.GetChannelTotal(m_Adam6000Type);
            m_iAoTotal = AnalogOutput.GetChannelTotal(m_Adam6000Type);
            m_iDoTotal = DigitalOutput.GetChannelTotal(m_Adam6000Type);

            m_bChEnabled = new bool[m_iAiTotal];
            m_byAiRange  = new byte[m_iAiTotal];
            m_byAoRange  = new byte[m_iAoTotal];

            for (iIdx = 0; iIdx < m_iAoTotal; iIdx++)
            {
                //
                cbxAOChannel.Items.Add(iIdx.ToString());
                //
            }
            cbxAOChannel.SelectedIndex = -1;

            txtModule.Text = m_Adam6000Type.ToString();
        }
Exemplo n.º 4
0
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            int iIdx;

            adamCtl = new AdamControl();

            m_iSlot  = 2;               // the slot index of the module
            m_iCount = 0;               // the counting start from 0
            m_bStart = false;
            adamCtl  = new AdamControl();

            m_Adam5000Type = Adam5000Type.Adam5024;             // the sample is for ADAM-5024

            m_iChTotal = AnalogOutput.GetChannelTotal(m_Adam5000Type);
            m_byRange  = new byte[m_iChTotal];
            for (iIdx = 0; iIdx < m_iChTotal; iIdx++)
            {
                cbxChannel.Items.Add(iIdx.ToString());
            }
            txtModule.Text = m_Adam5000Type.ToString();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Refresh start up value
        /// </summary>
        /// <returns></returns>
        private bool RefreshAoStartupValues()
        {
            try
            {
                string[] strVals;
                int      iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx];

                if (m_adamSocket.AnalogOutput().GetStartupValues(m_idxID, iChannelTotal, out m_usStartupAO))
                {
                    strVals = new string[iChannelTotal];
                    for (int i = 0; i < m_usStartupAO.Length; i++)
                    {
                        strVals[i] = AnalogOutput.GetScaledValue(this.m_usRanges[i], m_usStartupAO[i]).ToString("0.000;-0.000");
                        listViewChInfo.Items[i].SubItems[5].Text = strVals[i];
                    }
                }
                else
                {
                    StatusBar_IO.Text += "GetStartupValues() Failed! ";
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        private void RefreshAOValue()
        {
            float fValue;
            int   iValue;

            if (adamCom.AnalogOutput(m_iAddr).GetCurrentValue((byte)m_adamConfig.Format, out fValue))
            {
                if (m_adamConfig.Format == Adam4000_DataFormat.EngineerUnit)
                {
                    txtAOValue.Text = fValue.ToString("#0.000") + " " + AnalogOutput.GetUnitName(m_Adam4000Type, m_adamConfig.TypeCode);
                }
                else if (m_adamConfig.Format == Adam4000_DataFormat.Percent)
                {
                    txtAOValue.Text = fValue.ToString("#0.000") + " %";
                }
                else
                {
                    iValue          = Convert.ToInt32(fValue);
                    txtAOValue.Text = "0X" + iValue.ToString("X03");
                }
            }
            else
            {
                txtAOValue.Text = "GetCurrentValue() failed";
            }
        }
Exemplo n.º 7
0
        public Form1()
        {
            InitializeComponent();

            int iIdx;

            m_b5000 = true; // set to true for module on ADAM-5000; set to false for module on ADAM-5000/TCP
            if (m_b5000)
            {
                m_iCom           = 4;     // using COM4
                adamCom          = new AdamCom(m_iCom);
                adamCom.Checksum = false; // disbale checksum
            }
            else
            {
                m_szIP     = "172.18.3.179";
                adamSocket = new AdamSocket();
                adamSocket.SetTimeout(1000, 1000, 1000); // set timeout
            }
            m_iAddr        = 1;                          // the slave address is 1
            m_iSlot        = 0;                          // the slot index of the module
            m_iCount       = 0;                          // the counting start from 0
            m_bStart       = false;
            m_Adam5000Type = Adam5000Type.Adam5024;      // the sample is for ADAM-5024

            m_iChTotal = AnalogOutput.GetChannelTotal(m_Adam5000Type);
            m_byRange  = new byte[m_iChTotal];
            for (iIdx = 0; iIdx < m_iChTotal; iIdx++)
            {
                cbxChannel.Items.Add(iIdx.ToString());
            }
            txtModule.Text = m_Adam5000Type.ToString();
        }
Exemplo n.º 8
0
 /// <summary>
 /// Get Channel information "Range" column
 /// </summary>
 /// <returns></returns>
 private bool RefreshRanges()
 {
     try
     {
         int iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx];
         if (m_adamSocket.Configuration().GetModuleConfig(m_idxID, out m_aConf))
         {
             m_adamSocket.Configuration().GetModuleCurrentRange(Convert.ToInt32(m_idxID), m_aConf);
             m_usRanges = m_aConf.wChRange;
             // Update Range column
             for (int i = 0; i < iChannelTotal; i++)
             {
                 listViewChInfo.Items[i].SubItems[4].Text = AnalogOutput.GetRangeName(m_usRanges[i]).ToString();
             }
         }
         else
         {
             StatusBar_IO.Text += "GetModuleConfig(Error:" + m_adamSocket.Modbus().LastError.ToString() + ") Failed! ";
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 9
0
    public override void OnInspectorGUI()
    {
        this.serializedObject.Update();

        AnalogOutput controller = (AnalogOutput)target;

        GUI.enabled = false;
        EditorGUILayout.PropertyField(script, true, new GUILayoutOption[0]);
        GUI.enabled = true;
        foldout     = EditorGUILayout.Foldout(foldout, "Sketch Options");
        if (foldout)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(id, new GUIContent("id"));
            EditorGUILayout.PropertyField(pin, new GUIContent("pin"));
            EditorGUILayout.PropertyField(defaultValue, new GUIContent("defaultValue"));
            EditorGUILayout.PropertyField(resetOnStop, new GUIContent("resetOnStop"));
            EditorGUI.indentLevel--;
        }

        float newValue = EditorGUILayout.Slider("Value", controller.Value, 0f, 1f);

        if (newValue != controller.Value)
        {
            controller.Value = newValue;
            if (!Application.isPlaying)
            {
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }
        }

        this.serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 10
0
        private static void pe2a_AO_ch_choosing(AnalogOutput setVal, ref byte ptr)
        {
            switch (setVal)
            {
            case AnalogOutput.Gpio_J1_1:
                //daca 00
                pe2a_AO_wrLow(ref ptr, 7);
                pe2a_AO_wrLow(ref ptr, 6);

                break;

            case AnalogOutput.Gpio_J1_2:
                //dacb	01
                pe2a_AO_wrLow(ref ptr, 7);
                pe2a_AO_wrHigh(ref ptr, 6);

                break;

            case AnalogOutput.Gpio_J1_3:
                //dacc 10
                pe2a_AO_wrLow(ref ptr, 6);
                pe2a_AO_wrHigh(ref ptr, 7);

                break;

            case AnalogOutput.Gpio_J1_4:
                //dacd 11
                pe2a_AO_wrHigh(ref ptr, 7);
                pe2a_AO_wrHigh(ref ptr, 6);

                break;
            }
        }
 public FakePotentiometerSource(AnalogOutput output, double defaultPotMaxAngle)
 {
     this.defaultPotMaxAngle = defaultPotMaxAngle;
     potMaxAngle = defaultPotMaxAngle;
     this.output = output;
     m_init_output = false;
 }
Exemplo n.º 12
0
        public static void Main()
        {
            int DacValue1 = 10;
            int DacValue2 = 10;

            Debug.Print(Resources.GetString(Resources.StringResources.String1));

            // ADC
            AnalogInput ADC0 = new AnalogInput(ADC.PA1);
            AnalogInput ADC1 = new AnalogInput(ADC.PA2);
            AnalogInput ADC2 = new AnalogInput(ADC.PA3);
            AnalogInput ADC3 = new AnalogInput(ADC.PB0); // PB0 = PA0 ???

            //DAC
            AnalogOutput DAC0 = new AnalogOutput(Cpu.AnalogOutputChannel.ANALOG_OUTPUT_0);
            AnalogOutput DAC1 = new AnalogOutput(Cpu.AnalogOutputChannel.ANALOG_OUTPUT_1);

            DAC0.Scale = 1;
            DAC0.Write(0.8);

            DAC1.Scale = 1;
            DAC1.Write(0.1);

            /* Initialize LEDs */
            LED.LEDInit();
            LED.GreenLedToggle();
            while (true)
            {
                /* Display the ADC converted value */
                //int AdcValue = (ADC0.ReadRaw() * 1);
                //string str = AdcValue.ToString();
                Debug.Print("ADC0 (pin " + ADC0.Pin + ") = " + (ADC0.ReadRaw()));
                Debug.Print("ADC1 (pin " + ADC1.Pin + ") = " + (ADC1.ReadRaw()));
                Debug.Print("ADC2 (pin " + ADC2.Pin + ") = " + (ADC2.ReadRaw()));
                Debug.Print("ADC3 (pin " + ADC3.Pin + ") = " + (ADC3.ReadRaw()));

                Debug.Print("\r\n--------------------------------\r\n");

                /* Wait for 1s */
                Thread.Sleep(250);

                /* Toggle Green LED */
                LED.GreenLedToggle();
                LED.RedLedToggle();

                DacValue1 += 100;
                if (DacValue1 > 4000)
                {
                    DacValue1 = 0;
                }
                DAC0.WriteRaw(DacValue1);

                DacValue2 += 100;
                if (DacValue2 > 4000)
                {
                    DacValue2 = 0;
                }
                DAC1.WriteRaw(DacValue2);
            }
        }
Exemplo n.º 13
0
 public FakePotentiometerSource(AnalogOutput output, double defaultPotMaxAngle)
 {
     m_defaultPotMaxAngle = defaultPotMaxAngle;
     m_potMaxAngle = defaultPotMaxAngle;
     m_output = output;
     m_initOutput = false;
 }
Exemplo n.º 14
0
        private void btnSetSafetyValue_Click(object sender, EventArgs e)
        {
            if (!CheckControllable())
            {
                return;
            }

            timer1.Enabled = false;
            int iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx];

            float[] fAOSafetyVals = new float[iChannelTotal];

            for (int i = 0; i < iChannelTotal; i++)
            {
                fAOSafetyVals[i] = AnalogOutput.GetScaledValue(m_usRanges[i], m_usAOSafetyVals[i]);
            }

            string[] szRanges = new string[iChannelTotal];

            for (int idx = 0; idx < szRanges.Length; idx++)
            {
                szRanges[idx] = AnalogInput.GetRangeName(m_usRanges[idx]);
            }

            FormSafetySetting formSafety = new FormSafetySetting(iChannelTotal, fAOSafetyVals, szRanges);

            formSafety.ApplySafetyValueClick += new FormSafetySetting.EventHandler_ApplySafetyValueClick(formSafety_ApplySafetyValueClick);

            formSafety.ShowDialog();
            formSafety.Dispose();
            formSafety = null;

            timer1.Enabled = true;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Init Channel Information
        /// </summary>
        /// <param name="m_aConf">apax 5000 device object</param>
        private void InitialDataTabPages()
        {
            int          i = 0, idx = 0;
            byte         type = (byte)_HardwareIOType.AO; //APAX-5028 is AO module
            ListViewItem lvItem;

            string[] strRanges;

            for (i = 0; i < m_aConf.HwIoType.Length; i++)
            {
                if (m_aConf.HwIoType[i] == type)
                {
                    idx = i;
                }
            }
            m_tmpidx = idx;

            if (m_tmpidx == 0)
            {
                m_usRanges_supAO = m_aConf.wHwIoType_0_Range;
            }
            else if (m_tmpidx == 1)
            {
                m_usRanges_supAO = m_aConf.wHwIoType_1_Range;
            }
            else if (m_tmpidx == 2)
            {
                m_usRanges_supAO = m_aConf.wHwIoType_2_Range;
            }
            else if (m_tmpidx == 3)
            {
                m_usRanges_supAO = m_aConf.wHwIoType_3_Range;
            }
            else// if(idxType==3)
            {
                m_usRanges_supAO = m_aConf.wHwIoType_4_Range;
            }
            //init range combobox
            strRanges = new string[m_aConf.HwIoType_TotalRange[m_tmpidx]];
            for (i = 0; i < strRanges.Length; i++)
            {
                strRanges[i] = AnalogOutput.GetRangeName(m_usRanges_supAO[i]);
            }
            SetRangeComboBox(strRanges);

            listViewChInfo.BeginUpdate();
            listViewChInfo.Items.Clear();
            for (i = 0; i < m_aConf.HwIoTotal[m_tmpidx]; i++)
            {
                lvItem = new ListViewItem(_HardwareIOType.AO.ToString()); //Type
                lvItem.SubItems.Add(i.ToString());                        //Ch
                lvItem.SubItems.Add("*****");                             //Value
                lvItem.SubItems.Add("*****");                             //Range
                lvItem.SubItems.Add("*****");                             //Start up
                lvItem.SubItems.Add("*****");                             //Safety Value
                listViewChInfo.Items.Add(lvItem);
            }
            listViewChInfo.EndUpdate();
        }
Exemplo n.º 16
0
        public void displayAnalogOutputData(AnalogOutput tag)
        {
            displayBasicTagData(tag);

            tagInitValueTextBox.Text = tag.InitialValue.ToString();
            tagLowLimitTextBox.Text  = tag.LowLimits.ToString();
            tagHighLimitTextBox.Text = tag.HighLimits.ToString();
            tagUnitsTextBox.Text     = tag.Units.ToString();
        }
 public void Dispose()
 {
     if (m_init_output)
     {
         output.Dispose();
         output = null;
         m_init_output = false;
     }
 }
Exemplo n.º 18
0
 public void Dispose()
 {
     if (m_initOutput)
     {
         m_output.Dispose();
         m_output     = null;
         m_initOutput = false;
     }
 }
Exemplo n.º 19
0
        void SignalIn_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode)
        {
            var oldSignalIn = oldNode as NodeSignalIn;
            var newSignalIn = newNode as NodeSignalIn;

            if (oldSignalIn != null && newSignalIn != null)
            {
                AnalogOutput = AnalogOutput.SetSignalIn(newSignalIn);
            }
        }
Exemplo n.º 20
0
        public B10001GroupBoard(NeuronGroup neuronGroup, IBoardInformation boardSystemInformation, NeuronSpiConnector spiConnector, I2CConnector i2CConnector, DriverLogger logger) : base(neuronGroup, boardSystemInformation, spiConnector, i2CConnector, logger)
        {
            #region Digital Inputs

            for (ushort i = 0; i < AnzahlDigitalInputs; i++)
            {
                var input = new DigitalInput(i + 1, neuronGroup, 0, i);
                SetObservation(0, input);
                DigitalInputDictionary.Add(input.UniqueIdentifyer, input);
            }

            #endregion Digital Inputs

            #region Digital Outputs

            for (ushort i = 0; i < AnzahlDigitalOutputs; i++)
            {
                var digitalOutput = new DigitalOutput(1 + i, neuronGroup, i, spiConnector, logger, DigitalRelayOutputType.DigitalOutput, 1, i);
                DigitalOutputsDictionary.Add(digitalOutput.UniqueIdentifyer, digitalOutput);
            }

            #endregion Digital Outputs

            #region One Wire

            var oneWireConnector = new OneWireConnector(neuronGroup, 1, Logger, I2CConnector);
            OneWireConnectorsDictionary.Add(oneWireConnector.UniqueIdentifyer, oneWireConnector);

            #endregion One Wire

            #region User LED's

            for (ushort i = 0; i < UserLedsCount; i++)
            {
                var userLed = new UserLed(i + 1, neuronGroup, (ushort)(8 + i), spiConnector, 20, i);
                UserLedsDictionary.Add(userLed.UniqueIdentifyer, userLed);
            }

            #endregion User LED's

            #region Analog Output

            var analogOutput = new AnalogOutput(neuronGroup, 1, 2, spiConnector, logger);
            AnalogOutputsDictionary.Add(analogOutput.UniqueIdentifyer, analogOutput);

            #endregion Analog Output

            #region Analog Input

            var analogInput = new AnalogInput(neuronGroup, 1, 3, spiConnector);
            SetObservation(3, analogInput);
            AnalogInputsDictionary.Add(analogInput.UniqueIdentifyer, analogInput);

            #endregion Analog Input
        }
Exemplo n.º 21
0
        private void btnApplySelRange_Click(object sender, EventArgs e)
        {
            DialogResult result;

            if (!CheckControllable())
            {
                return;
            }
            timer1.Enabled = false;

            result = MessageBox.Show("After changing range setting, you need to configure proper start-up value again!", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
            if (result == DialogResult.Yes)
            {
                bool bRet        = true;
                bool i_bApplyAll = chbxApplyAll.Checked;
                if (listViewChInfo.SelectedIndices.Count == 0 && !i_bApplyAll)
                {
                    MessageBox.Show("Please select the target channel in the listview!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                    bRet = false;
                }
                if (bRet)
                {
                    ushort[] usRanges = new ushort[m_usRanges.Length];
                    Array.Copy(m_usRanges, 0, usRanges, 0, m_usRanges.Length);
                    if (i_bApplyAll)
                    {
                        for (int i = 0; i < usRanges.Length; i++)
                        {
                            usRanges[i] = AnalogOutput.GetRangeCode2Byte(cbxRange.SelectedItem.ToString());
                        }
                    }
                    else
                    {
                        for (int i = 0; i < listViewChInfo.SelectedIndices.Count; i++)
                        {
                            usRanges[listViewChInfo.SelectedIndices[i]] = AnalogOutput.GetRangeCode2Byte(cbxRange.SelectedItem.ToString());
                        }
                    }
                    int iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx];
                    if (m_adamSocket.AnalogOutput().SetRanges(this.m_idxID, iChannelTotal, usRanges))
                    {
                        MessageBox.Show("Set ranges done!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                        RefreshRanges();
                        RefreshAoStartupValues();
                    }
                    else
                    {
                        MessageBox.Show("Set ranges failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                    }
                }
            }
            timer1.Enabled = true;
        }
 private void Initialize()
 {
     lock (this)
     {
         if (!initialized)
         {
             input = GiveAnalogInput();
             output = GiveAnalogOutput();
             initialized = true;
         }
     }
 }
Exemplo n.º 23
0
        private void cbxAoChannel_SelectedIndexChanged(object sender, EventArgs e)
        {
            int iRetryLimit = 10;
            int iRetryCount = 0;

            if (cbxAoChannel.SelectedIndex != this.m_iAoChTotal)
            {
                if (timer1.Enabled)
                {
                    timer1.Enabled = false;
                    RefreshAoChannelRange(cbxAoChannel.SelectedIndex, true);
                    if (cbxAoChannel.SelectedIndex >= 0)
                    {
                        dgViewAoChannelInfo.Rows[cbxAoChannel.SelectedIndex].Selected = true;
                    }
                    timer1.Enabled = true;
                }
                else
                {
                    RefreshAoChannelRange(cbxAoChannel.SelectedIndex, true);
                    if (cbxAoChannel.SelectedIndex >= 0)
                    {
                        dgViewAoChannelInfo.Rows[cbxAoChannel.SelectedIndex].Selected = true;
                    }
                }

                gpBoxAoSetValue.Visible = true;
                for (int i = 0; i < iRetryLimit; i++)
                {
                    AnalogOutput.GetRangeHighLow(m_Adam6000Type, m_usRange[cbxAoChannel.SelectedIndex], out m_fHigh, out m_fLow);
                    if ((m_fHigh == 0.0f) && (m_fLow == 0.0f))
                    {
                        iRetryCount++;
                        System.Threading.Thread.Sleep(150);
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                txtSelAoChannel.Text = cbxAoChannel.SelectedIndex.ToString();
                RefreshOutputPanel(m_fHigh, m_fLow);
                if (iRetryCount >= iRetryLimit)
                {
                    MessageBox.Show("AnalogOutput.GetRangeHighLow failed! Please retry again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                }
            }
            else
            {
                gpBoxAoSetValue.Visible = false;
            }
        }
Exemplo n.º 24
0
 private void Initialize()
 {
     lock (this)
     {
         if (!m_initialized)
         {
             m_input       = GiveAnalogInput();
             m_output      = GiveAnalogOutput();
             m_initialized = true;
         }
     }
 }
Exemplo n.º 25
0
 public bool Add(AnalogOutput device)
 {
     try
     {
         context.Devices.Add(device);
         context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 26
0
        private void RefreshAdam5000Information()
        {
            int  iIdx;
            byte byCode;

            Adam5000Type adamType;

            adamType = (Adam5000Type)cbxModuleType.SelectedItem;
            // AI information
            txtAITotal.Text = AnalogInput.GetChannelTotal(adamType).ToString();
            listViewAI.Items.Clear();
            for (iIdx = 0; iIdx < AnalogInput.GetRangeTotal(adamType); iIdx++)
            {
                byCode = AnalogInput.GetRangeCode(adamType, iIdx);
                listViewAI.Items.Add(new ListViewItem("0x" + byCode.ToString("X02")));           // range code
                listViewAI.Items[iIdx].SubItems.Add(AnalogInput.GetRangeName(adamType, byCode)); // range name
                listViewAI.Items[iIdx].SubItems.Add(AnalogInput.GetUnitName(adamType, byCode));  // range name
            }
            // AO information
            txtAOTotal.Text = AnalogOutput.GetChannelTotal(adamType).ToString();
            listViewAO.Items.Clear();
            for (iIdx = 0; iIdx < AnalogOutput.GetRangeTotal(adamType); iIdx++)
            {
                byCode = AnalogOutput.GetRangeCode(adamType, iIdx);
                listViewAO.Items.Add(new ListViewItem("0x" + byCode.ToString("X02")));                  // range code
                listViewAO.Items[iIdx].SubItems.Add(AnalogOutput.GetRangeName(adamType, byCode));       // range name
                listViewAO.Items[iIdx].SubItems.Add(AnalogOutput.GetUnitName(adamType, byCode));        // range name
            }
            // DIO
            txtDITotal.Text = DigitalInput.GetChannelTotal(adamType).ToString();
            txtDOTotal.Text = DigitalOutput.GetChannelTotal(adamType).ToString();
            // counter
            txtCounterTotal.Text = Counter.GetChannelTotal(adamType).ToString();
            listViewCounter.Items.Clear();
            if (Counter.GetModeTotal(adamType) > 0)
            {
                listViewCounter.Items.Add(new ListViewItem(Counter.GetModeName(adamType, (byte)Adam5080_CounterMode.Bi_Direction)));    // mode name
                listViewCounter.Items[0].SubItems.Add(Counter.GetUnitName(adamType, (byte)Adam5080_CounterMode.Bi_Direction));          // unit name
                listViewCounter.Items.Add(new ListViewItem(Counter.GetModeName(adamType, (byte)Adam5080_CounterMode.Up_Down)));         // mode name
                listViewCounter.Items[1].SubItems.Add(Counter.GetUnitName(adamType, (byte)Adam5080_CounterMode.Up_Down));               // unit name
                listViewCounter.Items.Add(new ListViewItem(Counter.GetModeName(adamType, (byte)Adam5080_CounterMode.Frequency)));       // mode name
                listViewCounter.Items[2].SubItems.Add(Counter.GetUnitName(adamType, (byte)Adam5080_CounterMode.Frequency));             // unit name
            }
            // alarm
            listViewAlarm.Items.Clear();
            for (iIdx = 0; iIdx < Alarm.GetModeTotal(adamType); iIdx++)
            {
                byCode = Alarm.GetModeCode(adamType, iIdx);
                listViewAlarm.Items.Add(new ListViewItem(Alarm.GetModeName(adamType, byCode))); // mode name
            }
        }
Exemplo n.º 27
0
 public Adam6000(string name, Adam6000Type model)  : base(name, new ChannelsInfo {
     AnalogInputsCount    = AnalogInput.GetChannelTotal(model),
     AnalogOutputsCount   = AnalogOutput.GetChannelTotal(model),
     DiscreteInputsCount  = DigitalInput.GetChannelTotal(model),
     DiscreteOutputsCount = DigitalOutput.GetChannelTotal(model),
     CounterInputsCount   = DigitalInput.GetChannelTotal(model)
 })
 {
     Model = model;
     if (AnalogInputs != null)
     {
         AIRanges = new List <byte>(new byte[AnalogInputs.Count]);
     }
 }
Exemplo n.º 28
0
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            m_bStart   = false;                      // the action stops at the beginning
            m_szIP     = "172.18.3.93";              // modbus slave IP address
            m_iPort    = 502;                        // modbus TCP port is 502
            adamModbus = new AdamSocket();
            adamModbus.SetTimeout(1000, 1000, 1000); // set timeout for TCP
            adamModbus.AdamSeriesType = AdamType.Adam6200;
            adamModbus.Connect(m_szIP, ProtocolType.Tcp, m_iPort);

            m_Adam6000Type = Adam6000Type.Adam6224; // the sample is for ADAM-6224

            m_iAoChTotal        = AnalogOutput.GetChannelTotal(m_Adam6000Type);
            m_iAoRangeTotal     = AnalogOutput.GetRangeTotal(m_Adam6000Type, Adam6000_RangeFormat.Ushort);
            m_iDiTotal          = DigitalInput.GetChannelTotal(m_Adam6000Type);
            m_DiValueStartAddr  = 1;
            m_iAoValueStartAddr = 1;
            txtModule.Text      = m_Adam6000Type.ToString();
            m_usRange           = new ushort[m_iAoChTotal];
            m_usAoValue         = new ushort[m_iAoChTotal];

            InitialDiDgViewModbusGeneralRow(m_DiValueStartAddr, m_iDiTotal, ref dgViewDiChannelInfo);

            InitialAoDgViewModbusGeneralRow(m_iAoValueStartAddr, m_iAoChTotal, ref dgViewAoChannelInfo);
            for (int i = 0; i < m_iAoChTotal; i++)
            {
                cbxAoChannel.Items.Add(i.ToString());
            }

            cbxAoChannel.Items.Add("All");

            if (m_Adam6000Type == Adam6000Type.Adam6224)
            {
                for (int i_iIndex = 0; i_iIndex < m_iAoRangeTotal; i_iIndex++)
                {
                    ushort usRangeCode  = AnalogOutput.GetRangeCode2Byte(m_Adam6000Type, i_iIndex);
                    string strRangeName = AnalogOutput.GetRangeName(m_Adam6000Type, usRangeCode);
                    cbxAoOutputRange.Items.Add(new ComboItem(strRangeName, usRangeCode));
                }
            }
        }
Exemplo n.º 29
0
        private void btnSetAsSafety_Click(object sender, EventArgs e)
        {
            if (!CheckControllable())
            {
                return;
            }

            try
            {
                float fVal, fHigh, fLow;
                int   iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx];
                //Get range higf & low
                AnalogOutput.GetRangeHighLow(m_usRanges[m_iSelChannels], out fHigh, out fLow);
                if (fHigh - fLow == 0)
                {
                    MessageBox.Show("GetRangeHighLow() failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                    return;
                }
                //convert output value to float
                fVal = 0.0f;
                if (txtOutputVal.Text != null && txtOutputVal.Text.Length > 0)
                {
                    try
                    {
                        fVal = Convert.ToSingle(txtOutputVal.Text);
                    }
                    catch
                    {
                        System.Windows.Forms.MessageBox.Show("Invalid value: " + txtOutputVal.Text);
                    }
                }
                ushort[] usAOSafetyVals = new ushort[m_usAOSafetyVals.Length];
                Array.Copy(m_usAOSafetyVals, 0, usAOSafetyVals, 0, m_usAOSafetyVals.Length);

                usAOSafetyVals[m_iSelChannels] = Convert.ToUInt16(65535.0f * ((fVal - fLow) / (fHigh - fLow)));

                if (!m_adamSocket.AnalogOutput().SetSafetyValues(m_idxID, iChannelTotal, usAOSafetyVals))
                {
                    MessageBox.Show("Set safety value failed! (Err: " + m_adamSocket.Modbus().LastError.ToString() + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                }

                RefreshSafetySetting();
            }
            catch
            {
                return;
            }
            return;
        }
Exemplo n.º 30
0
        private void RefreshChannelValue(int i_iChannel, ref TextBox i_txtCh)
        {
            float  fValue;
            string szFormat;

            if (adamCom.AnalogOutput(m_iAddr).GetCurrentValue(i_iChannel, out fValue))
            {
                szFormat     = AnalogOutput.GetFloatFormat(m_Adam4000Type, m_byRange[i_iChannel]);
                i_txtCh.Text = fValue.ToString(szFormat) + " " + AnalogOutput.GetUnitName(m_Adam4000Type, m_byRange[i_iChannel]);
            }
            else
            {
                i_txtCh.Text = "GetCurrentValue() failed";
            }
        }
Exemplo n.º 31
0
        /// <summary>
        /// Turns on the buzzer.
        /// </summary>
        public static void StartBuzzer()
        {
            if (!Sound.IsEnabled)
            {
                throw new Exception("You must enable Sound first.");
            }

            if (AudioSwitch == null)
            {
                AudioSwitch = new AnalogOutput(Cpu.AnalogOutputChannel.ANALOG_OUTPUT_0, 12);
                AudioSwitch.Write(0);
            }

            Sound.PWMOut.Start();
        }
Exemplo n.º 32
0
        /// <summary>
        /// Turns off the buzzer.
        /// </summary>
        public static void StopBuzzer()
        {
            if (!Sound.IsEnabled)
            {
                throw new Exception("You must enable Sound first.");
            }

            Sound.PWMOut.Stop();

            if (AudioSwitch != null)
            {
                AudioSwitch.Dispose();
                AudioSwitch = null;
            }
        }
Exemplo n.º 33
0
        /// <summary>
        ///  Apply setting when user configure safety status
        /// </summary>
        /// <param name="bVal"></param>
        private void formSafety_ApplySafetyValueClick(string[] szVal)
        {
            int   iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx];
            float fVal, fHigh, fLow;

            ushort[] usAOSafetyVals = new ushort[m_usAOSafetyVals.Length];
            for (int i = 0; i < iChannelTotal; i++)
            {
                fVal = 0.0f;
                if (szVal[i] != null && szVal[i].Length > 0)
                {
                    try
                    {
                        fVal = Convert.ToSingle(szVal[i]);
                    }
                    catch
                    {
                        System.Windows.Forms.MessageBox.Show("Invalid value: " + szVal[i]);
                    }
                }

                AnalogOutput.GetRangeHighLow(m_usRanges[i], out fHigh, out fLow);

                if (fHigh - fLow == 0)
                {
                    MessageBox.Show("GetRangeHighLow() failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                    return;
                }

                if (fVal > fHigh || fVal < fLow)
                {
                    MessageBox.Show("Channel " + i.ToString() + " is illegal value! Please enter the value " + fLow.ToString() + " ~ " + fHigh.ToString() + ".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                    return;
                }

                usAOSafetyVals[i] = Convert.ToUInt16(65535.0f * ((fVal - fLow) / (fHigh - fLow)));
            }

            if (!m_adamSocket.AnalogOutput().SetSafetyValues(m_idxID, iChannelTotal, usAOSafetyVals))
            {
                MessageBox.Show("Set safety value failed! (Err: " + m_adamSocket.Modbus().LastError.ToString() + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }

            RefreshSafetySetting();
        }
Exemplo n.º 34
0
        public static void Main()
        {
            /*final voltage = Maximum Output  * ( (level*Scale) + Offset))*/
            AnalogOutput AnOutput = new AnalogOutput(Cpu.AnalogOutputChannel.ANALOG_OUTPUT_1);
            AnalogInput  AnInput  = new AnalogInput(Cpu.AnalogChannel.ANALOG_0);

            AnOutput.Scale  = 1;
            AnOutput.Offset = 0.25;
            AnOutput.Write(0.5);
            double value;

            while (true)
            {
                value = AnInput.Read() * 3.3;
                Debug.Print("Value=" + value.ToString());
                Thread.Sleep(1000);
            }
        }