| | |
| | | //using CodeProvider; |
| | | using DevExpress.Utils.Extensions; |
| | | using DevExpress.XtraEditors; |
| | | using DevExpress.XtraEditors.Controls; |
| | | using System.Data; |
| | | using Yw; |
| | | using Yw.WinFrmUI; |
| | | |
| | |
| | | { |
| | | public partial class IBoxFormProtocol : DocumentPage |
| | | { |
| | | private string startCode = "[&start&]"; |
| | | private string endCode = "[&end&]"; |
| | | private string paramCode = "[¶m&]"; |
| | | private string getprotocolCode = "getprotocol"; |
| | | private string saveprotocolCode = "saveprotocol"; |
| | | |
| | | public IBoxFormProtocol() |
| | | { |
| | | this.PageTitle.Caption = "协议配置"; |
| | | InitializeComponent(); |
| | | SetData(); |
| | | |
| | | |
| | | } |
| | | public event EventHandler<string> SendData; |
| | | private void SendText(string content) |
| | | { |
| | | //BluetoothHelper.GetInstance().SendData(content); |
| | | SendData?.Invoke(null, content); |
| | | } |
| | | |
| | | |
| | | public void GetReceive(string msg) |
| | | public void HideButton() |
| | | { |
| | | if (!this.IsHandleCreated || this.IsDisposed || string.IsNullOrEmpty(msg)) return; |
| | | if (msg.StartsWith("error:") && msg.Contains("目标主机坏了")) |
| | | { |
| | | MessageBoxHelper.ShowError("pr 蓝牙设备连接失败,请重试!"); return; |
| | | } |
| | | if (!string.IsNullOrEmpty(msg) && msg.Contains(startCode)) |
| | | { |
| | | var order = msg.Replace(endCode, "").Replace(startCode, "").Trim(); |
| | | SetOrder(order); |
| | | } |
| | | else MessageBoxHelper.ShowError("pr 蓝牙设备连接失败!"); |
| | | simpleButton1.Visible = false; |
| | | } |
| | | private void simpleButton1_Click(object sender, EventArgs e) |
| | | { |
| | | SendText(startCode + saveprotocolCode + paramCode + JsonHelper.Object2Json(GetData()) + endCode); |
| | | Save(); |
| | | MessageBoxHelper.ShowInfo("数据保存成功!"); |
| | | } |
| | | |
| | | private void SetData() |
| | | /// <summary> |
| | | /// 保存数据 |
| | | /// </summary> |
| | | public void Save() |
| | | { |
| | | SendText(IBoxHelper.startCode + IBoxHelper.saveprotocolCode + IBoxHelper.paramCode + JsonHelper.Object2Json(GetData()) + IBoxHelper.endCode); |
| | | } |
| | | public void SetData() |
| | | { |
| | | |
| | | var control = new ProtocolModbus(); |
| | |
| | | private void EboxFormProtocol_Load(object sender, EventArgs e) |
| | | { |
| | | Thread.Sleep(500); |
| | | SendText(startCode + getprotocolCode + paramCode + endCode); |
| | | //BluetoothHelper.GetInstance().SMR -= null; |
| | | //BluetoothHelper.GetInstance().SMR += new BluetoothHelper.ShowMessReturn(GetReceive); |
| | | SendText(IBoxHelper.startCode + IBoxHelper.getprotocolCode + IBoxHelper.paramCode + IBoxHelper.endCode); |
| | | } |
| | | |
| | | private void SetOrder(string order) |
| | | { |
| | | var smsg = order.Split(new string[] { paramCode }, StringSplitOptions.RemoveEmptyEntries); |
| | | if (smsg.Length < 2) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | switch (smsg[0].Trim()) |
| | | { |
| | | case "getprotocol": |
| | | var model = JsonHelper.Json2Object<IBoxProtocolViewModel>(smsg[1].Trim()); |
| | | BindData(model); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 绑定数据 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <param name="isBlue"></param> |
| | | public void BindData(IBoxProtocolViewModel model, bool isBlue = true) |
| | | { |
| | | if (model == null) |
| | |
| | | stopBits = System.IO.Ports.StopBits.One |
| | | }; |
| | | } |
| | | if (isBlue) { |
| | | this.Invoke(new Action(() => |
| | | if (isBlue) |
| | | { |
| | | var protocols = new dModbus().ProtocolType(); |
| | | var des = protocols.FirstOrDefault(x => x.Value == model.ProtocolType).Key; |
| | | imageComboBoxEditType.SelectItemByDescription(des); |
| | | ChangeType(model.ProtocolType, model); |
| | | })); |
| | | this.Invoke(new Action(() => |
| | | { |
| | | var protocols = new dModbus().ProtocolType(); |
| | | var des = protocols.FirstOrDefault(x => x.Value == model.ProtocolType).Key; |
| | | imageComboBoxEditType.SelectItemByDescription(des); |
| | | ChangeType(model.ProtocolType, model); |
| | | })); |
| | | } |
| | | else |
| | | { |