private void RefreshChannelValueUshortFormat()
        {
            int iStart = 1, iAiStatusStart = 101;
            int iIdx;

            int[]   iData, iAiStatus;
            float[] fValue = new float[m_iAiTotal];

            if (adamModbus.Modbus().ReadInputRegs(iStart, m_iAiTotal, out iData))
            {
                sensorValues.Clear();
                for (iIdx = 0; iIdx < m_iAiTotal; iIdx++)
                {
                    fValue[iIdx] = AnalogInput.GetScaledValue(m_Adam6000Type, m_usRange[iIdx], (ushort)iData[iIdx]);
                }

                if (adamModbus.Modbus().ReadInputRegs(iAiStatusStart, (m_iAiTotal * 2), out iAiStatus))
                {
                    // store data to db
                    //AddToDb(DateTime.Now, fValue[0], 0);
                    //AddToDb(DateTime.Now, fValue[1], 1);
                    //AddToDb(DateTime.Now, fValue[2], 2);
                    //AddToDb(DateTime.Now, fValue[3], 3);
                    for (int num = 0; num < sensorNumber; num++)
                    {
                        sensorValues.Add("sensor" + (num + 1), fValue[num].ToString());
                    }
                    sensorValues.Add("timeOperate", DateTime.Now.ToString("HH:mm:ss"));
                    sensorStatus = "true";
                }
                adamModbus.Disconnect();
            }
        }
Beispiel #2
0
        /// <summary>
        /// 刷新Adam-6018模块的温度和数字量输出状态
        /// </summary>
        public static AdamModule6018 Get_Value_6018(AdamModule6018 Adam)
        {
            if (Adam.ComR != null && Adam.IsComR != false)
            {
                int[]  iData;
                bool[] bData;

                Adam = Get_Range(Adam);

                if (Adam.ComR.Modbus().ReadInputRegs(1, Adam.Temp.Length, out iData))
                {
                    for (int i = 0; i < Adam.Temp.Length; i++)
                    {
                        Adam.Temp[i] = AnalogInput.GetScaledValue(Adam6000Type.Adam6018, Adam.Range[i], iData[i]);      //转化为对应的温度
                    }
                }
                if (Adam.ComT.Modbus().ReadCoilStatus(17, Adam.DO.Length, out bData))
                {
                    for (int i = 0; i < Adam.DO.Length; i++)
                    {
                        Adam.DO[i] = Convert.ToInt32(bData[i]);
                    }
                }
            }
            return(Adam);
        }
Beispiel #3
0
        private void RefreshAiChannelValue()
        {
            int iStart = 1, iStatusStart = 21;
            int iIdx;

            int[]   iData;
            float[] fValue  = new float[m_iAiTotal];
            int[]   iStatus = new int[m_iAiTotal];

            if (adamModbus.Modbus().ReadInputRegs(iStart, m_iAiTotal, out iData) &&
                adamModbus.Modbus().ReadInputRegs(iStatusStart, m_iAiTotal, out iStatus))
            {
                for (iIdx = 0; iIdx < m_iAiTotal; iIdx++)
                {
                    fValue[iIdx] = AnalogInput.GetScaledValue(m_Adam6000Type, m_byAiRange[iIdx], iData[iIdx]);
                }
                RefreshSingleAiChannel(0, ref txtCh0, fValue[0], iStatus[0]);
                RefreshSingleAiChannel(1, ref txtCh1, fValue[1], iStatus[1]);
                RefreshSingleAiChannel(2, ref txtCh2, fValue[2], iStatus[2]);
                RefreshSingleAiChannel(3, ref txtCh3, fValue[3], iStatus[3]);
                RefreshSingleAiChannel(4, ref txtCh4, fValue[4], iStatus[4]);
                RefreshSingleAiChannel(5, ref txtCh5, fValue[5], iStatus[5]);
            }
            else
            {
                txtReadCount.Text += "ReadInputRegs() failed;";
            }
        }
Beispiel #4
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);
        }
