Browse Source

添加设备指令发送

章政 7 years ago
parent
commit
2cb9208e67

+ 25 - 10
UAS_DeviceMonitor/Entity/Polling.cs

@@ -8,7 +8,7 @@ namespace UAS_DeviceMonitor.Entity
 {
 {
     class Polling
     class Polling
     {
     {
-        private string code;
+        private string sendRadix;
 
 
         private string deviceCode;
         private string deviceCode;
 
 
@@ -24,6 +24,8 @@ namespace UAS_DeviceMonitor.Entity
 
 
         private DataHelper dh;
         private DataHelper dh;
 
 
+        private string commandCode;
+
         public string DeviceCode
         public string DeviceCode
         {
         {
             get
             get
@@ -89,42 +91,55 @@ namespace UAS_DeviceMonitor.Entity
             }
             }
         }
         }
 
 
-        public string Code
+        public int Id
         {
         {
             get
             get
             {
             {
-                return code;
+                return id;
             }
             }
 
 
             set
             set
             {
             {
-                code = value;
+                id = value;
             }
             }
         }
         }
 
 
-        public int Id
+        public DataHelper Dh
         {
         {
             get
             get
             {
             {
-                return id;
+                return dh;
             }
             }
 
 
             set
             set
             {
             {
-                id = value;
+                dh = value;
             }
             }
         }
         }
 
 
-        public DataHelper Dh
+        public string SendRadix
         {
         {
             get
             get
             {
             {
-                return dh;
+                return sendRadix;
             }
             }
 
 
             set
             set
             {
             {
-                dh = value;
+                sendRadix = value;
+            }
+        }
+
+        public string CommandCode
+        {
+            get
+            {
+                return commandCode;
+            }
+
+            set
+            {
+                commandCode = value;
             }
             }
         }
         }
     }
     }

+ 47 - 45
UAS_DeviceMonitor/Main.Designer.cs

@@ -65,7 +65,7 @@ namespace UAS_DeviceMonitor
             this.ButtonDeleteCommand = new UAS_DeviceMonitor.CustomerControl.Button.ButtonDeleteRow();
             this.ButtonDeleteCommand = new UAS_DeviceMonitor.CustomerControl.Button.ButtonDeleteRow();
             this.Brand_label = new DevExpress.XtraEditors.LabelControl();
             this.Brand_label = new DevExpress.XtraEditors.LabelControl();
             this.Brand = new DevExpress.XtraEditors.ComboBoxEdit();
             this.Brand = new DevExpress.XtraEditors.ComboBoxEdit();
-            this.ButtonNewCommand = new CustomerControl.Button.ButtonAddRow();
+            this.ButtonNewCommand = new UAS_DeviceMonitor.CustomerControl.Button.ButtonAddRow();
             this.ButtonSaveCommand = new UAS_DeviceMonitor.CustomerControl.Button.ButtonSaveGrid();
             this.ButtonSaveCommand = new UAS_DeviceMonitor.CustomerControl.Button.ButtonSaveGrid();
             this.GridCommandSetting = new UAS_DeviceMonitor.CustomerControl.AutoDataGridControl.AutoDataGridControl();
             this.GridCommandSetting = new UAS_DeviceMonitor.CustomerControl.AutoDataGridControl.AutoDataGridControl();
             this.GridViewCommandSet = new UAS_DeviceMonitor.CustomerControl.GridViewWithSerialNum.GridViewWithSerialNum();
             this.GridViewCommandSet = new UAS_DeviceMonitor.CustomerControl.GridViewWithSerialNum.GridViewWithSerialNum();
@@ -75,6 +75,9 @@ namespace UAS_DeviceMonitor
             this.dc_code = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dc_code = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dc_name = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dc_name = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dc_value = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dc_value = new DevExpress.XtraGrid.Columns.GridColumn();
+            this.dc_sendcoding = new DevExpress.XtraGrid.Columns.GridColumn();
+            this.CommandSetRepositoryItemComboBox1 = new DevExpress.XtraEditors.Repository.RepositoryItemComboBox();
+            this.dc_receivecoding = new DevExpress.XtraGrid.Columns.GridColumn();
             this.PageDeviceNetSetting = new DevExpress.XtraTab.XtraTabPage();
             this.PageDeviceNetSetting = new DevExpress.XtraTab.XtraTabPage();
             this.ButtonDeleteNetConfig = new UAS_DeviceMonitor.CustomerControl.Button.ButtonDeleteRow();
             this.ButtonDeleteNetConfig = new UAS_DeviceMonitor.CustomerControl.Button.ButtonDeleteRow();
             this.ButtonAddNetConfig = new UAS_DeviceMonitor.CustomerControl.Button.ButtonAddRow();
             this.ButtonAddNetConfig = new UAS_DeviceMonitor.CustomerControl.Button.ButtonAddRow();
