Exemplo n.º 1
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.º 2
0
        private void RefreshOutputValue(int i_iChannel)
        {
            int iStart = 11 + i_iChannel;

            int[]  iData;
            float  fValue;
            string szFormat;
            Adam6024_OutputRange byRange;

            if (adamModbus.Modbus().ReadInputRegs(iStart, 1, out iData))
            {
                fValue = AnalogOutput.GetScaledValue(m_Adam6000Type, m_byAoRange[i_iChannel], iData[0]);
                //
                szFormat = AnalogOutput.GetFloatFormat(m_Adam6000Type, m_byAoRange[i_iChannel]);
                byRange  = (Adam6024_OutputRange)m_byAoRange[i_iChannel];

                if (byRange == Adam6024_OutputRange.mA_0To20) // 0~20mA
                {
                    lblLow.Text     = "0 mA";
                    lblHigh.Text    = "20 mA";
                    trackBar1.Value = Convert.ToInt32(fValue * trackBar1.Maximum / 20);
                }
                else if (byRange == Adam6024_OutputRange.mA_4To20) // 4~20mA
                {
                    lblLow.Text     = "4 mA";
                    lblHigh.Text    = "20 mA";
                    trackBar1.Value = Convert.ToInt32((fValue - 4.0) * trackBar1.Maximum / 16);
                }
                else // 0~10V
                {
                    lblLow.Text     = "0 V";
                    lblHigh.Text    = "10 V";
                    trackBar1.Value = Convert.ToInt32(fValue * trackBar1.Maximum / 10);
                }
                txtOutputValue.Text = fValue.ToString(szFormat);
            }
            else
            {
                txtReadCount.Text += "ReadInputRegs() failed;";
            }
        }
Exemplo n.º 3
0
        private void RefreshAoChannelValue(int i_iChannel)
        {
            int iStart = 11 + i_iChannel;

            int[]  iData;
            float  fValue;
            string szFormat;

            if (adamModbus.Modbus().ReadInputRegs(iStart, 1, out iData))
            {
                fValue = AnalogOutput.GetScaledValue(m_Adam6000Type, m_byAoRange[i_iChannel], iData[0]);
                //
                szFormat = AnalogOutput.GetFloatFormat(m_Adam6000Type, m_byAoRange[i_iChannel]);
                //
                txtCurrentValue.Text = fValue.ToString(szFormat) + " " + AnalogOutput.GetUnitName(m_Adam6000Type, m_byAoRange[i_iChannel]);
            }
            else
            {
                txtReadCount.Text += "ReadInputRegs() failed;";
            }
        }
Exemplo n.º 4
0
        private bool RefreshAoModbusValue(int i_AoValueStart, int i_AoChTotal, ref DataGridView dgViewModbus)
        {
            int iIdx;

            int[]  iValueData;
            string szRange, szFormat;

            if (adamModbus.Modbus().ReadInputRegs(i_AoValueStart, i_AoChTotal, out iValueData))
            {
                for (iIdx = 0; iIdx < i_AoChTotal; iIdx++)
                {
                    szRange           = AnalogOutput.GetRangeName(m_Adam6000Type, m_usRange[iIdx]);
                    szFormat          = AnalogOutput.GetFloatFormat(m_Adam6000Type, m_usRange[iIdx]);
                    m_usAoValue[iIdx] = Convert.ToUInt16(iValueData[iIdx]);
                    dgViewModbus.Rows[iIdx].Cells[3].Value = m_usAoValue[iIdx].ToString();
                    dgViewModbus.Rows[iIdx].Cells[4].Value = m_usAoValue[iIdx].ToString("X04");
                    dgViewModbus.Rows[iIdx].Cells[5].Value = AnalogOutput.GetScaledValue(m_Adam6000Type, m_usRange[iIdx], m_usAoValue[iIdx]).ToString(szFormat);
                    dgViewModbus.Rows[iIdx].Cells[6].Value = szRange;
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 5
0
        private void RefreshChannelValue(int i_iChannel, ref TextBox i_txtCh)
        {
            int iStart = m_iSlot * 8 + i_iChannel + 1;

            int[]  iData;
            float  fValue;
            string szFormat;

            if (m_b5000)
            {
                if (adamCom.AnalogOutput(m_iAddr).GetCurrentValue(m_iSlot, i_iChannel, out fValue))
                {
                    szFormat     = AnalogOutput.GetFloatFormat(m_Adam5000Type, m_byRange[i_iChannel]);
                    i_txtCh.Text = fValue.ToString(szFormat) + " " + AnalogOutput.GetUnitName(m_Adam5000Type, m_byRange[i_iChannel]);
                }
                else
                {
                    i_txtCh.Text = "Failed to get";
                }
            }
            else
            {
                if (adamSocket.Modbus(m_iAddr).ReadInputRegs(iStart, 1, out iData))
                {
                    fValue = AnalogOutput.GetScaledValue(m_Adam5000Type, m_byRange[i_iChannel], iData[0]);
                    //
                    szFormat = AnalogOutput.GetFloatFormat(m_Adam5000Type, m_byRange[i_iChannel]);
                    //
                    i_txtCh.Text = fValue.ToString(szFormat) + " " + AnalogOutput.GetUnitName(m_Adam5000Type, m_byRange[i_iChannel]);
                }
                else
                {
                    i_txtCh.Text = "Failed to get";
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Refresh AI Channel Information
        /// </summary>
        /// <returns></returns>
        private bool RefreshData()
        {
            int iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx];

            ushort[] usVal;
            string[] strVal;
            float    fHigh = 0, fLow = 0;

            if (!m_adamSocket.AnalogOutput().GetValues(m_idxID, iChannelTotal, out usVal))
            {
                StatusBar_IO.Text += "ApiErr:" + m_adamSocket.Modbus().LastError.ToString() + " ";
                return(false);
            }
            strVal = new string[usVal.Length];

            for (int i = 0; i < iChannelTotal; i++)
            {
                if (this.IsShowRawData)
                {
                    strVal[i] = usVal[i].ToString("X04");
                }
                else
                {
                    strVal[i] = AnalogOutput.GetScaledValue(this.m_usRanges[i], usVal[i]).ToString(AnalogOutput.GetFloatFormat(this.m_usRanges[i]));
                }
                listViewChInfo.Items[i].SubItems[3].Text = strVal[i].ToString();  //moduify "Value" column
            }
            //Update tBarOutputVal
            if (!b_AOValueModified)
            {
                int idx = 0;
                for (int i = 0; i < listViewChInfo.Items.Count; i++)
                {
                    if (listViewChInfo.Items[i].Selected)
                    {
                        idx = i;
                    }
                }
                AnalogOutput.GetRangeHighLow(m_usRanges[idx], out fHigh, out fLow);
                RefreshOutputPanel(fHigh, fLow, AnalogOutput.GetScaledValue(this.m_usRanges[idx], usVal[idx]));
            }

            return(true);
        }