public static void Init() { BarcodeClient.ReceiveDataChanged += UpdateReceiveData; Buffer.Init(); Timer.Enabled = false; Timer.Interval = 10; Timer.Elapsed += TimerElapsed; using (var sw = System.IO.File.CreateText(File)) { sw.WriteLine("// read times //"); } // AllocConsole(); Items.Add(DataItem.FromAddress("DB57.DBW32")); Items.Add(DataItem.FromAddress("DB57.DBW78")); Items.Add(DataItem.FromAddress("DB57.DBW24")); Items.Add(DataItem.FromAddress("DB57.DBW26")); Items.Add(DataItem.FromAddress("DB57.DBW28")); for (var i = 0; i < 5; i++) { var address = 86 + i * 2; Items.Add(DataItem.FromAddress("DB57.DBW" + address)); } Items.Add(DataItem.FromAddress("DB57.DBW100")); for (var i = 0; i < 3; i++) { var address = 38 + i * 2; Items.Add(DataItem.FromAddress("DB57.DBW" + address)); } }
private void btn_read_Click(object sender, EventArgs e) { try { if (_plc == null) { lbMsg.Text = "请先连接"; return; } if (string.IsNullOrEmpty(cb_addr.Text)) { lbMsg.Text = "请输入地址"; return; } lbMsg.Text = "读取中"; List <DataItem> dataItems = new List <DataItem>(); var item = DataItem.FromAddress(cb_addr.Text); dataItems.Add(item); _plc.Open(); _plc.ReadMultipleVars(dataItems); _plc.Close(); var result = dataItems.First().Value.ToString(); lbMsg.Text = result; } catch (PlcException ex) { lbMsg.Text = ex.Message; } }
public void T08_ParseID200() { DataItem dataItem = DataItem.FromAddress("ID200"); Assert.AreEqual(DataType.Input, dataItem.DataType, "Wrong datatype for ID200"); Assert.AreEqual(0, dataItem.DB, "Wrong dbnumber for ID200"); Assert.AreEqual(VarType.DWord, dataItem.VarType, "Wrong vartype for ID200"); Assert.AreEqual(200, dataItem.StartByteAdr, "Wrong startbyte for ID200"); Assert.AreEqual(0, dataItem.BitAdr, "Wrong bit for ID200"); }
public void T05_ParseI2000_1() { DataItem dataItem = DataItem.FromAddress("I2000.1"); Assert.AreEqual(DataType.Input, dataItem.DataType, "Wrong datatype for I2000.1"); Assert.AreEqual(0, dataItem.DB, "Wrong dbnumber for I2000.1"); Assert.AreEqual(VarType.Bit, dataItem.VarType, "Wrong vartype for I2000.1"); Assert.AreEqual(2000, dataItem.StartByteAdr, "Wrong startbyte for I2000.1"); Assert.AreEqual(1, dataItem.BitAdr, "Wrong bit for I2000.1"); }
public void T03_ParseMW200() { DataItem dataItem = DataItem.FromAddress("MW200"); Assert.AreEqual(DataType.Memory, dataItem.DataType, "Wrong datatype for MW200"); Assert.AreEqual(0, dataItem.DB, "Wrong dbnumber for MW200"); Assert.AreEqual(VarType.Word, dataItem.VarType, "Wrong vartype for MW200"); Assert.AreEqual(200, dataItem.StartByteAdr, "Wrong startbyte for MW200"); Assert.AreEqual(0, dataItem.BitAdr, "Wrong bit for MW200"); }
public void T10_ParseQB200() { DataItem dataItem = DataItem.FromAddress("QB200"); Assert.AreEqual(DataType.Output, dataItem.DataType, "Wrong datatype for QB200"); Assert.AreEqual(0, dataItem.DB, "Wrong dbnumber for QB200"); Assert.AreEqual(VarType.Byte, dataItem.VarType, "Wrong vartype for QB200"); Assert.AreEqual(200, dataItem.StartByteAdr, "Wrong startbyte for QB200"); Assert.AreEqual(0, dataItem.BitAdr, "Wrong bit for QB200"); }