@@ -129,8 +132,6 @@ namespace UAS_DeviceMonitor
             this.pl_dccode = new DevExpress.XtraGrid.Columns.GridColumn();
             this.pl_dccode = new DevExpress.XtraGrid.Columns.GridColumn();
             this.pl_remark = new DevExpress.XtraGrid.Columns.GridColumn();
             this.pl_remark = new DevExpress.XtraGrid.Columns.GridColumn();
             this.PageDeviceStatus = new DevExpress.XtraTab.XtraTabPage();
             this.PageDeviceStatus = new DevExpress.XtraTab.XtraTabPage();
-            this.GridDeviceStatus = new UAS_DeviceMonitor.CustomerControl.AutoDataGridControl.AutoDataGridControl();
-            this.GridViewDeviceStatus = new UAS_DeviceMonitor.CustomerControl.GridViewWithSerialNum.GridViewWithSerialNum();
             this.PageWorkCenterStatus = new DevExpress.XtraTab.XtraTabPage();
             this.PageWorkCenterStatus = new DevExpress.XtraTab.XtraTabPage();
             this.GridWorkCenterStatus = new UAS_DeviceMonitor.CustomerControl.AutoDataGridControl.AutoDataGridControl();
             this.GridWorkCenterStatus = new UAS_DeviceMonitor.CustomerControl.AutoDataGridControl.AutoDataGridControl();
             this.GridViewWorkCenterStatus = new UAS_DeviceMonitor.CustomerControl.GridViewWithSerialNum.GridViewWithSerialNum();
             this.GridViewWorkCenterStatus = new UAS_DeviceMonitor.CustomerControl.GridViewWithSerialNum.GridViewWithSerialNum();
@@ -145,6 +146,7 @@ namespace UAS_DeviceMonitor
             ((System.ComponentModel.ISupportInitialize)(this.GridCommandSetting)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridCommandSetting)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewCommandSet)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewCommandSet)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.CheckEditCommandSet)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.CheckEditCommandSet)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.CommandSetRepositoryItemComboBox1)).BeginInit();
             this.PageDeviceNetSetting.SuspendLayout();
             this.PageDeviceNetSetting.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.GridDeviceNetSetting)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridDeviceNetSetting)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewDeviceNetSetting)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewDeviceNetSetting)).BeginInit();
@@ -158,9 +160,6 @@ namespace UAS_DeviceMonitor
             this.PagePolling.SuspendLayout();
             this.PagePolling.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.GridPolling)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridPolling)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewPolling)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewPolling)).BeginInit();
-            this.PageDeviceStatus.SuspendLayout();
-            ((System.ComponentModel.ISupportInitialize)(this.GridDeviceStatus)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.GridViewDeviceStatus)).BeginInit();
             this.PageWorkCenterStatus.SuspendLayout();
             this.PageWorkCenterStatus.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.GridWorkCenterStatus)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridWorkCenterStatus)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewWorkCenterStatus)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewWorkCenterStatus)).BeginInit();
@@ -491,6 +490,7 @@ namespace UAS_DeviceMonitor
             // ButtonNewCommand
             // ButtonNewCommand
             // 
             // 
             this.ButtonNewCommand.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
             this.ButtonNewCommand.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+            this.ButtonNewCommand.Grid = null;
             this.ButtonNewCommand.Location = new System.Drawing.Point(886, 551);
             this.ButtonNewCommand.Location = new System.Drawing.Point(886, 551);
             this.ButtonNewCommand.Name = "ButtonNewCommand";
             this.ButtonNewCommand.Name = "ButtonNewCommand";
             this.ButtonNewCommand.Size = new System.Drawing.Size(64, 23);
             this.ButtonNewCommand.Size = new System.Drawing.Size(64, 23);
@@ -523,7 +523,8 @@ namespace UAS_DeviceMonitor
             this.GridCommandSetting.MenuManager = this.RibbonNav;
             this.GridCommandSetting.MenuManager = this.RibbonNav;
             this.GridCommandSetting.Name = "GridCommandSetting";
             this.GridCommandSetting.Name = "GridCommandSetting";
             this.GridCommandSetting.RepositoryItems.AddRange(new DevExpress.XtraEditors.Repository.RepositoryItem[] {
             this.GridCommandSetting.RepositoryItems.AddRange(new DevExpress.XtraEditors.Repository.RepositoryItem[] {
-            this.CheckEditCommandSet});
+            this.CheckEditCommandSet,
+            this.CommandSetRepositoryItemComboBox1});
             this.GridCommandSetting.RowCount = 0;
             this.GridCommandSetting.RowCount = 0;
             this.GridCommandSetting.Size = new System.Drawing.Size(1027, 517);
             this.GridCommandSetting.Size = new System.Drawing.Size(1027, 517);
             this.GridCommandSetting.TabIndex = 1;
             this.GridCommandSetting.TabIndex = 1;
@@ -538,7 +539,9 @@ namespace UAS_DeviceMonitor
             this.dc_id,
             this.dc_id,
             this.dc_code,
             this.dc_code,
             this.dc_name,
             this.dc_name,
-            this.dc_value});
+            this.dc_value,
+            this.dc_sendcoding,
+            this.dc_receivecoding});
             this.GridViewCommandSet.GridControl = this.GridCommandSetting;
             this.GridViewCommandSet.GridControl = this.GridCommandSetting;
             this.GridViewCommandSet.IndicatorWidth = 30;
             this.GridViewCommandSet.IndicatorWidth = 30;
             this.GridViewCommandSet.Name = "GridViewCommandSet";
             this.GridViewCommandSet.Name = "GridViewCommandSet";
@@ -554,6 +557,7 @@ namespace UAS_DeviceMonitor
             this.CommandSetCheckedColumn.Tag = "0";
             this.CommandSetCheckedColumn.Tag = "0";
             this.CommandSetCheckedColumn.Visible = true;
             this.CommandSetCheckedColumn.Visible = true;
             this.CommandSetCheckedColumn.VisibleIndex = 0;
             this.CommandSetCheckedColumn.VisibleIndex = 0;
+            this.CommandSetCheckedColumn.Width = 60;
             // 
             // 
             // CheckEditCommandSet
             // CheckEditCommandSet
             // 
             // 
@@ -573,7 +577,7 @@ namespace UAS_DeviceMonitor
             this.dc_code.Name = "dc_code";
             this.dc_code.Name = "dc_code";
             this.dc_code.Visible = true;
             this.dc_code.Visible = true;
             this.dc_code.VisibleIndex = 1;
             this.dc_code.VisibleIndex = 1;
-            this.dc_code.Width = 118;
+            this.dc_code.Width = 95;
             // 
             // 
             // dc_name
             // dc_name
             // 
             // 
@@ -582,16 +586,43 @@ namespace UAS_DeviceMonitor
             this.dc_name.Name = "dc_name";
             this.dc_name.Name = "dc_name";
             this.dc_name.Visible = true;
             this.dc_name.Visible = true;
             this.dc_name.VisibleIndex = 2;
             this.dc_name.VisibleIndex = 2;
-            this.dc_name.Width = 123;
+            this.dc_name.Width = 99;
             // 
             // 
-            // dc_command
+            // dc_value
             // 
             // 
             this.dc_value.Caption = "发送指令";
             this.dc_value.Caption = "发送指令";
             this.dc_value.FieldName = "DC_VALUE";
             this.dc_value.FieldName = "DC_VALUE";
             this.dc_value.Name = "dc_value";
             this.dc_value.Name = "dc_value";
             this.dc_value.Visible = true;
             this.dc_value.Visible = true;
             this.dc_value.VisibleIndex = 3;
             this.dc_value.VisibleIndex = 3;
-            this.dc_value.Width = 768;
+            this.dc_value.Width = 291;
+            // 
+            // dc_sendcoding
+            // 
+            this.dc_sendcoding.Caption = "发送编码";
+            this.dc_sendcoding.ColumnEdit = this.CommandSetRepositoryItemComboBox1;
+            this.dc_sendcoding.FieldName = "DC_SENDCODING";
+            this.dc_sendcoding.Name = "dc_sendcoding";
+            this.dc_sendcoding.Visible = true;
+            this.dc_sendcoding.VisibleIndex = 4;
+            this.dc_sendcoding.Width = 219;
+            // 
+            // CommandSetRepositoryItemComboBox1
+            // 
+            this.CommandSetRepositoryItemComboBox1.AutoHeight = false;
+            this.CommandSetRepositoryItemComboBox1.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
+            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
+            this.CommandSetRepositoryItemComboBox1.Name = "CommandSetRepositoryItemComboBox1";
+            // 
+            // dc_receivecoding
+            // 
+            this.dc_receivecoding.Caption = "接收编码";
+            this.dc_receivecoding.ColumnEdit = this.CommandSetRepositoryItemComboBox1;
+            this.dc_receivecoding.FieldName = "DC_RECEIVECODING";
+            this.dc_receivecoding.Name = "dc_receivecoding";
+            this.dc_receivecoding.Visible = true;
+            this.dc_receivecoding.VisibleIndex = 5;
+            this.dc_receivecoding.Width = 231;
             // 
             // 
             // PageDeviceNetSetting
             // PageDeviceNetSetting
             // 
             // 
@@ -1151,39 +1182,11 @@ namespace UAS_DeviceMonitor
             // 
             // 
             // PageDeviceStatus
             // PageDeviceStatus
             // 
             // 
-            this.PageDeviceStatus.Controls.Add(this.GridDeviceStatus);
             this.PageDeviceStatus.Name = "PageDeviceStatus";
             this.PageDeviceStatus.Name = "PageDeviceStatus";
             this.PageDeviceStatus.PageVisible = false;
             this.PageDeviceStatus.PageVisible = false;
             this.PageDeviceStatus.Size = new System.Drawing.Size(1027, 577);
             this.PageDeviceStatus.Size = new System.Drawing.Size(1027, 577);
             this.PageDeviceStatus.Text = "xtraTabPage1";
             this.PageDeviceStatus.Text = "xtraTabPage1";
             // 
             // 
