Exemplo n.º 1
0
        // ------------------------------------------------------------------------
        // Button read holding register
        // ------------------------------------------------------------------------
        private void btnReadHoldReg_Click(object sender, System.EventArgs e)
        {
            int  ID           = 3;
            int  StartAddress = ReadStartAdr();
            byte Length       = Convert.ToByte(txtSize.Text);

            MBmaster.ReadHoldingRegister(ID, StartAddress, Length);
        }
Exemplo n.º 2
0
        // ------------------------------------------------------------------------
        // Button read holding register
        // ------------------------------------------------------------------------
        private void btnReadHoldReg_Click(object sender, System.EventArgs e)
        {
            ushort ID           = 3;
            ushort StartAddress = ReadStartAdr();
            ushort Length       = Convert.ToUInt16(txtSize.Text);

            MBmaster.ReadHoldingRegister(ID, StartAddress, Length);
        }
Exemplo n.º 3
0
        public void ReadFromPCS()
        {
            ushort ID           = 4;
            byte   unit         = Convert.ToByte(1);
            ushort StartAddress = ReadStartAdr(30);
            byte   Length       = Convert.ToByte(52);

            master.ReadHoldingRegister(ID, unit, StartAddress, Length);
        }
Exemplo n.º 4
0
 // ------------------------------------------------------------------------
 // Read word value
 internal int SyncReadWord(ushort id, ushort adr)
 {
     byte[] values = null;
     if (_connected)
     {
         MBmaster.ReadHoldingRegister(id, 0, adr, 1, ref values);
     }
     if (values == null)
     {
         return(0xFFFF);
     }
     else if (values.Length == 2)
     {
         return(Byte2Word(values[0], values[1]));
     }
     else
     {
         return(-1);
     }
 }
Exemplo n.º 5
0
        private void TimerPolling_Tick(object sender, EventArgs e)
        {
            ushort size         = Convert.ToUInt16(txtSize.Text);
            ushort startAddress = Convert.ToUInt16(txtStartAdress.Text);

            try
            {
                //COILS
                MBmaster.ReadCoils(1, 0, startAddress, size, ref data);

                lstCoils.BeginUpdate();

                lstCoils.Items.Clear();
                BitArray bitArray = new BitArray(data);
                bool[]   bits     = new bool[bitArray.Count];
                bitArray.CopyTo(bits, 0);

                for (int x = 0; x < size; x++)
                {
                    lstCoils.Items.Add((x + 1 + startAddress) + "\t - " + bits[x].ToString());
                }

                lstCoils.EndUpdate();

                //HOLDING

                MBmaster.ReadHoldingRegister(2, 0, startAddress, size, ref data);

                listHoldingRegisters.BeginUpdate();

                listHoldingRegisters.Items.Clear();
                int i = 1;
                for (int x = 0; x < data.Length - 1; x += 2)
                {
                    listHoldingRegisters.Items.Add((i + startAddress) + "\t - " + (data[x] * 256 + data[x + 1]).ToString());
                    i++;
                }


                listHoldingRegisters.EndUpdate();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TimerPolling.Stop();
            }
        }
Exemplo n.º 6
0
        //===============================================================
        #region THREAD de lecture de la sation RFID tout les 500ms
        private void ReadRFID()
        {
            while (true)
            {
                while (etat_Connection_RFID)
                {
                    ushort ID = ushort.Parse("3");

                    //byte unit = Convert.ToByte(Properties.Settings.Default.Unit);
                    //ushort StartAddress = ushort.Parse(Properties.Settings.Default.startAddress);
                    //byte Length = Convert.ToByte(Properties.Settings.Default.Size);

                    byte   unit         = Convert.ToByte(1);
                    ushort StartAddress = 0;
                    byte   Length       = Convert.ToByte(32);


                    MBmaster.ReadHoldingRegister(ID, unit, StartAddress, Length);
                    Task.Delay(500).Wait();
                }
            }
        }
