Ejemplo n.º 1
0
        /// <summary>
        /// 返回所有通道的数据,格式处理在这里设置
        /// </summary>
        /// <returns></returns>
        private Dictionary <int, string> GetAllChannelValue()
        {
            //string[] values = new string[channelTotal];
            string value      = "";
            int    startIndex = 1;

            int[]   data;
            float[] fValue = new float[channelTotal];

            if (adamModbus.Modbus().ReadInputRegs(startIndex, channelTotal, out data))
            {
                for (int i = 0; i < channelTotal; i++)
                {
                    fValue[i] = AnalogInput.GetScaledValue(adamType, channelRange[i], (ushort)data[i]);
                    if (channelEnabled[i])
                    {
                        string valueFormat = AnalogInput.GetFloatFormat(adamType, channelRange[i]);
                        //values[i] = fValue[i].ToString(valueFormat) + " " + AnalogInput.GetUnitName(adamType, channelRange[i]);
                        value      = fValue[i].ToString(valueFormat);
                        dataDic[i] = value;
                    }
                }
            }
            else
            {
                throw new Adam6217OperationException("ip为:" + slaveIp + ",研华adam6217模块读取输入通道数据失败。");
            }
            return(dataDic);
        }
Ejemplo n.º 2
0
        private void RefreshSingleAiChannel(int i_iIndex, ref TextBox txtCh, float fValue, int i_iStatus)
        {
            string szFormat;

            if (m_bChEnabled[i_iIndex])
            {
                if (i_iStatus == 0)
                {
                    szFormat   = AnalogInput.GetFloatFormat(m_Adam6000Type, m_byAiRange[i_iIndex]);
                    txtCh.Text = fValue.ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam6000Type, m_byAiRange[i_iIndex]);
                }
                else if (i_iStatus == 1)
                {
                    txtCh.Text = "Over(H)";
                }
                else if (i_iStatus == 2)
                {
                    txtCh.Text = "Over(L)";
                }
                else
                {
                    txtCh.Text = "Invalid(R)";
                }
            }
        }
Ejemplo n.º 3
0
        private void RefreshSingleChannel(int i_iIndex, ref TextBox txtCh, float fValue)
        {
            string szFormat;

            if (m_bChEnabled[i_iIndex])
            {
                szFormat   = AnalogInput.GetFloatFormat(m_Adam6000Type, m_byRange[i_iIndex]);
                txtCh.Text = fValue.ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam6000Type, m_byRange[i_iIndex]);
            }
        }
Ejemplo n.º 4
0
 private void RefreshValue(ref TextBox i_txtCh, Adam4000_ChannelStatus i_status, float i_fValue)
 {
     if (i_status == Adam4000_ChannelStatus.Normal)
     {
         i_txtCh.Text = i_fValue.ToString(AnalogInput.GetFloatFormat(m_Adam4000Type, m_adamConfig.TypeCode)) + " " + AnalogInput.GetUnitName(m_Adam4000Type, m_adamConfig.TypeCode);
     }
     else
     {
         i_txtCh.Text = i_status.ToString();
     }
 }
Ejemplo n.º 5
0
        private void RefreshAIValue()
        {
            float[] fVals;
            int[]   iVals;
            Adam4000_ChannelStatus[] status;

            if (m_adamConfig.Format == Adam4000_DataFormat.TwosComplementHex)
            {
                if (adamCom.AnalogInput(m_iAddr).GetValues(1, out iVals))
                {
                    txtAIValue.Text = "0x" + iVals[0].ToString("X04");
                }
                else
                {
                    txtAIValue.Text = "GetValues() failed;";
                }
            }
            else
            {
                if (adamCom.AnalogInput(m_iAddr).GetValues(1, out fVals, out status))
                {
                    if (status[0] == Adam4000_ChannelStatus.Normal)
                    {
                        if (m_adamConfig.Format == Adam4000_DataFormat.EngineerUnit)
                        {
                            txtAIValue.Text = fVals[0].ToString(AnalogInput.GetFloatFormat(m_Adam4000Type, m_adamConfig.TypeCode)) + " " + AnalogInput.GetUnitName(m_Adam4000Type, m_adamConfig.TypeCode);
                        }
                        else if (m_adamConfig.Format == Adam4000_DataFormat.Percent)
                        {
                            txtAIValue.Text = fVals[0].ToString("#0.00") + " %";
                        }
                        else if (m_adamConfig.Format == Adam4000_DataFormat.Ohms)
                        {
                            txtAIValue.Text = fVals[0].ToString("#0.000") + " ohms";
                        }
                    }
                    else
                    {
                        txtAIValue.Text = status[0].ToString();
                    }
                }
                else
                {
                    txtAIValue.Text = "GetValues() failed;";
                }
            }
        }