-            // GridDeviceStatus
-            // 
-            this.GridDeviceStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
-            | System.Windows.Forms.AnchorStyles.Left) 
-            | System.Windows.Forms.AnchorStyles.Right)));
-            this.GridDeviceStatus.Condition = null;
-            this.GridDeviceStatus.GetDataSQL = null;
-            this.GridDeviceStatus.ID = null;
-            this.GridDeviceStatus.InsertSQL = null;
-            this.GridDeviceStatus.Location = new System.Drawing.Point(3, 0);
-            this.GridDeviceStatus.MainView = this.GridViewDeviceStatus;
-            this.GridDeviceStatus.MenuManager = this.RibbonNav;
-            this.GridDeviceStatus.Name = "GridDeviceStatus";
-            this.GridDeviceStatus.RowCount = 0;
-            this.GridDeviceStatus.Size = new System.Drawing.Size(1024, 577);
-            this.GridDeviceStatus.TabIndex = 0;
-            this.GridDeviceStatus.TableName = null;
-            this.GridDeviceStatus.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] {
-            this.GridViewDeviceStatus});
-            // 
-            // GridViewDeviceStatus
-            // 
-            this.GridViewDeviceStatus.GridControl = this.GridDeviceStatus;
-            this.GridViewDeviceStatus.IndicatorWidth = 30;
-            this.GridViewDeviceStatus.Name = "GridViewDeviceStatus";
-            this.GridViewDeviceStatus.OptionsView.ShowGroupPanel = false;
-            // 
             // PageWorkCenterStatus
             // PageWorkCenterStatus
             // 
             // 
             this.PageWorkCenterStatus.Controls.Add(this.GridWorkCenterStatus);
             this.PageWorkCenterStatus.Controls.Add(this.GridWorkCenterStatus);
@@ -1246,6 +1249,7 @@ namespace UAS_DeviceMonitor
             ((System.ComponentModel.ISupportInitialize)(this.GridCommandSetting)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridCommandSetting)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewCommandSet)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewCommandSet)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.CheckEditCommandSet)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.CheckEditCommandSet)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.CommandSetRepositoryItemComboBox1)).EndInit();
             this.PageDeviceNetSetting.ResumeLayout(false);
             this.PageDeviceNetSetting.ResumeLayout(false);
             ((System.ComponentModel.ISupportInitialize)(this.GridDeviceNetSetting)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridDeviceNetSetting)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewDeviceNetSetting)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewDeviceNetSetting)).EndInit();
@@ -1259,9 +1263,6 @@ namespace UAS_DeviceMonitor
             this.PagePolling.ResumeLayout(false);
             this.PagePolling.ResumeLayout(false);
             ((System.ComponentModel.ISupportInitialize)(this.GridPolling)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridPolling)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewPolling)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewPolling)).EndInit();
-            this.PageDeviceStatus.ResumeLayout(false);
-            ((System.ComponentModel.ISupportInitialize)(this.GridDeviceStatus)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.GridViewDeviceStatus)).EndInit();
             this.PageWorkCenterStatus.ResumeLayout(false);
             this.PageWorkCenterStatus.ResumeLayout(false);
             ((System.ComponentModel.ISupportInitialize)(this.GridWorkCenterStatus)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridWorkCenterStatus)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewWorkCenterStatus)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewWorkCenterStatus)).EndInit();
@@ -1355,8 +1356,6 @@ namespace UAS_DeviceMonitor
         private GridViewWithSerialNum GridViewDeviceNetSetting;
         private GridViewWithSerialNum GridViewDeviceNetSetting;
         private DevExpress.XtraTab.XtraTabPage PageDeviceStatus;
         private DevExpress.XtraTab.XtraTabPage PageDeviceStatus;
         private DevExpress.XtraTab.XtraTabPage PageWorkCenterStatus;
         private DevExpress.XtraTab.XtraTabPage PageWorkCenterStatus;
-        private AutoDataGridControl GridDeviceStatus;
-        private GridViewWithSerialNum GridViewDeviceStatus;
         private AutoDataGridControl GridWorkCenterStatus;
         private AutoDataGridControl GridWorkCenterStatus;
         private GridViewWithSerialNum GridViewWorkCenterStatus;
         private GridViewWithSerialNum GridViewWorkCenterStatus;
         private DevExpress.XtraGrid.Columns.GridColumn dnc_id;
         private DevExpress.XtraGrid.Columns.GridColumn dnc_id;
@@ -1372,5 +1371,8 @@ namespace UAS_DeviceMonitor
         private CustomerControl.Button.ButtonSaveGrid ButtonSaveNetConfig;
         private CustomerControl.Button.ButtonSaveGrid ButtonSaveNetConfig;
         private DevExpress.XtraGrid.Columns.GridColumn NetSettingCheckedColumn;
         private DevExpress.XtraGrid.Columns.GridColumn NetSettingCheckedColumn;
         private DevExpress.XtraGrid.Columns.GridColumn gridColumn2;
         private DevExpress.XtraGrid.Columns.GridColumn gridColumn2;
+        private DevExpress.XtraGrid.Columns.GridColumn dc_sendcoding;
+        private DevExpress.XtraGrid.Columns.GridColumn dc_receivecoding;
+        private DevExpress.XtraEditors.Repository.RepositoryItemComboBox CommandSetRepositoryItemComboBox1;
     }
     }
 }
 }