Beispiel #5
0
        private void RefreshChannelValueUshortFormat()
        {
            int iStart = 1, iAiStatusStart = 101;
            int iIdx;

            int[]   iData, iAiStatus;
            float[] fValue = new float[m_iAiTotal];

            if (adamModbus.Modbus().ReadInputRegs(iStart, m_iAiTotal, out iData))
            {
                for (iIdx = 0; iIdx < m_iAiTotal; iIdx++)
                {
                    fValue[iIdx] = AnalogInput.GetScaledValue(m_Adam6000Type, m_usRange[iIdx], (ushort)iData[iIdx]);
                }

                if (adamModbus.Modbus().ReadInputRegs(iAiStatusStart, (m_iAiTotal * 2), out iAiStatus))
                {
                    RefreshSingleChannelWithAiStatus(0, ref txtAIValue0, fValue[0], (ushort)iAiStatus[(0 * 2)]);
                    RefreshSingleChannelWithAiStatus(1, ref txtAIValue1, fValue[1], (ushort)iAiStatus[(1 * 2)]);
                    RefreshSingleChannelWithAiStatus(2, ref txtAIValue2, fValue[2], (ushort)iAiStatus[(2 * 2)]);
                    RefreshSingleChannelWithAiStatus(3, ref txtAIValue3, fValue[3], (ushort)iAiStatus[(3 * 2)]);
                    RefreshSingleChannelWithAiStatus(4, ref txtAIValue4, fValue[4], (ushort)iAiStatus[(4 * 2)]);
                    RefreshSingleChannelWithAiStatus(5, ref txtAIValue5, fValue[5], (ushort)iAiStatus[(5 * 2)]);
                    RefreshSingleChannelWithAiStatus(6, ref txtAIValue6, fValue[6], (ushort)iAiStatus[(6 * 2)]);

                    if ((m_Adam6000Type == Adam6000Type.Adam6017) || (m_Adam6000Type == Adam6000Type.Adam6018))
                    {
                        RefreshSingleChannelWithAiStatus(7, ref txtAIValue7, fValue[7], (ushort)iAiStatus[(7 * 2)]);
                    }
                }
            }
        }
        private void RefreshChannelValueUshortFormat(object source, ElapsedEventArgs e)
        {
            int iStart = 1, iAiStatusStart = 101;
            int iIdx;

            int[]   iData, iAiStatus;
            float[] fValue = new float[m_iAiTotal];

            if (adamModbus.Modbus().ReadInputRegs(iStart, m_iAiTotal, out iData))
            {
                for (iIdx = 0; iIdx < m_iAiTotal; iIdx++)
                {
                    fValue[iIdx] = AnalogInput.GetScaledValue(m_Adam6000Type, m_usRange[iIdx], (ushort)iData[iIdx]);
                }

                if (adamModbus.Modbus().ReadInputRegs(iAiStatusStart, (m_iAiTotal * 2), out iAiStatus))
                {
                    // store data to db
                    AddToDb(DateTime.Now, fValue[0], 0);
                    AddToDb(DateTime.Now, fValue[1], 1);
                    AddToDb(DateTime.Now, fValue[2], 2);
                    AddToDb(DateTime.Now, fValue[3], 3);
                }
            }
        }
Beispiel #7
0
        private void RefreshChannelValue()
        {
            int iStart = 1;
            int iIdx;

            int[]   iData;
            float[] fValue = new float[m_iAiTotal];

            if (adamModbus.Modbus().ReadInputRegs(iStart, m_iAiTotal, out iData))
            {
                for (iIdx = 0; iIdx < m_iAiTotal; iIdx++)
                {
                    fValue[iIdx] = AnalogInput.GetScaledValue(m_Adam6000Type, m_byRange[iIdx], (ushort)iData[iIdx]);
                }

                RefreshSingleChannel(0, ref txtAIValue0, fValue[0]);
                RefreshSingleChannel(1, ref txtAIValue1, fValue[1]);
                RefreshSingleChannel(2, ref txtAIValue2, fValue[2]);
                RefreshSingleChannel(3, ref txtAIValue3, fValue[3]);
                RefreshSingleChannel(4, ref txtAIValue4, fValue[4]);
                RefreshSingleChannel(5, ref txtAIValue5, fValue[5]);
                RefreshSingleChannel(6, ref txtAIValue6, fValue[6]);
                RefreshSingleChannel(7, ref txtAIValue7, fValue[7]);
            }
        }
Beispiel #8
0
        public float ReadInputChannelAsFloat(int channel)
        {
            var b         = ReadInputChannelAsByte(channel);
            var inputRegs = ReadInputRegs();
            var res       = AnalogInput.GetScaledValue(adamtype, b, inputRegs[channel]);

            return(res);
        }
Beispiel #9
0
        public string ReadInputChannelAsString(int channel)
        {
            var b         = ReadInputChannelAsByte(channel);
            var ff        = GetFloatFormat(b);
            var inputRegs = ReadInputRegs();
            var res       = AnalogInput.GetScaledValue(adamtype, b, inputRegs[channel]);
            var s         = res.ToString(ff) + " " + AnalogInput.GetUnitName(adamtype, b);

            return(s);
        }
Beispiel #10
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);
        }
