获取药箱状态方法3次重试修改
This commit is contained in:
parent
c7d7a3b266
commit
e75f04beaf
|
@ -61,27 +61,56 @@ namespace DM_Weight.Port
|
||||||
|
|
||||||
public bool[] GetAllBoxState()
|
public bool[] GetAllBoxState()
|
||||||
{
|
{
|
||||||
//bool[] bools = { true };
|
//bool[] bools = Policy.Handle<Exception>()
|
||||||
//if (BoxOperate)
|
// .Retry(3, (exception, retryCount) =>
|
||||||
//{
|
// {
|
||||||
//if (ConfigurationManager.AppSettings["test"] != null && ConfigurationManager.AppSettings["test"].ToString() == "Y")
|
// this.Dispose();
|
||||||
//{
|
// //Debug.WriteLine($"获取所有箱子门状态出错,第{retryCount}次重试", exception);
|
||||||
// return new bool[] { false,false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
|
// logger.Info($"获取所有箱子门状态出错,第{retryCount}次重试, 异常信息{exception}");
|
||||||
//}
|
// Thread.Sleep(50);
|
||||||
bool[] bools = Policy.Handle<Exception>()
|
// this.SetModusIpMaster();
|
||||||
.Retry(3, (exception, retryCount) =>
|
// BoxOperate = false;
|
||||||
|
// // return TimeSpan.FromSeconds (1);
|
||||||
|
// }).Execute<bool[]>(() =>
|
||||||
|
// {
|
||||||
|
// bool[] flags = new bool[18];
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// if (master == null)
|
||||||
|
// {
|
||||||
|
// this.SetModusIpMaster();
|
||||||
|
// }
|
||||||
|
// var result = master.ReadInputRegisters(1, 0x0033, 2);
|
||||||
|
// var r1 = Convert.ToString(((int)result[0] >> 14) | ((int)result[1] << 2), 2).PadLeft(18, '0');
|
||||||
|
// var r2 = r1.ToCharArray();
|
||||||
|
// logger.Info("r2=>" + string.Join(", ", r2));
|
||||||
|
// //var r2=new char[18] { '0','0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };
|
||||||
|
// for (int i = 0; i < 18; i++)
|
||||||
|
// {
|
||||||
|
// flags[i] = r2[17 - i] == '1' ? true : false;
|
||||||
|
// }
|
||||||
|
// logger.Info($"获取所有箱子门状态返回:{string.Join(',', flags)};");
|
||||||
|
// }
|
||||||
|
// catch (Exception)
|
||||||
|
// {
|
||||||
|
// this.Dispose();
|
||||||
|
// //Debug.WriteLine($"获取所有箱子门状态出错,第{retryCount}次重试", exception);
|
||||||
|
// logger.Info($"获取所有箱子门状态出错,第{retryCount}次重试, 异常信息{exception}");
|
||||||
|
// Thread.Sleep(50);
|
||||||
|
// this.SetModusIpMaster();
|
||||||
|
// BoxOperate = false;
|
||||||
|
// }
|
||||||
|
// return flags;
|
||||||
|
// });
|
||||||
|
bool successFlag = true;
|
||||||
|
bool[] bools = new bool[18];
|
||||||
|
int iCount = 0;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
this.Dispose();
|
try
|
||||||
//Debug.WriteLine($"获取所有箱子门状态出错,第{retryCount}次重试", exception);
|
|
||||||
logger.Info($"获取所有箱子门状态出错,第{retryCount}次重试, 异常信息{exception}");
|
|
||||||
Thread.Sleep(50);
|
|
||||||
this.SetModusIpMaster();
|
|
||||||
BoxOperate = false;
|
|
||||||
// return TimeSpan.FromSeconds (1);
|
|
||||||
}).Execute<bool[]>(() =>
|
|
||||||
{
|
{
|
||||||
bool[] flags = new bool[18];
|
bool[] flags = new bool[18];
|
||||||
if(master==null)
|
if (master == null)
|
||||||
{
|
{
|
||||||
this.SetModusIpMaster();
|
this.SetModusIpMaster();
|
||||||
}
|
}
|
||||||
|
@ -92,27 +121,25 @@ namespace DM_Weight.Port
|
||||||
//var r2=new char[18] { '0','0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };
|
//var r2=new char[18] { '0','0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };
|
||||||
for (int i = 0; i < 18; i++)
|
for (int i = 0; i < 18; i++)
|
||||||
{
|
{
|
||||||
flags[i] = r2[17 - i] == '1' ? true : false;
|
bools[i] = r2[17 - i] == '1' ? true : false;
|
||||||
}
|
}
|
||||||
logger.Info($"获取所有箱子门状态返回:{string.Join(',', flags)};");
|
logger.Info($"获取所有箱子门状态返回:{string.Join(',', bools)};");
|
||||||
//bool allFalse = Array.TrueForAll(flags, b => b == false);
|
successFlag = true;
|
||||||
//if (!allFalse)
|
}
|
||||||
//{
|
catch (Exception exception)
|
||||||
// Task.Delay(500);
|
{
|
||||||
// Task.Factory.StartNew(async () =>
|
if (iCount >= 3)
|
||||||
// {
|
break;
|
||||||
// SpeakAsync("药箱已打开,请及时关闭");
|
iCount++;
|
||||||
// await Task.Delay(15000);
|
successFlag = false;
|
||||||
// });
|
this.Dispose();
|
||||||
//}
|
//Debug.WriteLine($"获取所有箱子门状态出错,第{retryCount}次重试", exception);
|
||||||
//else
|
logger.Info($"获取所有箱子门状态出错,第{iCount}次重试,异常信息{exception}");
|
||||||
//{
|
Thread.Sleep(500);
|
||||||
// BoxOperate = false;
|
this.SetModusIpMaster();
|
||||||
//}
|
BoxOperate = false;
|
||||||
|
}
|
||||||
return flags;
|
} while (!successFlag);
|
||||||
});
|
|
||||||
//}
|
|
||||||
return bools;
|
return bools;
|
||||||
}
|
}
|
||||||
public bool OpenBoxDoor(int boxNum)
|
public bool OpenBoxDoor(int boxNum)
|
||||||
|
@ -129,8 +156,8 @@ namespace DM_Weight.Port
|
||||||
this.Dispose();
|
this.Dispose();
|
||||||
//Debug.WriteLine($"打开箱子出错,第{retryCount}次重试", exception);
|
//Debug.WriteLine($"打开箱子出错,第{retryCount}次重试", exception);
|
||||||
logger.Info($"打开箱子出错,第{retryCount}次重试,异常信息{exception}");
|
logger.Info($"打开箱子出错,第{retryCount}次重试,异常信息{exception}");
|
||||||
SpeakAsync("打开药箱网中连接失败,正在尝试重新打开");
|
//SpeakAsync("药箱连接失败,正在尝试重新打开");
|
||||||
Thread.Sleep(50);
|
Thread.Sleep(500);
|
||||||
this.SetModusIpMaster();
|
this.SetModusIpMaster();
|
||||||
//return TimeSpan.FromSeconds (1);
|
//return TimeSpan.FromSeconds (1);
|
||||||
})).Execute(() =>
|
})).Execute(() =>
|
||||||
|
|
Loading…
Reference in New Issue