コード例 #1
0
    /**************************************************
    * 画面の切り替え:MyConsole Canvas
    **************************************************/
    void ChangeToMyConsole()
    {
        CanvasDictionary[0].SetActive(false);
        CanvasDictionary[2].SetActive(true);
        CanvasState = 2;

        if (myconsole_Delete)
        {
            myconsole.Delete();
            myconsole_Delete = false;
        }
        foreach (object message in myconsole_Buffer)
        {
            myconsole.Add(message);
        }
        myconsole_Buffer = new List <object>();
    }
コード例 #2
0
        private void DataMonitor_Load(object sender, EventArgs e)
        {
            MyConsole.Add("数据监控启动", Color.Orange);
            this.FormClosing += DataMonitor_FormClosing;
            //创建菜单
            contextMenu      = new ContextMenuStrip();
            contextMenu.Font = new Font("新宋体", 14);
            contextMenu.Items.Add("更新描述");
            contextMenu.Items.Add("清除描述");
            //添加点击事件
            contextMenu.Items[0].Click += contextMenu_AddDes_Click;
            contextMenu.Items[1].Click += contextMenu_ClearDes_Click;

            //添加单元格点击事件
            doubleBufferListView1.MouseClick += DoubleBufferListView1_MouseClick;

            #region 数据列表
            datekey[0] = "日期";
            datekey[1] = "时间";
            datekey[2] = "寄存器类型";
            datekey[3] = "寄存器地址";
            datekey[4] = "值";
            datekey[5] = "更新次数";
            datekey[6] = "传输方向";
            datekey[7] = "描述";

            doubleBufferListView1.FullRowSelect = true;//要选择就是一行
            doubleBufferListView1.Columns.Add(datekey[0], 180, HorizontalAlignment.Center);
            doubleBufferListView1.Columns.Add(datekey[1], 220, HorizontalAlignment.Center);
            doubleBufferListView1.Columns.Add(datekey[2], 140, HorizontalAlignment.Center);
            doubleBufferListView1.Columns.Add(datekey[3], 140, HorizontalAlignment.Center);
            doubleBufferListView1.Columns.Add(datekey[4], 100, HorizontalAlignment.Left);
            doubleBufferListView1.Columns.Add(datekey[5], 100, HorizontalAlignment.Left);
            doubleBufferListView1.Columns.Add(datekey[6], 150, HorizontalAlignment.Left);
            doubleBufferListView1.Columns.Add(datekey[7], -2, HorizontalAlignment.Left);

            for (int i = 0; i < DataSync.Profinet.Register.Length; i++)
            {
                ListViewItem item = new ListViewItem();
                item.Text = DateTime.Now.ToString("yyyy-MM-dd");          //"日期";
                item.SubItems.Add(DateTime.Now.ToString("HH:mm:ss fff")); //  "时间";
                item.SubItems.Add("WORD");                                //  "寄存器类型";
                item.SubItems.Add("0");                                   //  "寄存器地址";
                item.SubItems.Add("0");                                   //  "值";
                item.SubItems.Add("0");                                   //  "更新次数";
                item.SubItems.Add("");                                    //  "传输方向";
                item.SubItems.Add("");                                    //  "描述";
                doubleBufferListView1.Items.Add(item);
                doubleBufferListView1.Items[i].ForeColor = Color.Gray;

                doubleBufferListView1.Items[i].BackColor = i % 2 == 0 ? Color.White : Color.FromArgb(0xf0, 0xf5, 0xf5, 0xf5);
            }
            #endregion


            mainThread = new ExThread(func);
            mainThread.Start();
        }
コード例 #3
0
        private static void mainThreadFunc()
        {
            while (true)
            {
                if (MainThread.exitEvent.WaitOne(1000))
                {
                    break;
                }

                #region 启动Dbus
                //启动监听进程
                if (SyncState.Dbus == false)
                {
                    dbusThread = new ExThread(Syncdbus);
                    dbusThread.Start();
                    MyConsole.Add("监听Dbus线程已启动!", Color.Green);
                    SyncState.Dbus = true;
                }
                #endregion

                #region 启动ModbusTcp
                if (SyncState.ModbusTcp == false)
                {
                    try
                    {
                        MyConsole.Add(string.Format("开始连接ModbusTcp客户端,IP地址:{0},Port:{1}", Profinet.ModbusTcpSeverIPAddress, Profinet.ModbusTcpSeverPort));
                        //连接超时1000ms
                        TcpClient tcpClient = new ExTcpClient(Profinet.ModbusTcpSeverIPAddress, Profinet.ModbusTcpSeverPort, 1000).Connect();
                        modbusMaster = ModbusIpMaster.CreateIp(tcpClient);
                        modbusMaster.Transport.WriteTimeout            = Profinet.Timeout;         //写超时
                        modbusMaster.Transport.ReadTimeout             = Profinet.Timeout;         //读超时
                        modbusMaster.Transport.WaitToRetryMilliseconds = Profinet.WaitToRetryTime; //重试等待时间
                        modbusMaster.Transport.Retries = Profinet.RetryNum;                        //重试次数

                        //启动监听进程
                        modbusThread = new ExThread(SyncModbus);
                        modbusThread.Start();
                        SyncState.ModbusTcp = true;
                        MyConsole.Add("监听ModbusTCP线程启动成功!", Color.Green);
                    }
                    catch
                    {
                        MyConsole.Add("监听ModbusTCP线程启动失败!", Color.Red);
                    }
                }
                #endregion
            }
        }
コード例 #4
0
        //开始同步
        public static void Start()
        {
            //加载modbus配置,有配置则更新为配置,没有则不更新
            ExTimeOut et = new ExTimeOut(2000);

            modbusConfig = et.Connect();

            if (modbusConfig != null)
            {
                //modbus 检测时间
                var data = modbusConfig.FirstOrDefault(m => m.key == "circle");
                if (data != null)
                {
                    Profinet.Cycle = int.Parse(data.value);
                }

                //modbus服务器IP地址
                data = modbusConfig.FirstOrDefault(m => m.key == "ip");
                if (data != null)
                {
                    Profinet.ModbusTcpSeverIPAddress = data.value;
                }

                //modbus服务器端口
                data = modbusConfig.FirstOrDefault(m => m.key == "port");
                if (data != null)
                {
                    Profinet.ModbusTcpSeverPort = int.Parse(data.value);
                }

                MyConsole.Add("数据库打开成功!", Color.Green);
            }
            else
            {
                MyConsole.Add("数据库打开失败!", Color.Red);
            }


            MainThread = new ExThread(mainThreadFunc);
            MainThread.thread.IsBackground = true;
            MainThread.Start();
        }