Ejemplo n.º 6
0
        private void RefreshSingleChannelBurn(int i_iIndex, ref TextBox i_txtCh, float i_fValue, bool i_bBurn)
        {
            string szFormat;

            if (m_bChEnabled[i_iIndex])
            {
                if (i_bBurn)
                {
                    i_txtCh.Text = "Burn out";
                }
                else
                {
                    szFormat     = AnalogInput.GetFloatFormat(m_Adam6000Type, m_byRange[i_iIndex]);
                    i_txtCh.Text = i_fValue.ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam6000Type, m_byRange[i_iIndex]);
                }
            }
        }
Ejemplo n.º 7
0
 private void RefreshValue(ref TextBox i_txtCh, Adam4000_ChannelStatus i_status, float i_fValue, byte i_byRange)
 {
     if (i_status == Adam4000_ChannelStatus.Normal)
     {
         if (m_adamConfig.Format == Adam4000_DataFormat.EngineerUnit)
         {
             i_txtCh.Text = i_fValue.ToString(AnalogInput.GetFloatFormat(m_Adam4000Type, i_byRange)) + " " + AnalogInput.GetUnitName(m_Adam4000Type, i_byRange);
         }
         else if (m_adamConfig.Format == Adam4000_DataFormat.Percent)
         {
             i_txtCh.Text = i_fValue.ToString("#0.00") + " %";
         }
     }
     else
     {
         i_txtCh.Text = i_status.ToString();
     }
 }
