Ejemplo n.º 1
0
        private void btnReadCoils_Click(object sender, EventArgs e)
        {
            txtData.Text    = "";
            mbmUdp.Hostname = txtHost.Text;
            bool[] readData;
            ushort readAddr       = Convert.ToUInt16(txtReadCoilAddress.Text);
            wmnRet _wmnReceiveRet = mbmUdp.ReadCoils(0, readAddr, 32, out readData);

            if (_wmnReceiveRet.Value == 0)
            {
                for (int i = 0; i < readData.Length; i++)
                {
                    txtData.Text += "Address[" + (i).ToString() + "] Value: " + readData[i].ToString() + "; \r\n";
                }
            }
            else
            {
                txtData.Text = _wmnReceiveRet.Text;
            }
        }
Ejemplo n.º 2
0
        // The ThreadProc method is called when the thread starts.
        // It loops ten times, writing to the console and yielding
        // the rest of its time slice each time, and then ends.
        public void ThreadProc(object obj)
        {
            ModbusMasterUdp mbmUdpt = new ModbusMasterUdp();

            mbmUdpt.AutoConnect = true;
            mbmUdpt.Port        = 502;
            mbmUdpt.Hostname    = (string)obj;

            bool[] readData;
            wmnRet _wmnReceiveRet = mbmUdpt.ReadCoils(0, 0x3000, 2, out readData);

            if (_wmnReceiveRet.Value == 0)
            {
                for (int i = 0; i < readData.Length; i++)
                {
                    Console.WriteLine(mbmUdpt.Hostname + ":" + mbmUdpt.Port.ToString() + " Address[" + (0x3000 + i).ToString() + "] Value: " + readData[i].ToString() + ";");
                }
            }
            else
            {
                Console.WriteLine(_wmnReceiveRet.Text);
            }
        }
Ejemplo n.º 3
0
        private void btnReadBool_Click(object sender, EventArgs e)
        {
            txtData.Text    = "";
            mbmUdp.Hostname = txtHost.Text;
            bool[] readData;
            wmnRet _wmnReceiveRet = mbmUdp.ReadCoils(0, 0x3000, 2, out readData);

            if (_wmnReceiveRet.Value == 0)
            {
                for (int i = 0; i < readData.Length; i++)
                {
                    txtData.Text += "Address[" + (0x3000 + i).ToString() + "] Value: " + readData[i].ToString() + "; \r\n";
                }
            }
            else
            {
                txtData.Text = _wmnReceiveRet.Text;
            }
            Thread t1 = new Thread(new ParameterizedThreadStart(ThreadProc));
            Thread t2 = new Thread(new ParameterizedThreadStart(ThreadProc));

            t1.Start(txtHost.Text);
            t2.Start("192.168.1.1");
        }