Exemplo n.º 1
0
 public PLC(CPU_Type cpu, string ip, Int16 rack, Int16 slot)
 {
     this.IP   = ip;
     this.CPU  = cpu;
     this.Rack = rack;
     this.Slot = slot;
 }
Exemplo n.º 2
0
 public PLC(CPU_Type cpu, string ip, Int16 rack, Int16 slot)
 {
     IP   = ip;
     CPU  = cpu;
     Rack = rack;
     Slot = slot;
 }
Exemplo n.º 3
0
 public PLC(CPU_Type cpu, string ip, Int16 rack, Int16 slot, string name, object tag)
 {
     IP   = ip;
     CPU  = cpu;
     Rack = rack;
     Slot = slot;
     Name = name;
     Tag  = tag;
 }
Exemplo n.º 4
0
        private void btnConnection_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtIPaddress.Text))
                {
                    throw new Exception("Xin vui lòng nhập địa chỉ IP");
                }
                int      selectionIndex = cboxPLCs.SelectedIndex;
                CPU_Type cpuType        = CPU_Type.S7200;
                string   ipAddress      = txtIPaddress.Text;
                switch (selectionIndex)
                {
                case 0:
                    cpuType = CPU_Type.S7200;
                    break;

                case 1:
                    cpuType = CPU_Type.S7300;
                    break;

                case 2:
                    cpuType = CPU_Type.S7400;
                    break;

                case 3:
                    cpuType = CPU_Type.S71200;
                    break;

                default:
                    cboxPLCs.SelectedIndex = 3;
                    cpuType = CPU_Type.S71200;
                    break;
                }
                plc = new PLC(cpuType, ipAddress, (short)numericUpDownRack.Value, (short)numericUpDownSlot.Value);
                if (!plc.IsAvailable)
                {
                    throw new Exception("Không tìm thấy PLC cần kết nối!");
                }
                errCode = plc.Open();
                if (errCode != ExceptionCode.ExceptionNo)
                {
                    throw new Exception(plc.lastErrorString);
                }
                this.SetEnabledBotton(false);

                //BackgroundWorker START
                worker = new BackgroundWorker();
                worker.WorkerSupportsCancellation = true;

                worker.DoWork += new DoWorkEventHandler(worker_DoWork);
                //worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);

                //worker.DoWork += (obj, ea) => worker_DoWork();
                worker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Notification", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }