| | |
| | | //using CodeProvider; |
| | | using DevExpress.Utils.Extensions; |
| | | using DevExpress.XtraEditors; |
| | | using DevExpress.XtraEditors.Controls; |
| | | using DevExpress.XtraLayout; |
| | | 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 = "协议配置"; |
| | |
| | | public event EventHandler<string> SendData; |
| | | private void SendText(string content) |
| | | { |
| | | //BluetoothHelper.GetInstance().SendData(content); |
| | | SendData?.Invoke(null, content); |
| | | if (SendData != null) |
| | | { |
| | | SendData?.Invoke(null, content); |
| | | |
| | | } |
| | | else |
| | | { |
| | | if (IBoxHelper.Ping()) |
| | | { |
| | | var smsg = content.Split(new string[] { IBoxHelper.paramCode, IBoxHelper.startCode }, StringSplitOptions.RemoveEmptyEntries); |
| | | if (smsg.Length < 2) |
| | | { |
| | | return; |
| | | } |
| | | switch (smsg[0].Trim()) |
| | | { |
| | | case IBoxHelper.getprotocolCode: |
| | | { |
| | | var order = IBoxHelper.HttpGet(content); |
| | | var result = IBoxHelper.GetContent(order); |
| | | if (!string.IsNullOrEmpty(result)) |
| | | { |
| | | var model = JsonHelper.Json2Object<IBoxProtocolViewModel>(result); |
| | | BindData(model, false); |
| | | } |
| | | break; |
| | | } |
| | | case IBoxHelper.saveprotocolCode: |
| | | { |
| | | IBoxHelper.HttpPost(content); |
| | | break; |
| | | |
| | | } |
| | | default: |
| | | IBoxHelper.HttpGet(content); |
| | | break; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | MessageBoxHelper.ShowWarning("网络连接失败,请检查网络"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | 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; |
| | | layoutControlItem4.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
| | | } |
| | | private void simpleButton1_Click(object sender, EventArgs e) |
| | | { |
| | | SendText(startCode + saveprotocolCode + paramCode + JsonHelper.Object2Json(GetData()) + endCode); |
| | | MessageBoxHelper.ShowInfo("数据保存成功!"); |
| | | Save(); |
| | | } |
| | | |
| | | private void SetData() |
| | | /// <summary> |
| | | /// 保存数据 |
| | | /// </summary> |
| | | public void Save() |
| | | { |
| | | SendText(IBoxHelper.startCode + IBoxHelper.saveprotocolCode + IBoxHelper.paramCode + JsonHelper.Object2Json(GetData()) + IBoxHelper.endCode); |
| | | MessageBoxHelper.ShowInfo("数据保存成功!"); |
| | | |
| | | } |
| | | 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) |