|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- using BPASmartClient.Helper;
- using BPASmartClient.Message;
- 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: ObservableObject
- {
- string FileName => GLobal.deviceConfig.Count > 0 ? GLobal.deviceConfig[0].ShopName : string.Empty;
-
- /// <summary>
- /// 物料通道口列表
- /// </summary>
- public ObservableCollection<int> materialPosions { get; set; } = new ObservableCollection<int>();
-
- [ObservableProperty]
- private int _materialID = 0;
-
- /// <summary>
- /// 出料重量
- /// </summary>
- [ObservableProperty]
- private int _outMaterilWeight;
-
- /// <summary>
- /// 矫正的通道号
- /// </summary>
- [ObservableProperty]
- private int _CorrectPassway = 0;
- /// <summary>
- /// 通道是否开启
- /// </summary>
- [ObservableProperty]
- private bool _passwayIsOpen ;
- /// <summary>
- /// 矫正重量
- /// </summary>
- [ObservableProperty]
- private int _correctMatetailWeight = 0;
- /// <summary>
- /// 矫正时间
- /// </summary>
- [ObservableProperty]
- private int _outTime = 0;
-
- public bool IsEnable { get { return !GLobal.makeEnable; } set { GLobal.makeEnable = !value; OnPropertyChanged(); } }
- /// <summary>
- /// 出料动作
- /// </summary>
- [RelayCommand]
- private void OutMaterial()
- {
- ActionManage.GetInstance.Send("通道口出料", new object[] { MaterialID, OutMaterilWeight });
- }
- /// <summary>
- /// 开始矫正
- /// </summary>
- [RelayCommand]
- private void CheckPassway()
- {
-
- }
- /// <summary>
- /// 开启通道
- /// </summary>
- [RelayCommand]
- private void OpenPassway()
- {
-
- }
- /// <summary>
- /// 确认重量
- /// </summary>
- [RelayCommand]
- private void CheckMaterailWeight()
- {
-
- }
- #region 设备配置
-
- /// <summary>
- /// 店铺名称
- /// </summary>
- [ObservableProperty]
- private string? _shopName = string.Empty;
- /// <summary>
- /// 店铺ID
- /// </summary>
- [ObservableProperty]
- private string? _shopID = string.Empty;
- /// <summary>
- /// 设备ID
- /// </summary>
- [ObservableProperty]
- private string? _deviceID = string.Empty;
- /// <summary>
- /// PLC地址
- /// </summary>
- [ObservableProperty]
- private string? _pLCAdress = string.Empty;
-
- [ObservableProperty]
- private bool _isPort = true;
-
- [ObservableProperty]
- private Visibility _vsIP = Visibility.Hidden;
-
- [ObservableProperty]
- private Visibility _vsPort = Visibility.Visible;
-
- [ObservableProperty]
- private string[] _ports;
-
- [ObservableProperty]
- private string _prot;
-
- [RelayCommand]
- private void SaveDevices()
- {
- SaveDeviceMessage();
- }
- [RelayCommand]
- 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.GetInstance().GetDeviceConfigPath}MOC.json", JsonConvert.SerializeObject(GLobal.deviceConfig));
-
-
- }
-
-
- }
- }
|