Commit 60bd1e2b 张东亮

1

1 个父辈 738ee324
...@@ -19,7 +19,7 @@ namespace DeviceLibrary ...@@ -19,7 +19,7 @@ namespace DeviceLibrary
public static bool IsLoadOk = true; public static bool IsLoadOk = true;
public static bool IsConfigMode = false; public static bool IsConfigMode = false;
public static bool InoutDebugMode = false; public static bool InoutDebugMode = false;
public delegate void LoadFinish(bool state,string msg); public delegate void LoadFinish(bool state, string msg);
public static event LoadFinish LoadFinishEvent; public static event LoadFinish LoadFinishEvent;
public static event EventHandler<bool> UserPauseSet; public static event EventHandler<bool> UserPauseSet;
...@@ -31,20 +31,27 @@ namespace DeviceLibrary ...@@ -31,20 +31,27 @@ namespace DeviceLibrary
public static List<HumitureController> humitureControllers = new List<HumitureController>(); public static List<HumitureController> humitureControllers = new List<HumitureController>();
public static double averageHumidity() public static double averageHumidity()
{ {
return humitureControllers.FindAll(s => s.LastData.Humidity > 0).Average(x => x.LastData.Humidity); var ss = humitureControllers.FindAll(s => s.LastData.Humidity > 0);
if (ss != null && ss.Count > 0)
return ss.Average(x => x.LastData.Humidity);
return 0;
} }
public static double averageTemp() public static double averageTemp()
{ {
return humitureControllers.FindAll(s => s.LastData.Temperate > 0).Average(x => x.LastData.Temperate); var ss = humitureControllers.FindAll(s => s.LastData.Temperate > 0);
if (ss != null && ss.Count > 0)
return ss.Average(x => x.LastData.Temperate);
return 0;
} }
public static HIKCamera CameraA=new HIKCamera(); public static HIKCamera CameraA = new HIKCamera();
public static HIKCamera CameraB= new HIKCamera(); public static HIKCamera CameraB = new HIKCamera();
public static void Init() { public static void Init()
{
string msg = ""; string msg = "";
try try
{ {
mainMachine = null; mainMachine = null;
string configFile = Path.Combine(baseDir, "config\\Config.csv"); string configFile = Path.Combine(baseDir, "config\\Config.csv");
Config = new Robot_Config(0, "", configFile); Config = new Robot_Config(0, "", configFile);
Config = (Robot_Config)CSVConfigReader.LoadConfig(Config); Config = (Robot_Config)CSVConfigReader.LoadConfig(Config);
...@@ -56,7 +63,8 @@ namespace DeviceLibrary ...@@ -56,7 +63,8 @@ namespace DeviceLibrary
LogUtil.info("加载位置文件:" + positionConfigFile); LogUtil.info("加载位置文件:" + positionConfigFile);
CSVPositionReader<ACStorePosition>.ReloadCSVFile(positionConfigFile); CSVPositionReader<ACStorePosition>.ReloadCSVFile(positionConfigFile);
} }
else { else
{
IsLoadOk = false; IsLoadOk = false;
msg += "找不到库位配置文件\n"; msg += "找不到库位配置文件\n";
} }
...@@ -70,16 +78,17 @@ namespace DeviceLibrary ...@@ -70,16 +78,17 @@ namespace DeviceLibrary
msg += "IO板卡初始化失败\n"; msg += "IO板卡初始化失败\n";
} }
var hports = Setting_Init.Device_Humiture_Port.Val.Split(','); var hports = Setting_Init.Device_Humiture_Port.Val.Split(',');
foreach(var p in hports) foreach (var p in hports)
{ {
var hc = new HumitureController(); var hc = new HumitureController();
if (!hc.Init(p)) if (!hc.Init(p))
{ {
LogUtil.info("尝试打开端口:" + p+" 失败"); LogUtil.info("尝试打开端口:" + p + " 失败");
IsLoadOk = false; IsLoadOk = false;
msg += "温湿度传感器初始化失败,端口:" + $"{p}\n"; msg += "温湿度传感器初始化失败,端口:" + $"{p}\n";
} }
else { else
{
LogUtil.info("尝试打开端口:" + p + " 成功"); LogUtil.info("尝试打开端口:" + p + " 成功");
humitureControllers.Add(hc); humitureControllers.Add(hc);
} }
...@@ -102,22 +111,25 @@ namespace DeviceLibrary ...@@ -102,22 +111,25 @@ namespace DeviceLibrary
if (!CameraB.LoadCameraConfig("CameraB", out errmsg)) if (!CameraB.LoadCameraConfig("CameraB", out errmsg))
{ {
//IsLoadOk = false; //IsLoadOk = false;
msg += errmsg+"\r\n"; msg += errmsg + "\r\n";
} }
//IOManager.IOMove(IO_Type.Device_Led, IO_VALUE.HIGH); //IOManager.IOMove(IO_Type.Device_Led, IO_VALUE.HIGH);
//IOManager.IOMove(IO_Type.Camera_Led, IO_VALUE.HIGH); //IOManager.IOMove(IO_Type.Camera_Led, IO_VALUE.HIGH);
LoadFinishEvent?.Invoke(IsConfigMode ? IsConfigMode : IsLoadOk, msg); LoadFinishEvent?.Invoke(IsConfigMode ? IsConfigMode : IsLoadOk, msg);
} }
catch (Exception ex) { catch (Exception ex)
{
LoadFinishEvent?.Invoke(false, ex.Message); LoadFinishEvent?.Invoke(false, ex.Message);
LogUtil.error(ex.Message+ex.StackTrace); LogUtil.error(ex.Message + ex.StackTrace);
return; return;
} }
} }
public static void LoadDebug() { public static void LoadDebug()
{
LoadFinishEvent?.Invoke(true, "打开调试模式"); LoadFinishEvent?.Invoke(true, "打开调试模式");
} }
public static void Start() { public static void Start()
{
//Init(); //Init();
if (!IsLoadOk) if (!IsLoadOk)
{ {
...@@ -130,20 +142,21 @@ namespace DeviceLibrary ...@@ -130,20 +142,21 @@ namespace DeviceLibrary
isRunning = true; isRunning = true;
GC.KeepAlive(mainThread); GC.KeepAlive(mainThread);
Task.Run(()=> { Task.Run(() =>
{
AxisBean.List.ForEach((x) => { AxisManager.AlarmClear(x.Config.DeviceName, x.Config.GetAxisValue()); }); AxisBean.List.ForEach((x) => { AxisManager.AlarmClear(x.Config.DeviceName, x.Config.GetAxisValue()); });
Task.Delay(1000).Wait(); Task.Delay(1000).Wait();
if (mainMachine.DeviceCheck()) if (mainMachine.DeviceCheck())
mainMachine.BeginHomeReset(true); mainMachine.BeginHomeReset(true);
}); });
} }
public static void Stop() public static void Stop()
{ {
LogUtil.info("开始停止系统."); LogUtil.info("开始停止系统.");
mainMachine.Stop(); mainMachine.Stop();
mainMachine.UserPause = false; mainMachine.UserPause = false;
//IOManager.CloseAllConnection(); //IOManager.CloseAllConnection();
...@@ -160,14 +173,15 @@ namespace DeviceLibrary ...@@ -160,14 +173,15 @@ namespace DeviceLibrary
} }
public static void UserPause(bool userpause) public static void UserPause(bool userpause)
{ {
UserPause("", userpause,false); UserPause("", userpause, false);
} }
public static void UserPause(string msg="",bool userpause=true,bool upload=true) { public static void UserPause(string msg = "", bool userpause = true, bool upload = true)
{
if (userpause) if (userpause)
{ {
if(string.IsNullOrEmpty(msg)) if (string.IsNullOrEmpty(msg))
{ {
if(upload) if (upload)
{ {
Msg.add("用户暂停", MsgLevel.critical); Msg.add("用户暂停", MsgLevel.critical);
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!