Пример #1
0
        public string GetFlatPCLHtml(int flatid)
        {
            string         html     = "";
            PLCService     ps       = new PLCService();
            FlatPLCService fservice = new FlatPLCService();
            var            model    = ps.GetAllPLC();

            html += "<div id='panelPLC'>";
            foreach (var pm in model)
            {
                bool bl = fservice.IsPLCinFlat(pm.PLCID, flatid);
                if (bl == true)
                {
                    string id = pm.PLCID.ToString();
                    html += @"<label class='checkbox'><input type='checkbox' value='" + pm.PLCID + "' name='" + pm.PLCName + "' id='" + id + "' checked='checked'><i></i> " + pm.PLCName + "</label>";
                }
                else
                {
                    string id = pm.PLCID.ToString();
                    html += @"<label class='checkbox'><input type='checkbox' value='" + pm.PLCID + "' name='" + pm.PLCName + "' id='" + id + "'><i></i> " + pm.PLCName + "</label>";
                }
            }
            html += "</div></div>";
            return(html);
        }
Пример #2
0
        public void TestInvalidCommand()
        {
            PLCService service = new PLCService();
            {
                PLCRequest request = new PLCRequest {
                };
                var e = Assert.Throws <PLCService.PLCInvalidCommandException>(() =>
                {
                    service.Handle(request);
                });
                Assert.Equal(e.Code, "invalid_command");
            }

            {
                PLCRequest request = new PLCRequest {
                    Command = ""
                };
                var e = Assert.Throws <PLCService.PLCInvalidCommandException>(() =>
                {
                    service.Handle(request);
                });
                Assert.Equal(e.Code, "invalid_command");
            }

            {
                PLCRequest request = new PLCRequest {
                    Command = "unknown"
                };
                var e = Assert.Throws <PLCService.PLCInvalidCommandException>(() =>
                {
                    service.Handle(request);
                });
                Assert.Equal(e.Code, "invalid_command");
            }
        }
 //PLCService rullatriceVechePlc = new PLCService(CpuType.S7300, "172.16.4.167", 0, 2, "Rullatrice Project Man",
 //    "A2.0", "A2.1", "A2.2", "A2.3", "A2.4", "A2.5", "A2.6");
 public PLCViewModel(PLCService plc)
 {
     _plc = plc;
     _plc.Connect();
     _plc.RefreshValues();
     tempOprire1      = false;
     timpStartProgram = DateTime.Now;
 }
Пример #4
0
 public void TestPing()
 {
     PLCService service = new PLCService();
     {
         PLCRequest request = new PLCRequest {
             Command = PLCRequest.CommandPing
         };
         PLCResponse response = service.Handle(request);
         Assert.Null(response.Error);
     }
 }
Пример #5
0
        public string GetPCLHtml()
        {
            string     html  = "";
            PLCService ps    = new PLCService();
            var        model = ps.GetAllPLC();

            html += "<div id='panelPLC'>";
            foreach (var pm in model)
            {
                string id = pm.PLCID.ToString();
                html += @"<label class='checkbox'><input type='checkbox' value='" + pm.PLCID + "' name='" + pm.PLCName + "' id='" + id + "'><i></i> " + pm.PLCName + "</label>";
            }
            html += "</div></div>";
            return(html);
        }
Пример #6
0
        public void TestReadWriteBulk()
        {
            PLCService service = new PLCService();
            {
                PLCRequest request = new PLCRequest {
                    Command = PLCRequest.CommandRead
                };
                PLCResponse response = service.Handle(request);
                Assert.Null(response.Error);
                Assert.Null(response.Values);
            }

            {
                PLCRequest request = new PLCRequest {
                    Command = PLCRequest.CommandRead, Keys = new string[] { "test1", "test2", "test3" }
                };
                PLCResponse response = service.Handle(request);
                Assert.Null(response.Error);
                Assert.NotNull(response.Values);
                Assert.Equal(response.Values.Count, 0);
            }

            {
                Dictionary <string, object> values = new Dictionary <string, object>();
                values["test1"] = "hello";
                values["test3"] = true;
                PLCRequest request = new PLCRequest {
                    Command = PLCRequest.CommandWrite, Values = values
                };
                PLCResponse response = service.Handle(request);
                Assert.Null(response.Error);
            }

            {
                PLCRequest request = new PLCRequest {
                    Command = PLCRequest.CommandRead, Keys = new string[] { "test1", "test2", "test3" }
                };
                PLCResponse response = service.Handle(request);
                Assert.Null(response.Error);
                Assert.NotNull(response.Values);
                Assert.Equal(response.Values.Count, 2);
                Assert.Equal(response.Values["test1"], "hello");
                Assert.Equal(response.Values["test3"], true);
            }
        }
        public Frm_Control(string OperationString, bool value, string varName, PLCService p) : this()
        {
            this.objPLCService = p;

            this.operationString = OperationString;
            this.value           = value;
            this.varName         = varName;

            this.lbl_Operation.Text = "是否" + this.operationString + "?";
            //通过变量名寻址变量地址
            foreach (Variable_Modbus item in PLCService.listVar)
            {
                if (item.VarName == this.varName)
                {
                    this.address = item.Address;
                }
            }
        }
Пример #8
0
        public void TestReadWrite()
        {
            PLCService service = new PLCService();
            {
                PLCRequest request = new PLCRequest {
                    Command = PLCRequest.CommandRead
                };
                PLCResponse response = service.Handle(request);
                Assert.Null(response.Error);
                Assert.Null(response.Values);
            }

            {
                PLCRequest request = new PLCRequest {
                    Command = PLCRequest.CommandRead, Keys = new string[] { "test" }
                };
                PLCResponse response = service.Handle(request);
                Assert.Null(response.Error);
                Assert.NotNull(response.Values);
                Assert.Equal(response.Values.Count, 0);
            }

            {
                Dictionary <string, object> values = new Dictionary <string, object>();
                values["test"] = 3.1415926535;
                PLCRequest request = new PLCRequest {
                    Command = PLCRequest.CommandWrite, Values = values
                };
                PLCResponse response = service.Handle(request);
                Assert.Null(response.Error);
            }

            {
                PLCRequest request = new PLCRequest {
                    Command = PLCRequest.CommandRead, Keys = new string[] { "test" }
                };
                PLCResponse response = service.Handle(request);
                Assert.Null(response.Error);
                Assert.NotNull(response.Values);
                Assert.Equal(response.Values.Count, 1);
                Assert.Equal(response.Values["test"], 3.1415926535);
            }
        }
Пример #9
0
        public string FlatHmtl(string TotalFlat)
        {
            string FltHtml   = "";
            int    flatcount = Convert.ToInt32(TotalFlat);

            for (int i = 1; i <= flatcount; i++)
            {
                string     html  = fservice.FlatCreateBody();
                PLCService ps    = new PLCService();
                var        model = ps.GetAllPLC();
                html += "<div id='panel" + i.ToString() + "'>";
                foreach (var pm in model)
                {
                    string id = pm.PLCID.ToString() + " " + i.ToString();
                    html += @"<label class='checkbox'><input type='checkbox' value='" + pm.PLCID + "' name='" + pm.PLCName + "' id='" + id + "'><i></i> " + pm.PLCName + "</label>";
                }
                html    += "</div></div>";
                FltHtml += html.Replace("<% FlatNo %>", "FlatNo" + i).Replace("<% PreIncrement %>", "PreIncrement" + i);
            }
            return(FltHtml);
        }
Пример #10
0
 public FrmView(PLCService p)
     : this()
 {
     this.objPLCService = p;
 }