示例#1
0
        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));
            }
        }
示例#2
0
        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;
            }
        }
示例#3
0
        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");
        }
示例#4
0
        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");
        }
示例#5
0
        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");
        }
示例#6
0
        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");
        }