using BPASmartClient.Model;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BPASmartClient.Peripheral
{
///
/// 外设基类
///
public abstract class BasePeripheral : IPeripheral
{
///
/// 是否已连接
///
public bool IsConnected { get; set; }
///
/// 是否工作正常
///
public bool IsWork { get; set; }
///
/// 归属设备Id
///
public int DeviceId { get; set; }
public CommunicationPar communicationPar { get; set; } = new CommunicationPar();
public ConcurrentDictionary status { get; set; } = new ConcurrentDictionary();
public ObservableCollection variables { get; set; } = new ObservableCollection();
public ConcurrentDictionary tempVar { get; set; } = new();
/// q
/// 外设状态集合
///
//protected ConcurrentDictionary status = new ConcurrentDictionary();
///
/// 初始化外设状态
///
protected abstract void InitStatus();
public object? GetStatus(string statusName)
{
if (status.ContainsKey(statusName))
return status[statusName];
return null;
}
public void SetStatus(string statusName, object value)
{
if (status.ContainsKey(statusName))
status[statusName] = value;
else
status.TryAdd(statusName, value);
}
public abstract void Start();
public abstract void Stop();
public abstract void Init();
//public abstract void ReadData(string address);
public abstract void WriteData(string address, object value);
//public abstract void AddVarInfo(string add, int len);
public ConcurrentDictionary GetAllStatus()
{
return status;
}
public ConcurrentDictionary GetVariable()
{
return tempVar;
}
}
}