Beispiel #11
0
        private void RefreshChannelValueByteFormat()
        {
            int iStart = 1, iBurnStart = 121;
            int iIdx;

            int[]   iData;
            float[] fValue = new float[m_iAiTotal];
            bool[]  bBurn  = new bool[m_iAiTotal];

            if (adamModbus.Modbus().ReadInputRegs(iStart, m_iAiTotal, out iData))
            {
                for (iIdx = 0; iIdx < m_iAiTotal; iIdx++)
                {
                    fValue[iIdx] = AnalogInput.GetScaledValue(m_Adam6000Type, m_byRange[iIdx], iData[iIdx]);
                }

                if (m_Adam6000Type == Adam6000Type.Adam6015)
                {
                    if (adamModbus.Modbus().ReadCoilStatus(iBurnStart, m_iAiTotal, out bBurn)) // read burn out flag
                    {
                        RefreshSingleChannelBurn(0, ref txtAIValue0, fValue[0], bBurn[0]);
                        RefreshSingleChannelBurn(1, ref txtAIValue1, fValue[1], bBurn[1]);
                        RefreshSingleChannelBurn(2, ref txtAIValue2, fValue[2], bBurn[2]);
                        RefreshSingleChannelBurn(3, ref txtAIValue3, fValue[3], bBurn[3]);
                        RefreshSingleChannelBurn(4, ref txtAIValue4, fValue[4], bBurn[4]);
                        RefreshSingleChannelBurn(5, ref txtAIValue5, fValue[5], bBurn[5]);
                        RefreshSingleChannelBurn(6, ref txtAIValue6, fValue[6], bBurn[6]);
                    }
                }
                else
                {
                    RefreshSingleChannel(0, ref txtAIValue0, fValue[0]);
                    RefreshSingleChannel(1, ref txtAIValue1, fValue[1]);
                    RefreshSingleChannel(2, ref txtAIValue2, fValue[2]);
                    RefreshSingleChannel(3, ref txtAIValue3, fValue[3]);
                    RefreshSingleChannel(4, ref txtAIValue4, fValue[4]);
                    RefreshSingleChannel(5, ref txtAIValue5, fValue[5]);
                    RefreshSingleChannel(6, ref txtAIValue6, fValue[6]);
                    RefreshSingleChannel(7, ref txtAIValue7, fValue[7]);
                }
            }
        }
        private void readSensorData()
        {
            int iStart = 1;
            int iIdx;

            int[] iData;

            if (adamModbus.Modbus().ReadInputRegs(iStart, m_iAiTotal, out iData))
            {
                //读数据
                for (iIdx = 0; iIdx < m_iAiTotal; iIdx++)
                {
                    //NOTE : 有一个公式换算 需要后面修改
                    fValue[iIdx] = AnalogInput.GetScaledValue(m_Adam6000Type, m_byRange[iIdx], (ushort)iData[iIdx]);
                    //for test
                    // Console.Write(fValue[iIdx] + " ");
                }
                // Console.WriteLine();
            }
        }
Beispiel #13
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);
        }
Beispiel #14
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);
        }
Beispiel #15
0
        public override void UpdateData()
        {
            int iDiStart = 1;  //start address for discrete inputs

            if (DiscreteInputs != null)
            {
                bool[] bData;

                if (socket.Modbus().ReadCoilStatus(iDiStart, DiscreteInputs.Count, out bData))
                {
                    for (int i = 0; i < DiscreteInputs.Count; i++)
                    {
                        DiscreteInputs.Set(i, bData[i]);
                    }

                    OnUpdateDI(DiscreteInputs);
                }
                else
                {
                }
            }

            int iDoStart = 17; //start address for discrete outputs

            if (DiscreteOutputs != null)
            {
                bool[] bData;

                if (socket.Modbus().ReadCoilStatus(iDoStart, DiscreteOutputs.Count, out bData))
                {
                    for (int i = 0; i < DiscreteOutputs.Count; i++)
                    {
                        DiscreteOutputs.Set(i, bData[i]);
                    }

                    OnUpdateDO(DiscreteOutputs);
                }
                else
                {
                }
            }


            int iAiStart       = 1;
            int iAiStartStatus = 101;

            if (AnalogInputs != null)
            {
                int[]     iData;
                double [] aiData = new double[AnalogInputs.Count];
                if (socket.Modbus().ReadInputRegs(iAiStart, AnalogInputs.Count, out iData))
                {
                    for (int i = 0; i < AnalogInputs.Count; i++)
                    {
                        aiData[i] = AnalogInput.GetScaledValue(Model, AIRanges[i], iData[i]);
                    }
                }

                int[] iAIStatus;

                if (socket.Modbus().ReadInputRegs(iAiStartStatus, (AnalogInputs.Count * 2), out iAIStatus))
                {
                    for (int i = 0; i < AnalogInputs.Count; i++)
                    {
                        ProcessAnalogInputStatus(i, (ushort)iAIStatus[i * 2]);
                    }
                }

                OnUpdateAI(aiData);
            }

            if (AnalogOutputs != null)
            {
            }

            if (CounterInputs != null)
            {
                int   iCounterStart = 1;
                int[] iData;
                int[] counterData = new int[CounterInputs.Count];
                if (socket.Modbus().ReadInputRegs(iCounterStart, CounterInputs.Count * 2, out iData))
                {
                    for (int i = 0; i < CounterInputs.Count; i++)
                    {
                        counterData[i] = iData[2 * i + 1] * 65535 + iData[2 * i];
                    }

                    OnUpdateCounter(counterData);
                }
            }
        }
Beispiel #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);
        }
Beispiel #17
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!";
                    }
                }
            }
        }
Beispiel #18
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!";
                    }
                }
            }
        }
Beispiel #19
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);
        }