Exemplo n.º 7
0
        private void timerPolling_Tick(object sender, EventArgs e)
        {
            try
            {
                ushort size         = Convert.ToUInt16(ucTextBoxEx_Size.InputText);
                ushort startAddress = Convert.ToUInt16(ucTextBoxEx_StartAddress.InputText);
                //DISCRETE INPUTS
                MBmaster.ReadDiscreteInputs(1, 0, startAddress, size, ref newdataInputs);

                if (dataInputs.SequenceEqual <byte>(newdataInputs) == false || addressChanged)
                {
                    listBox_DiscreteInputs.BeginUpdate();
                    listBox_DiscreteInputs.Items.Clear();
                    BitArray bitArray = new BitArray(newdataInputs);
                    bool[]   bits     = new bool[bitArray.Count];
                    bitArray.CopyTo(bits, 0);

                    for (int x = 0; x < size; x++)
                    {
                        listBox_DiscreteInputs.Items.Add((x + 1 + startAddress) + "\t - " + bits[x].ToString());
                    }
                    listBox_DiscreteInputs.EndUpdate();
                    dataInputs = newdataInputs;
                }

                //COILS
                MBmaster.ReadCoils(2, 0, startAddress, size, ref newdataCoils);

                if (dataCoils.SequenceEqual <byte>(newdataCoils) == false || addressChanged)
                {
                    listBox_Coils.BeginUpdate();
                    listBox_Coils.Items.Clear();
                    BitArray bitArray = new BitArray(newdataCoils);
                    bool[]   bits     = new bool[bitArray.Count];
                    bitArray.CopyTo(bits, 0);

                    for (int x = 0; x < size; x++)
                    {
                        listBox_Coils.Items.Add((x + 1 + startAddress) + "\t - " + bits[x].ToString());
                    }
                    listBox_Coils.EndUpdate();
                    dataCoils = newdataCoils;
                }

                //INPUT REGISTERS
                MBmaster.ReadInputRegister(3, 0, startAddress, size, ref newdataInputRegisters);
                if (dataInputRegisters.SequenceEqual <byte>(newdataInputRegisters) == false || addressChanged)
                {
                    listBox_InputRegisters.BeginUpdate();
                    listBox_InputRegisters.Items.Clear();
                    int i = 1;
                    for (int x = 0; x < newdataInputRegisters.Length - 1; x += 2)
                    {
                        listBox_InputRegisters.Items.Add((i + startAddress) + "\t - " + (newdataInputRegisters[x] * 256 +
                                                                                         newdataInputRegisters[x + 1]).ToString());
                        i++;
                    }
                    listBox_InputRegisters.EndUpdate();
                    dataInputRegisters = newdataInputRegisters;
                }

                //HOLDING REGISTERS
                MBmaster.ReadHoldingRegister(4, 0, startAddress, size, ref newdataHoldingRegisters);
                if (dataHoldingRegisters.SequenceEqual <byte>(newdataHoldingRegisters) == false || addressChanged)
                {
                    listBox_HoldingRegisters.BeginUpdate();
                    listBox_HoldingRegisters.Items.Clear();
                    int i = 1;
                    for (int x = 0; x < newdataHoldingRegisters.Length - 1; x += 2)
                    {
                        listBox_HoldingRegisters.Items.Add((i + startAddress) + "\t - " + (newdataHoldingRegisters[x] * 256 +
                                                                                           newdataHoldingRegisters[x + 1]).ToString());
                        i++;
                    }
                    listBox_HoldingRegisters.EndUpdate();
                    dataHoldingRegisters = newdataHoldingRegisters;
                }
                addressChanged = false;

                MBmaster.ReadHoldingRegister(4, 0, startAddress, size, ref newdataHoldingRegisters);
                if (dataHoldingRegisters.SequenceEqual <byte>(newdataHoldingRegisters) == false || addressChanged)
                {
                    listBox_HoldingRegisters.BeginUpdate();
                    listBox_HoldingRegisters.Items.Clear();
                    int i = 1;
                    for (int x = 0; x < newdataHoldingRegisters.Length - 1; x += 2)
                    {
                        listBox_HoldingRegisters.Items.Add((i + startAddress) + "\t - " + (newdataHoldingRegisters[x] * 256 +
                                                                                           newdataHoldingRegisters[x + 1]).ToString());
                        i++;
                    }
                    listBox_HoldingRegisters.EndUpdate();
                    dataHoldingRegisters = newdataHoldingRegisters;
                }
                addressChanged = false;
            }
            catch (Exception ex)
            {
                timerPolling.Stop();
                DarkMessageBox.ShowWarning(ex.Message.ToString() + "\nDesconectando Sesión", "Warning!");
                //darkButton_Disconnect.PerformClick();
                newdataCoils               = new byte[0];
                newdataInputs              = new byte[0];
                newdataInputRegisters      = new byte[0];
                newdataHoldingRegisters    = new byte[0];
                addressChanged             = false;
                ucTextBoxEx_Size.InputText = "1";
                timerPolling.Start();
            }
        }
Exemplo n.º 8
0
 private void ReadReg(object o)
 {
     MBmaster.ReadHoldingRegister(3, 0, 0, 2);
 }