+ 55 - 7
UAS_DeviceMonitor/Main.cs

@@ -17,6 +17,7 @@ namespace UAS_DeviceMonitor
 
 
         StringBuilder sql = new StringBuilder();
         StringBuilder sql = new StringBuilder();
         DataHelper dh;
         DataHelper dh;
+        ModeBusTCPServer mbt = new ModeBusTCPServer();
 
 
         #region 初始化代码
         #region 初始化代码
         public Main()
         public Main()
@@ -25,9 +26,39 @@ namespace UAS_DeviceMonitor
             SystemInf.dh = dh;
             SystemInf.dh = dh;
             InitializeComponent();
             InitializeComponent();
             dpc_enableCheckEdit.QueryCheckStateByValue += CheckedEdit_QueryCheckStateByValue;
             dpc_enableCheckEdit.QueryCheckStateByValue += CheckedEdit_QueryCheckStateByValue;
+            CommandSetRepositoryItemComboBox1.ParseEditValue += CommandSetRepositoryItemComboBox1_ParseEditValue;
             CheckEditCommandSet.QueryCheckStateByValue += CheckedEdit_QueryCheckStateByValue;
             CheckEditCommandSet.QueryCheckStateByValue += CheckedEdit_QueryCheckStateByValue;
             PollSettingItemSearchLookUpEdit.ParseEditValue += PollSettingItemSearchLookUpEdit_ParseEditValue;
             PollSettingItemSearchLookUpEdit.ParseEditValue += PollSettingItemSearchLookUpEdit_ParseEditValue;
             GridViewPollSetting.RowCellStyle += GridViewPollSetting_RowCellStyle;
             GridViewPollSetting.RowCellStyle += GridViewPollSetting_RowCellStyle;
+            #region 添加发送接收编码规则的静态值
+            ComboBoxData cbd = new ComboBoxData();
+            cbd.Text = "UTF-8";
+            cbd.Value = "UTF-8";
+            ComboBoxData cbd1 = new ComboBoxData();
+            cbd1.Text = "Hexadecimal";
+            cbd1.Value = "Hexadecimal";
+            ComboBoxData cbd2 = new ComboBoxData();
+            cbd2.Text = "ASCII";
+            cbd2.Value = "ASCII";
+            CommandSetRepositoryItemComboBox1.Items.Add(cbd);
+            CommandSetRepositoryItemComboBox1.Items.Add(cbd1);
+            CommandSetRepositoryItemComboBox1.Items.Add(cbd2);
+            #endregion
+        }
+
+        private void CommandSetRepositoryItemComboBox1_ParseEditValue(object sender, DevExpress.XtraEditors.Controls.ConvertEditValueEventArgs e)
+        {
+            string val = "";
+            if (e.Value != null)
+            {
+                val = e.Value.ToString();
+            }
+            else
+            {
+                val = "FALSE";//默认为不选   
+            }
+            e.Value = val;
+            e.Handled = true;
         }
         }
 
 
         private void PollSettingItemSearchLookUpEdit_ParseEditValue(object sender, DevExpress.XtraEditors.Controls.ConvertEditValueEventArgs e)
         private void PollSettingItemSearchLookUpEdit_ParseEditValue(object sender, DevExpress.XtraEditors.Controls.ConvertEditValueEventArgs e)
@@ -59,10 +90,10 @@ namespace UAS_DeviceMonitor
             ButtonDeleteCommandSet.Grid = GridPollingSetting;
             ButtonDeleteCommandSet.Grid = GridPollingSetting;
 
 
             //指令设置界面
             //指令设置界面
-            GridCommandSetting.GetDataSQL = "select 0 CHECKEDCOLUMN,dc_id,dc_code,dc_name,dc_value from devicecommand order by dc_id".ToUpper();
+            GridCommandSetting.GetDataSQL = "select 0 CHECKEDCOLUMN,dc_id,dc_code,dc_name,dc_value,dc_sendcoding,dc_receivecoding from devicecommand ".ToUpper();
             GridCommandSetting.TableName = "devicecommand";
             GridCommandSetting.TableName = "devicecommand";
             GridCommandSetting.ID = "dc_id";
             GridCommandSetting.ID = "dc_id";
-            GridCommandSetting.InsertSQL = "insert into devicecommand(dc_id,dc_code,dc_name,dc_value,dc_debrand) values(devicecommand_seq.nextval,:dc_code,:dc_name,:dc_value,'" + BaseUtil.GetComboxEditValue(Brand) + "')";
+            GridCommandSetting.InsertSQL = "insert into devicecommand(dc_id,dc_code,dc_name,dc_value,dc_debrand,dc_sendcoding,dc_receivecoding) values(devicecommand_seq.nextval,:dc_code,:dc_name,:dc_value,'" + BaseUtil.GetComboxEditValue(Brand) + "',:dc_sendcoding,:dc_receivecoding)";
             ButtonSaveCommand.Grid = GridCommandSetting;
             ButtonSaveCommand.Grid = GridCommandSetting;
             ButtonDeleteCommand.Grid = GridCommandSetting;
             ButtonDeleteCommand.Grid = GridCommandSetting;
             ButtonNewCommand.Grid = GridCommandSetting;
             ButtonNewCommand.Grid = GridCommandSetting;
@@ -150,7 +181,7 @@ namespace UAS_DeviceMonitor
         /// <param name="e"></param>
         /// <param name="e"></param>
         private void ButtonSaveCommand_Click(object sender, EventArgs e)
         private void ButtonSaveCommand_Click(object sender, EventArgs e)
         {
         {
-            GridCommandSetting.InsertSQL = "insert into devicecommand(dc_id,dc_code,dc_name,dc_value,dc_debrand) values(devicecommand_seq.nextval,:dc_code,:dc_name,:dc_value,'" + BaseUtil.GetComboxEditValue(Brand) + "')";
+            GridCommandSetting.InsertSQL = "insert into devicecommand(dc_id,dc_code,dc_name,dc_value,dc_debrand,dc_sendcoding,dc_receivecoding) values(devicecommand_seq.nextval,:dc_code,:dc_name,:dc_value,'" + BaseUtil.GetComboxEditValue(Brand) + "',:dc_sendcoding,:dc_receivecoding)";
             ButtonSaveCommand.DoSave();
             ButtonSaveCommand.DoSave();
         }
         }
 
 
@@ -165,7 +196,7 @@ namespace UAS_DeviceMonitor
             {
             {
                 DataTable dt = (DataTable)SystemInf.dh.ExecuteSql("select * from devicebrand", "select");
                 DataTable dt = (DataTable)SystemInf.dh.ExecuteSql("select * from devicebrand", "select");
                 BaseUtil.FillComBoxEditWidthDataTable(Brand, "db_name", "db_code", dt);
                 BaseUtil.FillComBoxEditWidthDataTable(Brand, "db_name", "db_code", dt);
-                GridCommandSetting.Condition = " where dc_debrand='" + BaseUtil.GetComboxEditValue(Brand) + "'";
+                GridCommandSetting.Condition = " where dc_debrand='" + BaseUtil.GetComboxEditValue(Brand) + "' order by dc_id";
             }
             }
         }
         }
 
 
@@ -188,14 +219,17 @@ namespace UAS_DeviceMonitor
         private void ButtonStartPolling_Click(object sender, EventArgs e)
         private void ButtonStartPolling_Click(object sender, EventArgs e)
         {
         {
             GridView grid = GridViewPollSetting;
             GridView grid = GridViewPollSetting;
+            mbt.Open();
             for (int i = 0; i < GridPollingSetting.RowCount; i++)
             for (int i = 0; i < GridPollingSetting.RowCount; i++)
             {
             {
                 Polling pl = new Polling();
                 Polling pl = new Polling();
                 pl.Id = int.Parse(GridViewPollSetting.GetRowCellValue(i, "DPC_ID").ToString());
                 pl.Id = int.Parse(GridViewPollSetting.GetRowCellValue(i, "DPC_ID").ToString());
                 pl.DeviceCode = GridViewPollSetting.GetRowCellValue(i, "DPC_DECODE").ToString();
                 pl.DeviceCode = GridViewPollSetting.GetRowCellValue(i, "DPC_DECODE").ToString();
+                pl.CommandCode = GridViewPollSetting.GetRowCellValue(i, "DPC_DCCODE").ToString();
                 pl.Interval = int.Parse(GridViewPollSetting.GetRowCellValue(i, "DPC_INTERVAL").ToString());
                 pl.Interval = int.Parse(GridViewPollSetting.GetRowCellValue(i, "DPC_INTERVAL").ToString());
+                pl.SendRadix = GridViewPollSetting.GetRowCellValue(i, "DPC_INTERVAL").ToString();
                 pl.Enable = GridViewPollSetting.GetRowCellValue(i, "DPC_ENABLE").ToString() != "0";
                 pl.Enable = GridViewPollSetting.GetRowCellValue(i, "DPC_ENABLE").ToString() != "0";
-                pl.Code = GridViewPollSetting.GetRowCellValue(i, "DPC_PLCODE").ToString();
+                pl.Dh = new DataHelper();
                 if (pl.Enable)
                 if (pl.Enable)
                 {
                 {
                     pt.AddTask(RunTask, pl);
                     pt.AddTask(RunTask, pl);
@@ -250,9 +284,23 @@ namespace UAS_DeviceMonitor
         {
         {
             PollingTimer timer = (PollingTimer)sender;
             PollingTimer timer = (PollingTimer)sender;
             Polling pl = (Polling)timer.Polling;
             Polling pl = (Polling)timer.Polling;
+            DataHelper dh = pl.Dh;
             string Decode = pl.DeviceCode;
             string Decode = pl.DeviceCode;
-            string IP = dh.getFieldDataByCondition("DEVICENETCONFIG", "dnc_ip", "dnc_decode='" + Decode + "'").ToString();
-            Console.WriteLine(IP);
+            string Dccode = pl.CommandCode;
+            DataTable dt = (DataTable)dh.ExecuteSql("select dnc_ip,dnc_port from DEVICENETCONFIG where dnc_decode='" + Decode + "'", "select");
+            DataTable dt1 = (DataTable)dh.ExecuteSql("select dc_sendcoding,dc_value from devicecommand where dc_code='" + Dccode + "'", "select");
+            if (dt.Rows.Count > 0)
+            {
+                string IP = dt.Rows[0]["dnc_ip"].ToString() + ":" + dt.Rows[0]["dnc_port"].ToString();
+                string Coding = "";
+                string Command = "";
+                if (dt1.Rows.Count > 0)
+                {
+                    Coding = dt1.Rows[0]["dc_sendcoding"].ToString();
+                    Command = dt1.Rows[0]["dc_value"].ToString();
+                }
+                mbt.Send(IP, Coding, Command);
+            }
         }
         }
 
 
         /// <summary>
         /// <summary>

+ 68 - 78
UAS_DeviceMonitor/PublicMethod/ModeBusTCPServer.cs

@@ -70,12 +70,19 @@ namespace UAS_DeviceMonitor.PublicMethod
         {
         {
             try
             try
             {
             {
+                IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
+                for (int i = 0; i < IpEntry.AddressList.Length; i++)
+                {
+                    if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
+                        iP = IpEntry.AddressList[i].ToString();
+                }
+                Console.WriteLine(iP);
                 //定义一个套接字用于监听客户端发来的信息  包含3个参数(IP4寻址协议,流式连接,TCP协议)
                 //定义一个套接字用于监听客户端发来的信息  包含3个参数(IP4寻址协议,流式连接,TCP协议)
                 socketWatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                 socketWatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                 //服务端发送信息 需要1个IP地址和端口号
                 //服务端发送信息 需要1个IP地址和端口号
                 IPAddress ipaddress = IPAddress.Parse(iP);
                 IPAddress ipaddress = IPAddress.Parse(iP);
                 //将IP地址和端口号绑定到网络节点endpoint上 
                 //将IP地址和端口号绑定到网络节点endpoint上 
-                IPEndPoint endpoint = new IPEndPoint(ipaddress, int.Parse(port));
+                IPEndPoint endpoint = new IPEndPoint(ipaddress, 8090);
                 //监听绑定的网络节点
                 //监听绑定的网络节点
                 socketWatch.Bind(endpoint);
                 socketWatch.Bind(endpoint);
                 //将套接字的监听队列长度限制为20
                 //将套接字的监听队列长度限制为20
@@ -96,68 +103,66 @@ namespace UAS_DeviceMonitor.PublicMethod
             }
             }
         }
         }
 
 
-        //private void SEND_Click(object sender, EventArgs e)
-        //{
-        //    foreach (Socket item in list)
-        //    {
-        //        if (item != null)
-        //        {
-        //            if (item.RemoteEndPoint != null)
-        //            {
-        //                if (item.RemoteEndPoint.ToString() == SelectIP.Text)
-        //                {
-        //                    switch (Encodingbox.Text)
-        //                    {
-        //                        case "UTF-8":
-        //                            item.Send(Encoding.UTF8.GetBytes(SENDMESSAGE.Text));
-        //                            break;
-        //                        case "ASCII":
-        //                            byte[] array = Encoding.ASCII.GetBytes(SENDMESSAGE.Text.Trim());
-        //                            string str = null;
-        //                            for (int i = 0; i < array.Length; i++)
-        //                            {
-        //                                int asciicode = (int)(array[i]);
-        //                                str += Convert.ToString(asciicode) + " ";
-        //                            }
-        //                            item.Send(Encoding.ASCII.GetBytes(str));
-        //                            break;
-        //                        case "Hexadecimal":
-        //                            char[] values = SENDMESSAGE.Text.ToCharArray();
-        //                            string strH = null;
-        //                            foreach (char letter in values)
-        //                            {
-        //                                // Get the integral value of the character.
-        //                                int value = Convert.ToInt32(letter);
-        //                                // Convert the decimal value to a hexadecimal value in string form.
-        //                                string hexOutput = String.Format("{0:X}", value);
-        //                                strH += hexOutput + " ";
-        //                            }
-        //                            item.Send(Encoding.UTF8.GetBytes(strH));
-        //                            break;
-        //                    }                        
-        //                }
-        //            }
-        //            else
-        //            {   
-        //                int index = SelectIP.Items.IndexOf(item.RemoteEndPoint.ToString());
-        //                SelectIP.Items.RemoveAt(index);
-        //                if (SelectIP.Items.Count > 0)
-        //                {
-        //                    if (SelectIP.Text == "")
-        //                        SelectIP.Text = SelectIP.Items[0].ToString();
-        //                }
-        //                else
-        //                    SelectIP.Text = "";
-        //                if (list.Contains(item))
-        //                {
-        //                    list.Remove(item);
-        //                }
-        //                //关闭之前accept出来的和客户端进行通信的套接字 
-        //                item.Close();
-        //            }
-        //        }
-        //    }
-        //}
+        public void Send(string IPAddress, string EnCoding, string Command)
+        {
+            foreach (Socket item in list)
+            {
+                if (item != null)
+                {
+                    if (item.RemoteEndPoint != null)
+                    {
+                        if (item.RemoteEndPoint.ToString() == IPAddress)
+                        {
+                            switch (EnCoding)
+                            {
+                                case "UTF-8":
+                                    item.Send(Encoding.UTF8.GetBytes(Command));
+                                    break;
+                                case "ASCII":
+                                    byte[] array = Encoding.ASCII.GetBytes(Command);
+                                    string str = null;
+                                    for (int i = 0; i < array.Length; i++)
+                                    {
+                                        int asciicode = (int)(array[i]);
+                                        str += Convert.ToString(asciicode) + " ";
+                                    }
+                                    item.Send(Encoding.ASCII.GetBytes(str));
+                                    break;
+                                case "Hexadecimal":
+                                    char[] values = Command.ToCharArray();
+                                    string strH = null;
+                                    foreach (char letter in values)
+                                    {
+                                        // Get the integral value of the character.
+                                        int value = Convert.ToInt32(letter);
+                                        // Convert the decimal value to a hexadecimal value in string form.
+                                        string hexOutput = String.Format("{0:X}", value);
+                                        strH += hexOutput + " ";
+                                    }
+                                    item.Send(Encoding.UTF8.GetBytes(strH));
+                                    break;
+                            }
+                        }
+                    }
+                    else
+                    {
+                        if (list.Count > 0)
+                        {
+                            if (IPAddress == "")
+                                IPAddress = list[0].RemoteEndPoint.ToString();
+                        }
+                        else
+                            IPAddress = "";
+                        if (list.Contains(item))
+                        {
+                            list.Remove(item);
+                        }
+                        //关闭之前accept出来的和客户端进行通信的套接字 
+                        item.Close();
+                    }
+                }
+            }
+        }
 
 
         private void WatchConnecting()
         private void WatchConnecting()
         {
         {
@@ -184,9 +189,7 @@ namespace UAS_DeviceMonitor.PublicMethod
                 //客户端网络结点号  
                 //客户端网络结点号  
                 string remoteEndPoint = connection.RemoteEndPoint.ToString();
                 string remoteEndPoint = connection.RemoteEndPoint.ToString();
                 //显示与客户端连接情况
                 //显示与客户端连接情况
-                //IPEndPoint netpoint = new IPEndPoint(clientIP,clientPort); 
                 IPEndPoint netpoint = connection.RemoteEndPoint as IPEndPoint;
                 IPEndPoint netpoint = connection.RemoteEndPoint as IPEndPoint;
-
                 //创建一个通信线程      
                 //创建一个通信线程      
                 ParameterizedThreadStart pts = new ParameterizedThreadStart(recv);
                 ParameterizedThreadStart pts = new ParameterizedThreadStart(recv);
                 Thread thread = new Thread(pts);
                 Thread thread = new Thread(pts);
@@ -194,7 +197,6 @@ namespace UAS_DeviceMonitor.PublicMethod
                 thread.IsBackground = true;
                 thread.IsBackground = true;
                 //启动线程     
                 //启动线程     
                 thread.Start(connection);
                 thread.Start(connection);
-
                 //创建一个通信线程
                 //创建一个通信线程
                 //ParameterizedThreadStart sed = new ParameterizedThreadStart(sends);
                 //ParameterizedThreadStart sed = new ParameterizedThreadStart(sends);
                 //Thread threadsed = new Thread(sed);
                 //Thread threadsed = new Thread(sed);
@@ -202,9 +204,7 @@ namespace UAS_DeviceMonitor.PublicMethod
                 //threadsed.IsBackground = true;
                 //threadsed.IsBackground = true;
                 //启动线程
                 //启动线程
                 //threadsed.Start(connection);
                 //threadsed.Start(connection);
-
                 list.Add(connection);
                 list.Add(connection);
-
             }
             }
         }
         }
 
 
@@ -263,15 +263,5 @@ namespace UAS_DeviceMonitor.PublicMethod
             socketWatch.Close();
             socketWatch.Close();
             isOpen = false;
             isOpen = false;
         }
         }
-
-        public void SendOrder(string Code)
-        {
-
-            switch (Code)
-            {
-                default:
-                    break;
-            }
-        }
     }
     }
 }
 }

+ 0 - 5
UAS_DeviceMonitor/PublicMethod/PollingTask.cs

@@ -41,11 +41,6 @@ namespace UAS_DeviceMonitor.PublicMethod
         public void AddTask(Action<object> action, object obj)
         public void AddTask(Action<object> action, object obj)
         {
         {
             Task.Factory.StartNew(action, obj);
             Task.Factory.StartNew(action, obj);
-            //Polling pl = (Polling)obj;
-            //if (!InTask.ContainsKey(pl.Code))
-            //{
-            //    InTask.Add(pl.Code, Task.Factory.StartNew(action, obj));
-            //}
         }
         }
 
 
         /// 添加一系列任务
         /// 添加一系列任务