###### tags: `work` # GXDLMSDirector ## Create a collection of Devices - Device Properties - Form: - `DevicePropertiesForm.cs` ![](https://i.imgur.com/NzWSPJq.png) - Code: - event: `OKBtn_Click` - functions: ```c# private void UpdateSettings(GXDLMSMeter device, bool validate) ``` - class: setting hostname, port, protocol or PortName ```c# public GXNet(NetworkType protocol, string hostName, int connectionPort); public GXSerial(string portName); ``` ---------------------- - 連線設定 ```c# # DevicePropertiesForm.cs private void UpdateMediaSettings() ``` - Media == Net ![](https://i.imgur.com/NzWSPJq.png) code: ```c# # line: 872 else if (SelectedMedia is GXNet) { if (validate && this.HostNameTB.Text.Length == 0) { throw new Exception("Invalid host name."); } ((GXNet)SelectedMedia).HostName = this.HostNameTB.Text; int port; if (!Int32.TryParse(this.PortTB.Text, out port)) { if (validate) { port = 0; } else { throw new Exception("Invalid port number."); } } ((GXNet)SelectedMedia).Port = port; device.UseRemoteSerial = UseRemoteSerialCB.Checked; ((GXNet)SelectedMedia).Protocol = (NetworkType)NetProtocolCB.SelectedItem; } ``` - Media == Serial 插入裝置,`Serial Port`下拉選單會出現可選擇Serial port ![](https://i.imgur.com/zhfUYBo.png) code: ```c# # line: 859 if (SelectedMedia is GXSerial) { device.UseRemoteSerial = false; if (validate && this.SerialPortCB.Text.Length == 0) { throw new Exception("Invalid serial port."); } ((GXSerial)SelectedMedia).PortName = this.SerialPortCB.Text; if (UseMaximumBaudRateCB.Checked) { device.MaximumBaudRate = (int)MaximumBaudRateCB.SelectedItem; } } ``` ```c# # line: 918 if (SelectedMedia != null) { device.MediaSettings = SelectedMedia.Settings; } ``` What is device? `GXDLMSMeter => GXDLMSMeterBase` Meter的設定(like a container) ![](https://i.imgur.com/aDXSc74.png) ------------------- ## Communicate with the device - Connect & Disconnect - Form: - `MainForm.cs` ![](https://i.imgur.com/x2cQTvD.png) - Code: - event: `ConnectMnu_Click`, `DisconnectMnu_Click` - functions: ```C# void Connect(object sender, GXAsyncWork work, object[] parameters) void Disconnect(object sender, GXAsyncWork work, object[] parameters) ``` -------------------------- ```c# # line: 1662 private void ConnectMnu_Click(object sender, EventArgs e) { ClearTrace(); if (tabControl1.SelectedIndex == 0) { TransactionWork = new GXAsyncWork(this, OnAsyncStateChange, Connect, OnError, null, new object[] { ObjectTree.SelectedNode.Tag }); } else { TransactionWork = new GXAsyncWork(this, OnAsyncStateChange, Connect, OnError, null, new object[] { GetDevices() }); } TransactionWork.Start(); } ``` ------------------------- # Todo: - what is class `GXAsyncWork` in function `ConnectMnu_Click` - what is the meaning of the values in `Device Properties` - A table show all the Forms in project