Exemplo n.º 1
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))
            {
                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();
            }
        }
Exemplo n.º 2
0
        public void buttonStart()
        {
            int iDiStart = 1;

            int iConfigStart;

            bool[] bDiData;
            int    iChTotal = 2;
            string dataButton;
            int    iStart;
            int    iOnOff;

            iConfigStart = Counter.GetChannelStart(m_Adam6000Type);
            iStart       = 17 + 6 - 12;
            if (m_adamModbus.Modbus().ReadCoilStatus(iDiStart, 12, out bDiData))
            {
                dataButton = bDiData[6].ToString();
                if (dataButton == "True")
                {
                    Console.WriteLine("Button OFF");
                    iOnOff = 0;
                }
                else
                {
                    Console.WriteLine("Button ON");
                    iOnOff = 1;
                }
            }
            else
            {
                Console.WriteLine("Failed to read status...");
            }
        }
Exemplo n.º 3
0
        //*****************************

        public static void Read_AdamValues6018()
        {
            try
            {
                int   iIdx;
                int[] iData;

                while (true)
                {
                    if (m_bRegister1) // Read registers (4X references)
                    {
                        adamTCP1.Connect(m_IP18, ProtocolType.Tcp, m_iPort);
                        if (adamTCP1.Modbus().ReadHoldingRegs(m_iStart1, m_iLength1, out iData))
                        {
                            for (iIdx = 0; iIdx < m_iLength1; iIdx++)
                            {
                                Double ValF = ((Convert.ToDouble(iData[iIdx]) * 1370) / 65535) * 1000;
                                Global.GenData[10 + iIdx] = (Global.RandomNumberBetween((ValF + 0.0001), (ValF - 0.0002)) / 1000).ToString("000.0000");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return;
            }
        }
Exemplo n.º 4
0
        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);
                }
            }
        }
