Ejemplo n.º 1
0
        private LibnodavePLC Connect(string addr)
        {
            LibnodavePLC _LIBnodavePLC = new LibnodavePLC();
            bool         isopen        = _LIBnodavePLC.Init(Txt_IP.Text);

            _LIBnodavePLC.Device = _LIBnodavePLC.GetDeviceAddress(addr);
            return(_LIBnodavePLC);
        }
Ejemplo n.º 2
0
        private void LibCreate()
        {
            _LibnodavePLC = new LibnodavePLC();
            bool isopen = _LibnodavePLC.Init(Txt_IP.Text);

            if (isopen)
            {
                this.SetText("连接成功");
                label10.BackColor = Color.Green;
            }
            else
            {
                this.SetText("断开连接");
                label10.BackColor = Color.Red;
            }
        }
Ejemplo n.º 3
0
        private void LibInit()
        {
            try
            {
                ThreadState4  = true;
                logNet2       = new LogNetSingle("StrDataLog.txt");
                _LibnodavePLC = new LibnodavePLC();
                bool   isopen      = _LibnodavePLC.Init("DB1.0", Txt_IP.Text);;
                byte[] ReciveData  = new byte[1000];
                string sendmessage = "";
                Task.Run(() =>
                {
                    while (true)
                    {
                        this.Invoke(new Action(() =>
                        {
                            lock (this)
                            {
                                sendmessage = Txt_Send.Text = GetRandomString(400);
                            }
                        }
                                               )
                                    );

                        _LibnodavePLC.WriteBytes(SoftBasic.HexStringToBytes(Txt_Send.Text));
                        logNet2.RecordMessage(HslMessageDegree.DEBUG, "写入", sendmessage);
                        ReciveData = _LibnodavePLC.ReadBytes(200);
                        this.Invoke(new Action(() =>
                        {
                            lock (this)
                                Txt_Recieve.Text = SoftBasic.ByteToHexString(ReciveData);
                            logNet2.RecordMessage(HslMessageDegree.DEBUG, "读取", Txt_Recieve.Text);
                            logNet2.RecordMessage(HslMessageDegree.DEBUG, null, "是否正常" + Check(Txt_Recieve.Text, Txt_Send.Text));
                        }));
                    }
                }
                         );
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }