|
- using BPA.Helper;
-
- using BPASmartClient.Model;
- //using CommunityToolkit.Mvvm.Input;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.MilkWithTea.ViewModel
- {
- partial class PatrameterSettiongViewModel : NotifyBase
- {
- string FileName => GLobal.deviceConfig.Count > 0 ? GLobal.deviceConfig[0].ShopName : string.Empty;
-
- /// <summary>
- /// 物料通道口列表
- /// </summary>
- public ObservableCollection<int> materialPosions { get; set; } = new ObservableCollection<int>();
-
-
- public int MaterialID { get { return _materialID; } set { _materialID = value; OnPropertyChanged(); } }
- private int _materialID = 0;
-
- /// <summary>
- /// 出料重量
- /// </summary>
- public int OutMaterilWeight { get { return _outMaterilWeight; } set { _outMaterilWeight = value; OnPropertyChanged(); } }
- private int _outMaterilWeight = 0;
-
- /// <summary>
- /// 矫正的通道号
- /// </summary>
- public int CorrectPassway { get { return _CorrectPassway; } set { _CorrectPassway = value; OnPropertyChanged(); } }
- private int _CorrectPassway = 0;
-
- /// <summary>
- /// 通道是否开启
- /// </summary>
- public bool PasswayIsOpen { get { return _passwayIsOpen; } set { _passwayIsOpen = value; OnPropertyChanged(); } }
- private bool _passwayIsOpen;
-
- /// <summary>
- /// 矫正重量
- /// </summary>
- public int CorrectMatetailWeight { get { return _correctMatetailWeight; } set { _correctMatetailWeight = value; OnPropertyChanged(); } }
- private int _correctMatetailWeight;
-
- /// <summary>
- /// 矫正重量
- /// </summary>
- public int OutTime { get { return _outTime; } set { _outTime = value; OnPropertyChanged(); } }
- private int _outTime;
-
- public bool IsEnable { get { return !GLobal.makeEnable; } set { GLobal.makeEnable = !value; OnPropertyChanged(); } }
- /// <summary>
- /// 出料动作
- /// </summary>
- //[BPARelayCommand]
- private void OutMaterial()
- {
- ActionManage.GetInstance.Send("通道口出料", new object[] { MaterialID, OutMaterilWeight });
- }
- /// <summary>
- /// 开始矫正
- /// </summary>
- //[BPARelayCommand]
- private void CheckPassway()
- {
-
- }
- /// <summary>
- /// 开启通道
- /// </summary>
- //[BPARelayCommand]
- private void OpenPassway()
- {
-
- }
- /// <summary>
- /// 确认重量
- /// </summary>
- //[BPARelayCommand]
- private void CheckMaterailWeight()
- {
-
- }
- #region 设备配置
-
- /// <summary>
- /// 店铺名称
- /// </summary>
- public string ShopName { get { return _shopName; } set { _shopName = value; OnPropertyChanged(); } }
- private string _shopName;
-
- /// <summary>
- /// 店铺ID
- /// </summary>
- public string ShopID { get { return _shopID; } set { _shopID = value; OnPropertyChanged(); } }
- private string _shopID;
-
- /// <summary>
- /// 设备ID
- /// </summary>
- public string DeviceID { get { return _deviceID; } set { _deviceID = value; OnPropertyChanged(); } }
- private string _deviceID;
-
- /// <summary>
- /// PLC地址
- /// </summary>
- public string PLCAdress { get { return _pLCAdress; } set { _pLCAdress = value; OnPropertyChanged(); } }
- private string _pLCAdress;
-
- public bool IsPort { get { return _isPort; } set { _isPort = value; OnPropertyChanged(); } }
- private bool _isPort = true;
-
- public Visibility VsIP { get { return _vsIP; } set { _vsIP = value; OnPropertyChanged(); } }
- private Visibility _vsIP = Visibility.Hidden;
-
- public Visibility VsPort { get { return _vsPort; } set { _vsPort = value; OnPropertyChanged(); } }
- private Visibility _vsPort = Visibility.Visible;
-
- public string[] Ports { get { return _ports; } set { _ports = value; OnPropertyChanged(); } }
- private string[] _ports;
-
- public string Prot { get { return _prot; } set { _prot = value; OnPropertyChanged(); } }
- private string _prot;
-
-
- //[BPARelayCommand]
- private void SaveDevices()
- {
- SaveDeviceMessage();
- }
- //[BPARelayCommand]
- private void ChangeCommunation()
- {
- if (IsPort)
- {
- VsPort = Visibility.Visible;
- VsIP = Visibility.Hidden;
- }
- else
- {
- VsIP = Visibility.Visible;
- VsPort = Visibility.Hidden;
- }
- }
- #endregion
-
- public PatrameterSettiongViewModel()
- {
- Ports = System.IO.Ports.SerialPort.GetPortNames();
- init();
- }
- private void init()
- {
- for (int i = 1; i < 14; i++)
- {
- materialPosions.Add(i);
- }
- if (GLobal.deviceConfig.Count > 0)
- {
- ShopName = GLobal.deviceConfig.ElementAtOrDefault(0).ShopName;
- ShopID = GLobal.deviceConfig.ElementAtOrDefault(0).ShopId;
-
- DeviceID = GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAt(0).DeviceId;
- PLCAdress = GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAt(0).communicationDevcies.ElementAt(0).communicationPar.IPAddress;
- }
-
- }
-
- private void SaveDeviceMessage()
- {
-
- if (GLobal.deviceConfig.Count > 0)
- {
- GLobal.deviceConfig.ElementAtOrDefault(0).ShopName = ShopName;
- GLobal.deviceConfig.ElementAtOrDefault(0).ShopId = ShopID;
- GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).DeviceId = DeviceID;
- if (IsPort)
- {
- GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.ElementAtOrDefault(0).communicationPar.IsSerialPort = true;
- GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.ElementAtOrDefault(0).communicationPar.SerialPort = Prot;
- GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.ElementAtOrDefault(0).communicationPar.BaudRate = 9600;
- }
- else
- {
- GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.ElementAtOrDefault(0).communicationPar.IsSerialPort = false;
- GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.ElementAtOrDefault(0).communicationPar.IsNetworkPort = true;
- GLobal.deviceConfig.ElementAtOrDefault(0).deviceModels.ElementAtOrDefault(0).communicationDevcies.ElementAtOrDefault(0).communicationPar.IPAddress = PLCAdress;
- }
- }
- File.WriteAllText($"{LocaPath.GetDeviceConfigPath}MOC.json", JsonConvert.SerializeObject(GLobal.deviceConfig));
-
-
- }
-
-
- }
- }
|