Exemplo n.º 5
0
        public static void Read_AdamValues6017()
        {
            try
            {
                int   iIdx;
                int[] iData;

                while (true)
                {
                    if (m_bRegister2) // Read registers (4X references)
                    {
                        adamTCP2.Connect(m_IP17, ProtocolType.Tcp, m_iPort);
                        if (adamTCP2.Modbus().ReadHoldingRegs(m_iStart2, m_iLength2, out iData))
                        {
                            for (iIdx = 0; iIdx < m_iLength2; iIdx++)
                            {
                                Double V    = (Double.Parse(Global.PMax[18 + iIdx]) - Double.Parse(Global.PMin[18 + iIdx])) / 16;
                                Double ValF = ((Convert.ToDouble(iData[iIdx]) * 16) / 65535) * 1000;
                                Global.GenData[18 + iIdx] = ((Global.RandomNumberBetween((ValF + 0.0001), (ValF - 0.0003)) * V / 1000) + Double.Parse(Global.PMin[18 + iIdx])).ToString("000.0000");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Check module controllable
        /// </summary>
        /// <returns></returns>
        private bool CheckControllable()
        {
            ushort active;

            if (m_adamSocket.Configuration().SYS_GetGlobalActive(out active))
            {
                if (active == 1)
                {
                    return(true);
                }
                else
                {
                    MessageBox.Show("There is another controller taking control, so you only can monitor IO data.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                    return(false);
                }
            }
            else if (m_adamSocket.Modbus().LastError == Advantech.Common.ErrorCode.Socket_Recv_Fail)
            {
                MessageBox.Show("SYS_GetGlobalActive failed (Err: " + m_adamSocket.Modbus().LastError.ToString() + ")", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
            }
            else
            {
                MessageBox.Show("Checking controllable failed, utility only could monitor io data now. (" + m_adamSocket.Modbus().LastError.ToString() + ")", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
            }
            return(false);
        }
Exemplo n.º 7
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            int iIdx;

            int[] iData;

            if (m_bRegister1) // Read registers (4X references)
            {
                adamTCP1.Connect(m_IP18, ProtocolType.Tcp, m_iPort);
                if (adamTCP1.Modbus().ReadHoldingRegs(m_iStart1, m_iLength1, out iData))
                {
                    for (iIdx = 0; iIdx < m_iLength1; iIdx++)
                    {
                        Double ValF = ((Convert.ToDouble(iData[iIdx]) * 1370) / 65535) * 1000;
                        DGView11[iIdx + 2, 0].Value = ((rand1.Next(((int)ValF - 1), ((int)ValF + 1))) / 1000.0).ToString("000.000");
                    }
                }
                m_bRegister1 = false;
                m_bRegister2 = true;
            }
            else if (m_bRegister2)             // Read registers (4X references)
            {
                adamTCP2.Connect(m_IP17, ProtocolType.Tcp, m_iPort);
                if (adamTCP2.Modbus().ReadHoldingRegs(m_iStart2, m_iLength2, out iData))
                {
                    for (iIdx = 0; iIdx < m_iLength2; iIdx++)
                    {
                        Double ValF = ((Convert.ToDouble(iData[iIdx]) * 16) / 65535) * 1000;
                        DGView11[iIdx + 2, 1].Value = (((rand1.Next(((int)ValF - 1), ((int)ValF + 1))) / 1000.0) + 4).ToString("000.000");
                    }
                }
                m_bRegister2 = false;
                m_bRegister1 = true;
            }
        }
Exemplo n.º 8
0
        public bool[] ReadInputChannels()
        {
            bool[] digitalInputChannels;
            var    modbus = _adamSocket.Modbus();

            modbus.ReadCoilStatus(IdSartForInputChanel, TotalDigitalInputChannels, out digitalInputChannels);
            return(digitalInputChannels);
        }
Exemplo n.º 9
0
 public void BulbOn()
 {
     if (AdamTCP.Connect(IP, System.Net.Sockets.ProtocolType.Tcp, port))
     {
         AdamTCP.Modbus().ForceSingleCoil(IO, true);
     }
     else
     {
         Console.WriteLine("Error! cant connect to the adam");
         MessageBox.Show("Error! cant connect to the adam");
     }
 }
Exemplo n.º 10
0
        public void counterStart()
        {
            int iStart;             // base address
            int iConfigStart;       // index ulaznog kanala pa se po formuli dobije adresa

            iConfigStart = Counter.GetChannelStart(m_Adam6000Type);
            iStart       = 32 + (iConfigStart + 0) * 4 + 1; // + 0 za prvi kanal prakticno nema smisla al cisto da se vidi da se tu dodaje u zavisnosti od kanala
            if (!m_adamModbus.Modbus().ForceSingleCoil(iStart, cnt_enable))
            {
                Console.WriteLine("ForceSingleCoil() failed...");
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Refresh Channel Information "Value" column
        /// </summary>
        /// <returns></returns>
        private bool RefreshData()
        {
            int    iChannelTotal  = 0;
            string strSelPageName = tabControl1.TabPages[tabControl1.SelectedIndex].Text;

            if (strSelPageName == "DI")
            {
                bool[] bVal;
                iChannelTotal = this.m_aConf.HwIoTotal[m_DIidx];
                if (!m_adamSocket.DigitalInput().GetValues(m_idxID, iChannelTotal, out bVal))
                {
                    StatusBar_IO.Text += "ApiErr:" + m_adamSocket.Modbus().LastError.ToString() + " ";
                    return(false);
                }
                for (int i = 0; i < bVal.Length; i++)
                {
                    listViewChInfo_DI.Items[i].SubItems[3].Text = bVal[i].ToString();  //moduify "Value" column
                }
            }
            else if (strSelPageName == "DO")
            {
                bool[] bVal;
                iChannelTotal = this.m_aConf.HwIoTotal[m_DOidx];
                if (!m_adamSocket.DigitalOutput().GetValues(m_idxID, m_iDoOffset + iChannelTotal, out bVal))   //Should add offset for DIO modules
                {
                    StatusBar_IO.Text += "ApiErr:" + m_adamSocket.Modbus().LastError.ToString() + " ";
                    return(false);
                }
                for (int i = 0; i < bVal.Length - m_iDoOffset; i++)
                {
                    listViewChInfo_DO.Items[i].SubItems[3].Text = bVal[i + m_iDoOffset].ToString();  //moduify "Value" column
                }
            }
            return(true);
        }
Exemplo n.º 12
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]);
            }
        }
Exemplo n.º 13
0
        public void AdamOutputRead(AdamSocket adam6060)
        {


            int outindex = 17;
            bool[] outbuffer;
            try

            {
                Program.AdamOutputErrorRead = false;
                if (adam6060.Modbus().ReadCoilStatus(outindex, 6, out outbuffer))
                {

                    

                
                while i != 6 {
                if (outbuffer[i]){
                        Program.Adam = true;
                    else
                        Program.Adam = false;
                 }
                    else
                {
                    Program.AdamOutputErrorRead = true;
                }
                     i++;
                 }

                }
Exemplo n.º 14
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            int iIdx;

            int[]  iData;
            bool[] bData;


            if (m_bRegister) // Read registers (4X references)
            {
                // read register (4X) data from slave
                if (adamTCP.Modbus().ReadHoldingRegs(m_iStart, m_iLength, out iData))
                {
                    m_iCount++; // increment the reading counter
                    txtStatus.Text = "Read registers " + m_iCount.ToString() + " times...";
                    // update ListView
                    for (iIdx = 0; iIdx < m_iLength; iIdx++)
                    {
                        listViewModbusCur.Items[iIdx].SubItems[2].Text = iData[iIdx].ToString();        // show value in decimal
                        listViewModbusCur.Items[iIdx].SubItems[3].Text = iData[iIdx].ToString("X04");   // show value in hexdecimal
                    }
                }
                else
                {
                    txtStatus.Text = "Read registers failed!"; // show error message in "txtStatus"
                }
            }
            else
            {
                // read coil (0X) data from slave
                if (adamTCP.Modbus().ReadCoilStatus(m_iStart, m_iLength, out bData))
                {
                    m_iCount++; // increment the reading counter
                    txtStatus.Text = "Read coil " + m_iCount.ToString() + " times...";
                    // update ListView
                    for (iIdx = 0; iIdx < m_iLength; iIdx++)
                    {
                        listViewModbusCur.Items[iIdx].SubItems[2].Text = bData[iIdx].ToString();        // show value
                    }
                }
                else
                {
                    txtStatus.Text = "Read coil failed!"; // show error message in "txtStatus"
                }
            }
        }
Exemplo n.º 15
0
        public int[] ReadInputRegs()
        {
            const int start = 1;

            int[] iData;
            _adamSocket.Modbus().ReadInputRegs(start, _channelsTotal, out iData);
            return(iData);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Refresh Fail Safe Value Setting
        /// </summary>
        private void RefreshFSVSettingInfo()
        {
            int[]      o_iData;
            AdamSocket adamSocket = new AdamSocket(adamType);

            if (adamSocket.Connect(this.txtIPAddress.Text, protoType, portNum))
            {
                if (adamSocket.Modbus().ReadAdvantechRegs(60004, 2, out o_iData)) //60004 is to read platform (AXIS) FW version
                {
                    if (0x0a == (o_iData[0] >> 12))                               //check 'a' of 0xa105
                    {
                        if (0x105 > (o_iData[0] & 0x0FFF))
                        {
                            panelFSVSetting.Visible = false; //AXIS fw version under 105 not support set communication IO FSV, so invisible
                        }
                        else
                        {                                                                     //fw version greater than 0x105 (include 0x105)
                            if (adamSocket.Modbus().ReadAdvantechRegs(60301, 2, out o_iData)) //Communication IO FSV Setting
                            {
                                if (0x01 == o_iData[0])                                       //Communication IO FSV enable
                                {
                                    chbxEnCommFSV.Checked     = true;
                                    txtCommFSVtimeout.Enabled = true;
                                    txtCommFSVtimeout.Text    = o_iData[1].ToString(); //Communication IO FSV Timeout
                                }
                                else
                                {
                                    chbxEnCommFSV.Checked = false;
                                }
                            }
                        }
                    }
                }
                else
                {
                    panelFSVSetting.Visible = false;
                }
            }

            adamSocket.Disconnect();
            adamSocket = null;
        }
Exemplo n.º 17
0
        public void ChangeLightColor(int entryOrExitSide, bool greenLight)
        {
            int iOnOff;

            if (greenLight == true) // was ON, now set to OFF
            {
                iOnOff = 1;
            }
            else
            {
                iOnOff = 0;
            }
            try
            {
                adamModbus.Modbus().ForceSingleCoil(entryOrExitSide, iOnOff);
            }
            catch (Exception e)
            {
                Logger.Error("Błąd w zmianie koloru światła, kod błędu {0}", e.ToString());
            }
            Console.WriteLine("Zmieniam kolor światła {0} na {1}", EnterOrExitLight(entryOrExitSide), LightColor(iOnOff));
        }
Exemplo n.º 18
0
        private void RefreshDO()
        {
            int iStart = 17;

            bool[] bData = new bool[m_iDoTotal];

            if (m_iDoTotal == 0)
            {
            }
            else
            {
                if (adamModbus.Modbus().ReadCoilStatus(iStart, m_iDoTotal, out bData))
                {
                    if (m_iDoTotal > 0)
                    {
                        txtCh0.Text = bData[0].ToString();
                    }
                    if (m_iDoTotal > 1)
                    {
                        txtCh1.Text = bData[1].ToString();
                    }
                    if (m_iDoTotal > 2)
                    {
                        txtCh2.Text = bData[2].ToString();
                    }
                    if (m_iDoTotal > 3)
                    {
                        txtCh3.Text = bData[3].ToString();
                    }
                    if (m_iDoTotal > 4)
                    {
                        txtCh4.Text = bData[4].ToString();
                    }
                    if (m_iDoTotal > 5)
                    {
                        txtCh5.Text = bData[5].ToString();
                    }
                    if (m_iDoTotal > 6)
                    {
                        txtCh6.Text = bData[6].ToString();
                    }
                    if (m_iDoTotal > 7)
                    {
                        txtCh7.Text = bData[7].ToString();
                    }
                }
                else
                {
                    txtCh0.Text = "Fail";
                    txtCh1.Text = "Fail";
                    txtCh2.Text = "Fail";
                    txtCh3.Text = "Fail";
                    txtCh4.Text = "Fail";
                    txtCh5.Text = "Fail";
                    txtCh6.Text = "Fail";
                    txtCh7.Text = "Fail";
                }
            }
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
0
        /// <summary>
        /// If checkbox disable, it will disable all safety value
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chbxEnableSafety_CheckedChanged(object sender, EventArgs e)
        {
            btnSetSafetyValue.Enabled = chbxEnableSafety.Checked;
            if (!CheckControllable())
            {
                return;
            }

            if (!m_adamSocket.Configuration().OUT_SetSafetyEnable(m_idxID, chbxEnableSafety.Checked))
            {
                MessageBox.Show("Set safety function failed! (Err: " + m_adamSocket.Modbus().LastError.ToString() + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }

            RefreshSafetySetting();
        }
Exemplo n.º 22
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.º 23
0
 public bool[] ReadCoils(int _idx, int _len)
 {
     bData_in = new bool[_len]; bool[] t_Data_in;
     if (adamTCP.Modbus(Device.Port).ReadCoilStatus(_idx, _len, out t_Data_in) && m_connFlg)
     {
         bData_in = t_Data_in;
     }
     return(bData_in);
 }
Exemplo n.º 24
0
        /// <summary>
        /// Refresh Channel Information "Value" column
        /// </summary>
        /// <returns></returns>
        private bool RefreshData()
        {
            int iChannelTotal = 0;

            bool[] bVal;
            iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx];
            if (!m_adamSocket.DigitalInput().GetValues(m_idxID, iChannelTotal, out bVal))
            {
                StatusBar_IO.Text += "ApiErr:" + m_adamSocket.Modbus().LastError.ToString() + " ";
                return(false);
            }
            for (int i = 0; i < bVal.Length; i++)
            {
                listViewChInfo.Items[i].SubItems[3].Text = bVal[i].ToString();  //moduify "Value" column
            }
            return(true);
        }
Exemplo n.º 25
0
        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();
            }
        }
        public object ReadModule(string Variable)
        {
            object Value = "ReadError";

            if (string.IsNullOrEmpty(Variable))
            {
                MessageBox.Show("Wysłano do odczytu pustą zmienną! (Workbit, bity do odczytu, interpreter)", "Błąd odczytu!", MessageBoxButton.OK, MessageBoxImage.Error);
                return(0);
            }

            if (Pelecek != null)
            {
                Variable = Variable.ToUpper();
                Variable = Variable.Replace("Q", "A");
                Variable = Variable.Replace("I", "E");
                Value    = Pelecek.Read(Variable);
            }
            if (Adamek != null)
            {
                Variable = Variable.ToUpper();
                if (Variable.Contains("I") || Variable.Contains("E"))
                {
                    Variable = Variable.Remove(0, 1);
                    string[] invocation = Variable.Split(new char[] { '.' });

                    int    index;
                    bool[] data;
                    if (int.TryParse(invocation[0], out index) && Adamek.Modbus().ReadCoilStatus(index + 1, 1, out data))
                    {
                        Value = data[0];
                    }
                }
            }

            return(Value);
        }
Exemplo n.º 27
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";
                }
            }
        }