Ejemplo n.º 8
0
        private void RefreshAdam5013ChannelValue()
        {
            int iStart = m_iSlot * 8 + 1;

            float[] fVal;
            string  szFormat, szUnit;


            if (adamCtl.AnalogInput().GetValues(m_iSlot, m_iChTotal, out fVal))
            {
                // floating format
                szFormat = AnalogInput.GetFloatFormat(m_Adam5000Type, m_byRange);
                szUnit   = AnalogInput.GetUnitName(m_Adam5000Type, m_byRange);
                //
                if (chkboxCh0.Checked)
                {
                    txtAIValue0.Text = fVal[0].ToString(szFormat) + " " + szUnit;
                }
                if (chkboxCh1.Checked)
                {
                    txtAIValue1.Text = fVal[1].ToString(szFormat) + " " + szUnit;
                }
                if (chkboxCh2.Checked)
                {
                    txtAIValue2.Text = fVal[2].ToString(szFormat) + " " + szUnit;
                }
            }
            else
            {
                if (chkboxCh0.Checked)
                {
                    txtAIValue0.Text = "Failed to get!";
                }
                if (chkboxCh1.Checked)
                {
                    txtAIValue1.Text = "Failed to get!";
                }
                if (chkboxCh2.Checked)
                {
                    txtAIValue2.Text = "Failed to get!";
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 返回特定通道的数据字符串,数据格式在这里设置
        /// </summary>
        /// <param name="channelIndex">通道的索引0-7</param>
        /// <returns></returns>
        public string GetChannelSingleValue(int channelIndex)
        {
            string value = string.Empty;

            int[] data;
            float fValue;
            int   index = channelIndex;

            if (adamModbus.Modbus().ReadInputRegs(channelIndex + 1, 1, out data))
            {
                fValue = AnalogInput.GetScaledValue(adamType, channelRange[index], (ushort)data[0]);
                if (channelEnabled[index])
                {
                    string valueFormat = AnalogInput.GetFloatFormat(adamType, channelRange[index]);
                    value = fValue.ToString(valueFormat) + " " + AnalogInput.GetUnitName(adamType, channelRange[index]);
                }
            }
            return(value);
        }
Ejemplo n.º 10
0
        private void RefreshSingleChannelWithAiStatus(int i_iIndex, ref TextBox i_txtCh, float i_fValue, ushort i_usAiStatus)
        {
            string szFormat;
            string szRange;
            string szErrorMsg = string.Empty;
            string szComma    = " , ";

            szRange = AnalogInput.GetRangeName(m_Adam6000Type, m_usRange[i_iIndex]);

            if (m_bChEnabled[i_iIndex])
            {
                if (i_usAiStatus == (ushort)Adam_AiStatus_LowAddress.No_Fault_Detected)
                {
                    szErrorMsg   = string.Empty;
                    szFormat     = AnalogInput.GetFloatFormat(m_Adam6000Type, m_usRange[i_iIndex]);
                    i_txtCh.Text = i_fValue.ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam6000Type, m_usRange[i_iIndex]);
                }
                else
                {
                    if ((i_usAiStatus & (ushort)Adam_AiStatus_LowAddress.FailToProvideAiValueUartTimeout) == (ushort)Adam_AiStatus_LowAddress.FailToProvideAiValueUartTimeout)
                    {
                        szErrorMsg = "Fail to provide AI value (UART timeout)";
                    }
                    else if ((i_usAiStatus & (ushort)Adam_AiStatus_LowAddress.Over_Range) == (ushort)Adam_AiStatus_LowAddress.Over_Range)
                    {
                        szErrorMsg = (szErrorMsg == string.Empty) ? ("Over Range") : (szErrorMsg + szComma + "Over Range");
                    }
                    else if ((i_usAiStatus & (ushort)Adam_AiStatus_LowAddress.Under_Range) == (ushort)Adam_AiStatus_LowAddress.Under_Range)
                    {
                        szErrorMsg = (szErrorMsg == string.Empty) ? ("Under Range") : (szErrorMsg + szComma + "Under Range");
                    }
                    else if ((i_usAiStatus & (ushort)Adam_AiStatus_LowAddress.Open_Circuit_Burnout) == (ushort)Adam_AiStatus_LowAddress.Open_Circuit_Burnout)
                    {
                        szErrorMsg = (szErrorMsg == string.Empty) ? ("Open Circuit (Burnout)") : (szErrorMsg + szComma + "Open Circuit (Burnout)");
                    }
                    else if ((i_usAiStatus & (ushort)Adam_AiStatus_LowAddress.Zero_Span_CalibrationError) == (ushort)Adam_AiStatus_LowAddress.Zero_Span_CalibrationError)
                    {
                        szErrorMsg = (szErrorMsg == string.Empty) ? ("Zero/Span Calibration Error") : (szErrorMsg + szComma + "Zero/Span Calibration Error");
                    }
                    i_txtCh.Text = szErrorMsg;
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 返回所有通道的数据,格式处理在这里设置
        /// </summary>
        /// <returns></returns>
        public string[] GetAllChannelValue()
        {
            string[] values     = new string[channelTotal];
            int      startIndex = 1;

            int[]   data;
            float[] fValue = new float[channelTotal];

            if (adamModbus.Modbus().ReadInputRegs(startIndex, channelTotal, out data))
            {
                for (int i = 0; i < channelTotal; i++)
                {
                    fValue[i] = AnalogInput.GetScaledValue(adamType, channelRange[i], (ushort)data[i]);
                    if (channelEnabled[i])
                    {
                        string valueFormat = AnalogInput.GetFloatFormat(adamType, channelRange[i]);
                        values[i] = fValue[i].ToString(valueFormat) + " " + AnalogInput.GetUnitName(adamType, channelRange[i]);
                    }
                }
            }
            return(values);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 返回特定通道的数据字符串,数据格式在这里设置
        /// </summary>
        /// <param name="channelIndex">通道的索引0-7</param>
        /// <returns></returns>
        private string GetChannelSingleValue(int channelIndex)
        {
            string value = string.Empty;

            int[] data;
            float fValue;
            int   index = channelIndex;

            if (adamModbus.Modbus().ReadInputRegs(channelIndex + 1, 1, out data))
            {
                fValue = AnalogInput.GetScaledValue(adamType, channelRange[index], (ushort)data[0]);
                if (channelEnabled[index])
                {
                    string valueFormat = AnalogInput.GetFloatFormat(adamType, channelRange[index]);
                    value = fValue.ToString(valueFormat);
                }
            }
            else
            {
                throw new Adam6217OperationException("ip为:" + slaveIp + ",研华adam6217模块读取输入通道数据失败。");
            }
            return(value);
        }
Ejemplo n.º 13
0
        private bool RefreshValue(int i_iCh, ref TextBox i_txtCh)
        {
            float fVal;
            Adam4000_ChannelStatus status;

            if (m_bCh[i_iCh] == false) // channel disabled
            {
                i_txtCh.Text = "";
                return(true);
            }
            if (adamCom.AnalogInput(m_iAddr).GetValue(i_iCh, out fVal, out status))
            {
                if (status == Adam4000_ChannelStatus.Normal)
                {
                    i_txtCh.Text = fVal.ToString(AnalogInput.GetFloatFormat(m_Adam4000Type, m_adamConfig.TypeCode)) + " " + AnalogInput.GetUnitName(m_Adam4000Type, m_adamConfig.TypeCode);
                }
                else
                {
                    i_txtCh.Text = fVal.ToString();
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 获取浮动格式
        /// </summary>
        public static string RefreshValue(AdamModule6018 Adam, int Channel)
        {
            string szFormat = AnalogInput.GetFloatFormat(Adam6000Type.Adam6018, Adam.Range[Channel]);

            return(Adam.Temp[Channel].ToString(szFormat));
        }
Ejemplo n.º 15
0
        private void RefreshChannelValue()
        {
            float[] fValue;
            string  szFormat;


            if (adamCtl.AnalogInput().GetValues(m_iSlot, m_iChTotal, out fValue))
            {
                //
                szFormat = AnalogInput.GetFloatFormat(m_Adam5000Type, m_byRange[0]);
                //
                if (chkboxCh0.Checked)
                {
                    txtAIValue0.Text = fValue[0].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[0]);
                }
                if (chkboxCh1.Checked)
                {
                    txtAIValue1.Text = fValue[1].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[1]);
                }
                if (chkboxCh2.Checked)
                {
                    txtAIValue2.Text = fValue[2].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[2]);
                }
                if (chkboxCh3.Checked)
                {
                    txtAIValue3.Text = fValue[3].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[3]);
                }
                if (chkboxCh4.Checked)
                {
                    txtAIValue4.Text = fValue[4].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[4]);
                }
                if (chkboxCh5.Checked)
                {
                    txtAIValue5.Text = fValue[5].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[5]);
                }
                if (chkboxCh6.Checked)
                {
                    txtAIValue6.Text = fValue[6].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[6]);
                }
                if (chkboxCh7.Checked)
                {
                    txtAIValue7.Text = fValue[7].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[7]);
                }
            }
            else
            {
                if (chkboxCh0.Checked)
                {
                    txtAIValue0.Text = "Failed to get!";
                }
                if (chkboxCh1.Checked)
                {
                    txtAIValue1.Text = "Failed to get!";
                }
                if (chkboxCh2.Checked)
                {
                    txtAIValue2.Text = "Failed to get!";
                }
                if (chkboxCh3.Checked)
                {
                    txtAIValue3.Text = "Failed to get!";
                }
                if (chkboxCh4.Checked)
                {
                    txtAIValue4.Text = "Failed to get!";
                }
                if (chkboxCh5.Checked)
                {
                    txtAIValue5.Text = "Failed to get!";
                }
                if (chkboxCh6.Checked)
                {
                    txtAIValue6.Text = "Failed to get!";
                }
                if (chkboxCh7.Checked)
                {
                    txtAIValue7.Text = "Failed to get!";
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Refresh AI Channel Information
        /// </summary>
        /// <returns></returns>
        private bool RefreshData()
        {
            int iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx];

            if (this.m_uiChMask != 0x00)
            {
                ushort[] usVal;
                Advantech.Adam.Apax5000_ChannelStatus[] aStatus;

                if (!m_adamCtl.AnalogInput().GetChannelStatus(m_idxID, iChannelTotal, out aStatus))
                {
                    StatusBar_IO.Text += "[GetChannelStatus] ApiErr:" + m_adamCtl.AnalogInput().ApiLastError.ToString() + " ";
                    return(false);
                }
                if (!m_adamCtl.AnalogInput().GetValues(m_idxID, iChannelTotal, out usVal))
                {
                    StatusBar_IO.Text += "[GetValues] ApiErr:" + m_adamCtl.AnalogInput().ApiLastError.ToString() + " ";
                    return(false);
                }

                string[] strVal    = new string[iChannelTotal];
                string[] strStatus = new string[iChannelTotal];
                double[] dVals     = new double[iChannelTotal];

                for (int i = 0; i < iChannelTotal; i++)
                {
                    if (m_aConf.wPktVer >= 0x0002)
                    {
                        dVals[i] = AnalogInput.GetScaledValueWithResolution(this.m_usRanges[i], usVal[i], m_aConf.wHwIoType_0_Resolution);
                    }
                    else
                    {
                        if (m_aConf.GetModuleName() == "5017H")
                        {
                            dVals[i] = AnalogInput.GetScaledValueWithResolution(this.m_usRanges[i], usVal[i], 12);
                        }
                        else
                        {
                            dVals[i] = AnalogInput.GetScaledValue(this.m_usRanges[i], usVal[i]);
                        }
                    }

                    if (m_bChMask[i])
                    {
                        if (this.IsShowRawData)
                        {
                            strVal[i] = usVal[i].ToString("X04");
                        }
                        else
                        {
                            strVal[i] = dVals[i].ToString(AnalogInput.GetFloatFormat(this.m_usRanges[i]));
                        }
                        strStatus[i] = aStatus[i].ToString();
                    }
                    else
                    {
                        strVal[i]    = "*****";
                        strStatus[i] = "Disable";
                    }
                    listViewChInfo.Items[i].SubItems[2].Text = strVal[i].ToString();    //moduify "Value" column
                    listViewChInfo.Items[i].SubItems[3].Text = strStatus[i].ToString(); //modify "Ch Status" column
                }
            }
            else
            {
                for (int i = 0; i < iChannelTotal; i++)
                {
                    listViewChInfo.Items[i].SubItems[2].Text = "******";        //moduify "Value" column
                    listViewChInfo.Items[i].SubItems[3].Text = "******";        //modify "Ch Status" column
                }
            }
            return(true);
        }
Ejemplo n.º 17
0
 public string GetFloatFormat(byte b)
 {
     return(AnalogInput.GetFloatFormat(adamtype, b));
 }
Ejemplo n.º 18
0
        private void RefreshAdam5018ChannelValue()
        {
            int iStart = m_iSlot * 8 + 1;

            int[]   iData;
            float[] fVal;
            float   fValue;
            string  szFormat, szUnit;

            if (m_b5000)
            {
                if (adamCom.AnalogInput(m_iAddr).GetValues(m_iSlot, m_iChTotal, out fVal))
                {
                    // floating format
                    szFormat = AnalogInput.GetFloatFormat(m_Adam5000Type, m_byRange);
                    szUnit   = AnalogInput.GetUnitName(m_Adam5000Type, m_byRange);
                    //
                    if (chkboxCh0.Checked)
                    {
                        txtAIValue0.Text = fVal[0].ToString(szFormat) + " " + szUnit;
                    }
                    if (chkboxCh1.Checked)
                    {
                        txtAIValue1.Text = fVal[1].ToString(szFormat) + " " + szUnit;
                    }
                    if (chkboxCh2.Checked)
                    {
                        txtAIValue2.Text = fVal[2].ToString(szFormat) + " " + szUnit;
                    }
                    if (chkboxCh3.Checked)
                    {
                        txtAIValue3.Text = fVal[3].ToString(szFormat) + " " + szUnit;
                    }
                    if (chkboxCh4.Checked)
                    {
                        txtAIValue4.Text = fVal[4].ToString(szFormat) + " " + szUnit;
                    }
                    if (chkboxCh5.Checked)
                    {
                        txtAIValue5.Text = fVal[5].ToString(szFormat) + " " + szUnit;
                    }
                    if (chkboxCh6.Checked)
                    {
                        txtAIValue6.Text = fVal[6].ToString(szFormat) + " " + szUnit;
                    }
                }
                else
                {
                    if (chkboxCh0.Checked)
                    {
                        txtAIValue0.Text = "Failed to get!";
                    }
                    if (chkboxCh1.Checked)
                    {
                        txtAIValue1.Text = "Failed to get!";
                    }
                    if (chkboxCh2.Checked)
                    {
                        txtAIValue2.Text = "Failed to get!";
                    }
                    if (chkboxCh3.Checked)
                    {
                        txtAIValue3.Text = "Failed to get!";
                    }
                    if (chkboxCh4.Checked)
                    {
                        txtAIValue4.Text = "Failed to get!";
                    }
                    if (chkboxCh5.Checked)
                    {
                        txtAIValue5.Text = "Failed to get!";
                    }
                    if (chkboxCh6.Checked)
                    {
                        txtAIValue6.Text = "Failed to get!";
                    }
                }
            }
            else
            {
                if (adamSocket.Modbus().ReadInputRegs(iStart, m_iChTotal, out iData))
                {
                    // floating format
                    szFormat = AnalogInput.GetFloatFormat(m_Adam5000Type, m_byRange);
                    szUnit   = AnalogInput.GetUnitName(m_Adam5000Type, m_byRange);
                    //
                    if (chkboxCh0.Checked)
                    {
                        fValue           = AnalogInput.GetScaledValue(m_Adam5000Type, m_byRange, iData[0]);
                        txtAIValue0.Text = fValue.ToString(szFormat) + " " + szUnit;
                    }
                    if (chkboxCh1.Checked)
                    {
                        fValue           = AnalogInput.GetScaledValue(m_Adam5000Type, m_byRange, iData[1]);
                        txtAIValue1.Text = fValue.ToString(szFormat) + " " + szUnit;
                    }
                    if (chkboxCh2.Checked)
                    {
                        fValue           = AnalogInput.GetScaledValue(m_Adam5000Type, m_byRange, iData[2]);
                        txtAIValue2.Text = fValue.ToString(szFormat) + " " + szUnit;
                    }
                    if (chkboxCh3.Checked)
                    {
                        fValue           = AnalogInput.GetScaledValue(m_Adam5000Type, m_byRange, iData[3]);
                        txtAIValue3.Text = fValue.ToString(szFormat) + " " + szUnit;
                    }
                    if (chkboxCh4.Checked)
                    {
                        fValue           = AnalogInput.GetScaledValue(m_Adam5000Type, m_byRange, iData[4]);
                        txtAIValue4.Text = fValue.ToString(szFormat) + " " + szUnit;
                    }
                    if (chkboxCh5.Checked)
                    {
                        fValue           = AnalogInput.GetScaledValue(m_Adam5000Type, m_byRange, iData[5]);
                        txtAIValue5.Text = fValue.ToString(szFormat) + " " + szUnit;
                    }
                    if (chkboxCh6.Checked)
                    {
                        fValue           = AnalogInput.GetScaledValue(m_Adam5000Type, m_byRange, iData[6]);
                        txtAIValue6.Text = fValue.ToString(szFormat) + " " + szUnit;
                    }
                }
                else
                {
                    if (chkboxCh0.Checked)
                    {
                        txtAIValue0.Text = "Failed to get!";
                    }
                    if (chkboxCh1.Checked)
                    {
                        txtAIValue1.Text = "Failed to get!";
                    }
                    if (chkboxCh2.Checked)
                    {
                        txtAIValue2.Text = "Failed to get!";
                    }
                    if (chkboxCh3.Checked)
                    {
                        txtAIValue3.Text = "Failed to get!";
                    }
                    if (chkboxCh4.Checked)
                    {
                        txtAIValue4.Text = "Failed to get!";
                    }
                    if (chkboxCh5.Checked)
                    {
                        txtAIValue5.Text = "Failed to get!";
                    }
                    if (chkboxCh6.Checked)
                    {
                        txtAIValue6.Text = "Failed to get!";
                    }
                }
            }
        }
Ejemplo n.º 19
0
        private void RefreshChannelValue()
        {
            int iStart = m_iSlot * 8 + 1;
            int iIdx;

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

            if (m_b5000)
            {
                if (m_byFormat == (byte)Adam5000_DataFormat.EngineerUnit)
                {
                    if (adamCom.AnalogInput(m_iAddr).GetValues(m_iSlot, m_iChTotal, out fValue))
                    {
                        //
                        szFormat = AnalogInput.GetFloatFormat(m_Adam5000Type, m_byRange[0]);
                        //
                        if (chkboxCh0.Checked)
                        {
                            txtAIValue0.Text = fValue[0].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[0]);
                        }
                        if (chkboxCh1.Checked)
                        {
                            txtAIValue1.Text = fValue[1].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[1]);
                        }
                        if (chkboxCh2.Checked)
                        {
                            txtAIValue2.Text = fValue[2].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[2]);
                        }
                        if (chkboxCh3.Checked)
                        {
                            txtAIValue3.Text = fValue[3].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[3]);
                        }
                        if (chkboxCh4.Checked)
                        {
                            txtAIValue4.Text = fValue[4].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[4]);
                        }
                        if (chkboxCh5.Checked)
                        {
                            txtAIValue5.Text = fValue[5].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[5]);
                        }
                        if (chkboxCh6.Checked)
                        {
                            txtAIValue6.Text = fValue[6].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[6]);
                        }
                        if (chkboxCh7.Checked)
                        {
                            txtAIValue7.Text = fValue[7].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[7]);
                        }
                    }
                    else
                    {
                        if (chkboxCh0.Checked)
                        {
                            txtAIValue0.Text = "Failed to get!";
                        }
                        if (chkboxCh1.Checked)
                        {
                            txtAIValue1.Text = "Failed to get!";
                        }
                        if (chkboxCh2.Checked)
                        {
                            txtAIValue2.Text = "Failed to get!";
                        }
                        if (chkboxCh3.Checked)
                        {
                            txtAIValue3.Text = "Failed to get!";
                        }
                        if (chkboxCh4.Checked)
                        {
                            txtAIValue4.Text = "Failed to get!";
                        }
                        if (chkboxCh5.Checked)
                        {
                            txtAIValue5.Text = "Failed to get!";
                        }
                        if (chkboxCh6.Checked)
                        {
                            txtAIValue6.Text = "Failed to get!";
                        }
                        if (chkboxCh7.Checked)
                        {
                            txtAIValue7.Text = "Failed to get!";
                        }
                    }
                }
                else if (m_byFormat == (byte)Adam5000_DataFormat.TwosComplementHex)
                {
                    if (adamCom.AnalogInput(m_iAddr).GetValues(m_iSlot, m_iChTotal, out iData))
                    {
                        szFormat = "X04";
                        //
                        if (chkboxCh0.Checked)
                        {
                            txtAIValue0.Text = "0x" + iData[0].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[0]);
                        }
                        if (chkboxCh1.Checked)
                        {
                            txtAIValue1.Text = "0x" + iData[1].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[1]);
                        }
                        if (chkboxCh2.Checked)
                        {
                            txtAIValue2.Text = "0x" + iData[2].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[2]);
                        }
                        if (chkboxCh3.Checked)
                        {
                            txtAIValue3.Text = "0x" + iData[3].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[3]);
                        }
                        if (chkboxCh4.Checked)
                        {
                            txtAIValue4.Text = "0x" + iData[4].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[4]);
                        }
                        if (chkboxCh5.Checked)
                        {
                            txtAIValue5.Text = "0x" + iData[5].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[5]);
                        }
                        if (chkboxCh6.Checked)
                        {
                            txtAIValue6.Text = "0x" + iData[6].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[6]);
                        }
                        if (chkboxCh7.Checked)
                        {
                            txtAIValue7.Text = "0x" + iData[7].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[7]);
                        }
                    }
                    else
                    {
                        if (chkboxCh0.Checked)
                        {
                            txtAIValue0.Text = "Failed to get!";
                        }
                        if (chkboxCh1.Checked)
                        {
                            txtAIValue1.Text = "Failed to get!";
                        }
                        if (chkboxCh2.Checked)
                        {
                            txtAIValue2.Text = "Failed to get!";
                        }
                        if (chkboxCh3.Checked)
                        {
                            txtAIValue3.Text = "Failed to get!";
                        }
                        if (chkboxCh4.Checked)
                        {
                            txtAIValue4.Text = "Failed to get!";
                        }
                        if (chkboxCh5.Checked)
                        {
                            txtAIValue5.Text = "Failed to get!";
                        }
                        if (chkboxCh6.Checked)
                        {
                            txtAIValue6.Text = "Failed to get!";
                        }
                        if (chkboxCh7.Checked)
                        {
                            txtAIValue7.Text = "Failed to get!";
                        }
                    }
                }
            }
            else
            {
                if (adamSocket.Modbus().ReadInputRegs(iStart, m_iChTotal, out iData))
                {
                    fValue = new float[m_iChTotal];
                    for (iIdx = 0; iIdx < m_iChTotal; iIdx++)
                    {
                        fValue[iIdx] = AnalogInput.GetScaledValue(m_Adam5000Type, m_byRange[iIdx], iData[iIdx]);
                    }
                    //
                    szFormat = AnalogInput.GetFloatFormat(m_Adam5000Type, m_byRange[0]);
                    //
                    if (chkboxCh0.Checked)
                    {
                        txtAIValue0.Text = fValue[0].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[0]);
                    }
                    if (chkboxCh1.Checked)
                    {
                        txtAIValue1.Text = fValue[1].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[1]);
                    }
                    if (chkboxCh2.Checked)
                    {
                        txtAIValue2.Text = fValue[2].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[2]);
                    }
                    if (chkboxCh3.Checked)
                    {
                        txtAIValue3.Text = fValue[3].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[3]);
                    }
                    if (chkboxCh4.Checked)
                    {
                        txtAIValue4.Text = fValue[4].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[4]);
                    }
                    if (chkboxCh5.Checked)
                    {
                        txtAIValue5.Text = fValue[5].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[5]);
                    }
                    if (chkboxCh6.Checked)
                    {
                        txtAIValue6.Text = fValue[6].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[6]);
                    }
                    if (chkboxCh7.Checked)
                    {
                        txtAIValue7.Text = fValue[7].ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam5000Type, m_byRange[7]);
                    }
                }
                else
                {
                    if (chkboxCh0.Checked)
                    {
                        txtAIValue0.Text = "Failed to get!";
                    }
                    if (chkboxCh1.Checked)
                    {
                        txtAIValue1.Text = "Failed to get!";
                    }
                    if (chkboxCh2.Checked)
                    {
                        txtAIValue2.Text = "Failed to get!";
                    }
                    if (chkboxCh3.Checked)
                    {
                        txtAIValue3.Text = "Failed to get!";
                    }
                    if (chkboxCh4.Checked)
                    {
                        txtAIValue4.Text = "Failed to get!";
                    }
                    if (chkboxCh5.Checked)
                    {
                        txtAIValue5.Text = "Failed to get!";
                    }
                    if (chkboxCh6.Checked)
                    {
                        txtAIValue6.Text = "Failed to get!";
                    }
                    if (chkboxCh7.Checked)
                    {
                        txtAIValue7.Text = "Failed to get!";
                    }
                }
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Refresh AI Channel Information
        /// </summary>
        /// <returns></returns>
        private bool RefreshData()
        {
            int iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx];

            if (this.m_uiChMask != 0x00)
            {
                ushort[] usVal;
                Advantech.Adam.Apax5000_ChannelStatus[] aStatus;

                if (!m_adamSocket.AnalogInput().GetChannelStatus(m_idxID, iChannelTotal, out aStatus))
                {
                    StatusBar_IO.Text += "[GetChannelStatus] ApiErr:" + m_adamSocket.Modbus().LastError.ToString() + " ";
                    return(false);
                }
                if (!m_adamSocket.AnalogInput().GetValues(m_idxID, iChannelTotal, out usVal))
                {
                    StatusBar_IO.Text += "[GetValues] ApiErr:" + m_adamSocket.Modbus().LastError.ToString() + " ";
                    return(false);
                }

                string[] strVal      = new string[iChannelTotal];
                string[] strStatus   = new string[iChannelTotal];
                double[] dVals       = new double[iChannelTotal];
                bool     bHasTCRange = false;

                for (int i = 0; i < iChannelTotal; i++)
                {
                    if (m_aConf.wPktVer >= 0x0002)
                    {
                        dVals[i] = AnalogInput.GetScaledValueWithResolution(this.m_usRanges[i], usVal[i], m_aConf.wHwIoType_0_Resolution);
                    }
                    else
                    {
                        if (m_aConf.GetModuleName() == "5017H")
                        {
                            dVals[i] = AnalogInput.GetScaledValueWithResolution(this.m_usRanges[i], usVal[i], 12);
                        }
                        else
                        {
                            dVals[i] = AnalogInput.GetScaledValue(this.m_usRanges[i], usVal[i]);
                        }
                    }

                    if (m_usRanges[i] >= 0x400 && m_usRanges[i] < 0x500)
                    {
                        bHasTCRange = true;
                    }
                    if (m_bChMask[i])
                    {
                        if (this.IsShowRawData)
                        {
                            strVal[i] = usVal[i].ToString("X04");
                        }
                        else
                        {
                            strVal[i] = dVals[i].ToString(AnalogInput.GetFloatFormat(this.m_usRanges[i]));
                        }
                        strStatus[i] = aStatus[i].ToString();
                    }
                    else
                    {
                        strVal[i]    = "*****";
                        strStatus[i] = "Disable";
                    }

                    listViewChInfo.Items[i].SubItems[3].Text = strVal[i].ToString();    //moduify "Value" column
                    listViewChInfo.Items[i].SubItems[4].Text = strStatus[i].ToString(); //modify "Ch Status" column
                }

                if (bHasTCRange && (((m_iScanCount * timer1.Interval) % 5000 >= 0) && ((m_iScanCount * timer1.Interval) % 5000 < 1)))
                {
                    float fCJCVal;
                    Apax5000_ChannelStatus o_Status;
                    if (m_adamSocket.AnalogInput().GetCJCValue(m_idxID, out fCJCVal, out o_Status))
                    {
                        if (o_Status == Apax5000_ChannelStatus.CJCTempError)
                        {
                            timer1.Enabled = false;
                            MessageBox.Show("The CJC temperature sensor failed!\nPlease check device is install correctly.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                            StatusBar_IO.Text += "The CJC temperature sensor failed! Please check device is install correctly.";
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < iChannelTotal; i++)
                {
                    listViewChInfo.Items[i].SubItems[3].Text = "******";        //moduify "Value" column
                    listViewChInfo.Items[i].SubItems[4].Text = "******";        //modify "Ch Status" column
                }
            }
            return(true);
        }