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; /// /// 物料通道口列表 /// public ObservableCollection materialPosions { get; set; } = new ObservableCollection(); public int MaterialID { get { return _materialID; } set { _materialID = value; OnPropertyChanged(); } } private int _materialID = 0; /// /// 出料重量 /// public int OutMaterilWeight { get { return _outMaterilWeight; } set { _outMaterilWeight = value; OnPropertyChanged(); } } private int _outMaterilWeight = 0; /// /// 矫正的通道号 /// public int CorrectPassway { get { return _CorrectPassway; } set { _CorrectPassway = value; OnPropertyChanged(); } } private int _CorrectPassway = 0; /// /// 通道是否开启 /// public bool PasswayIsOpen { get { return _passwayIsOpen; } set { _passwayIsOpen = value; OnPropertyChanged(); } } private bool _passwayIsOpen; /// /// 矫正重量 /// public int CorrectMatetailWeight { get { return _correctMatetailWeight; } set { _correctMatetailWeight = value; OnPropertyChanged(); } } private int _correctMatetailWeight; /// /// 矫正重量 /// 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(); } } /// /// 出料动作 /// //[BPARelayCommand] private void OutMaterial() { ActionManage.GetInstance.Send("通道口出料", new object[] { MaterialID, OutMaterilWeight }); } /// /// 开始矫正 /// //[BPARelayCommand] private void CheckPassway() { } /// /// 开启通道 /// //[BPARelayCommand] private void OpenPassway() { } /// /// 确认重量 /// //[BPARelayCommand] private void CheckMaterailWeight() { } #region 设备配置 /// /// 店铺名称 /// public string ShopName { get { return _shopName; } set { _shopName = value; OnPropertyChanged(); } } private string _shopName; /// /// 店铺ID /// public string ShopID { get { return _shopID; } set { _shopID = value; OnPropertyChanged(); } } private string _shopID; /// /// 设备ID /// public string DeviceID { get { return _deviceID; } set { _deviceID = value; OnPropertyChanged(); } } private string _deviceID; /// /// PLC地址 /// 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)); } } }