1.增加配置ID等接口
2.长按取消 长按又挂起任务
This commit is contained in:
@ -48,7 +48,9 @@ namespace WCS.BLL.HardWare
|
||||
ModuleCode = module.ModuleCode,
|
||||
BoardId = module.BoardId,
|
||||
IsEnable = module.IsEnable,
|
||||
CurrentMode = TaskModeEnum.待机模式
|
||||
CurrentMode = TaskModeEnum.待机模式,
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
ModulesStr = string.Join(";", MXL4Modules.Select(t => t.ModuleCode));
|
||||
@ -64,42 +66,50 @@ namespace WCS.BLL.HardWare
|
||||
|
||||
while (true)
|
||||
{
|
||||
Logs.Write($"[test]{ShelfCode}");
|
||||
//Logs.Write($"[后台刷新线程]开始刷新{ShelfCode}");
|
||||
try
|
||||
{
|
||||
Logs.Write($"[test]{ShelfCode}1");
|
||||
await Task.Delay(100);
|
||||
//Logs.Write($"[后台刷新线程]开始刷新{ShelfCode}");
|
||||
if (TcpCleint == null)
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
continue;
|
||||
}
|
||||
Logs.Write($"[test]{ShelfCode}2");
|
||||
|
||||
//Logs.Write($"[后台刷新线程]TcpCleint =null {ShelfCode}");
|
||||
//未完成首次连接时 暂不发送
|
||||
if (TcpCleint.IsFirstConnected == false)
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
continue;
|
||||
}
|
||||
Logs.Write($"[test]{ShelfCode}3");
|
||||
// Logs.Write($"[test]{ShelfCode}3");
|
||||
//查询属于本货架的任务
|
||||
var currentShelfTasks = DbHelp.db.Queryable<CurrentTask>()
|
||||
.Where(t => t.ShelfId == this.ShelfId)
|
||||
.Where(t => t.IsSended == false)
|
||||
.Where(t => (t.IsSended == false && t.IsSuspended == false) || t.IsCancel == true || (t.IsSended == true && t.IsSuspended == true))
|
||||
.OrderBy(t => t.CreateTime)
|
||||
.ToList();
|
||||
|
||||
//Logs.Write($"[后台刷新线程]属于本货架的任务{currentShelfTasks.Count}");
|
||||
//获取因为任务需要刷新的module
|
||||
var haveTaskModules = currentShelfTasks.Select(t => t.ModuleId).Distinct().ToList();
|
||||
var haveTaskModules = currentShelfTasks.Where(t => t.IsCancel == true || (t.IsSended == false && t.IsSuspended == false))
|
||||
.Select(t => t.ModuleId)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
MXL4Modules.ForEach(t =>
|
||||
{
|
||||
if (haveTaskModules.Contains(t.ModuleId))
|
||||
{ t.IsNeedRefresh = true; }
|
||||
{
|
||||
t.IsNeedRefresh = true;
|
||||
}
|
||||
});
|
||||
|
||||
Logs.Write($"[test]{ShelfCode}4");
|
||||
// Logs.Write($"[test]{ShelfCode}4");
|
||||
//查询是否有需要刷新的
|
||||
var needRefreshModules = MXL4Modules.Where(t => t.IsNeedRefresh)
|
||||
.ToList();
|
||||
Logs.Write($"[test]{ShelfCode}5");
|
||||
foreach (var module in needRefreshModules)
|
||||
{
|
||||
try
|
||||
@ -108,7 +118,86 @@ namespace WCS.BLL.HardWare
|
||||
var currentTasks = currentShelfTasks.Where(t => t.ModuleId == module.ModuleId)
|
||||
.OrderBy(t => t.CreateTime)
|
||||
.ToList();
|
||||
Logs.Write($"[test]{ShelfCode}5.1");
|
||||
|
||||
//if (currentTasks == null || currentTasks.Count <= 0)
|
||||
//{
|
||||
// continue;
|
||||
//}
|
||||
|
||||
#region 取消任务的逻辑
|
||||
var cancelTasks = currentTasks.Where(t => t.IsCancel == true)
|
||||
.ToList();
|
||||
if (cancelTasks != null && cancelTasks.Count > 0)
|
||||
{
|
||||
Logs.Write($"[后台刷新线程]当前有任务需要取消!");
|
||||
//删除取消的这个任务
|
||||
DbHelp.db.Deleteable(cancelTasks).ExecuteCommand();
|
||||
currentShelfTasks.RemoveAll(t => t.IsCancel == true);
|
||||
|
||||
//退出当前模式
|
||||
if (module.CurrentMode != TaskModeEnum.待机模式)
|
||||
{
|
||||
Logs.Write($"当前模组不是待机模式 退出对应模式");
|
||||
// 退出对应模式
|
||||
switch (module.CurrentMode)
|
||||
{
|
||||
case (TaskModeEnum.入库模式):
|
||||
module.GoOutInstoreMode(TcpCleint);
|
||||
break;
|
||||
case (TaskModeEnum.出库模式):
|
||||
module.GoOutOutstoreMode(TcpCleint);
|
||||
break;
|
||||
case (TaskModeEnum.盘点模式):
|
||||
module.GoOutStocktakingMode(TcpCleint);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
await Task.Delay(10);
|
||||
}
|
||||
module.IsNeedRefresh = true;
|
||||
continue;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 挂起任务退出的逻辑
|
||||
var suspendedTasks = currentTasks.Where(t =>t.IsSended == true && t.IsSuspended == true)
|
||||
.FirstOrDefault();
|
||||
if (suspendedTasks != null)
|
||||
{
|
||||
Logs.Write("【挂起】任务,先退出当前模式,再重新发送所有任务内容!");
|
||||
//先退出当前模式
|
||||
if (module.CurrentMode != TaskModeEnum.待机模式)
|
||||
{
|
||||
Logs.Write($"【挂起】模组当前模式为{module.CurrentMode},先退出模式");
|
||||
switch (module.CurrentMode)
|
||||
{
|
||||
case (TaskModeEnum.入库模式):
|
||||
module.GoOutInstoreMode(TcpCleint);
|
||||
break;
|
||||
case (TaskModeEnum.出库模式):
|
||||
module.GoOutOutstoreMode(TcpCleint);
|
||||
break;
|
||||
case (TaskModeEnum.盘点模式):
|
||||
module.GoOutStocktakingMode(TcpCleint);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
await Task.Delay(10);
|
||||
|
||||
//将此字段更新为未发送
|
||||
suspendedTasks.IsSended = false;
|
||||
DbHelp.db.Updateable(suspendedTasks).ExecuteCommand();
|
||||
Logs.Write($"【挂起】模组当前模式为{module.CurrentMode},先退出模式1");
|
||||
}
|
||||
|
||||
module.IsNeedRefresh = true;
|
||||
continue;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
//入库、出库、盘点等任务
|
||||
if (currentTasks != null && currentTasks.Count > 0)
|
||||
{
|
||||
@ -202,8 +291,7 @@ namespace WCS.BLL.HardWare
|
||||
//不存在入库、出库、盘点等任务 应该变成待机
|
||||
else
|
||||
{
|
||||
Logs.Write($"[test]{ShelfCode}5.3");
|
||||
//退出对应模式到待机模式! 后续持续刷新数据!
|
||||
//退出对应模式到待机模式! 退出后续会再走这个else分支刷新数据!
|
||||
if (module.CurrentMode != TaskModeEnum.待机模式)
|
||||
{
|
||||
Logs.Write($"[test]{ShelfCode}5.4");
|
||||
@ -224,8 +312,25 @@ namespace WCS.BLL.HardWare
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
//模组是待机模式后 如果还有任务 那么显示对应的任务
|
||||
var otherTasks = DbHelp.db.Queryable<CurrentTask>()
|
||||
.Where(t => t.ModuleId == module.ModuleId && t.IsSended == true)
|
||||
.ToList();
|
||||
if (otherTasks != null && otherTasks.Count > 0)
|
||||
{
|
||||
Logs.Write($"[后台刷新线程]当前有任务需要重新发送!");
|
||||
otherTasks.ForEach(t => { t.IsSended = false; });
|
||||
DbHelp.db.Updateable(otherTasks).ExecuteCommand();
|
||||
|
||||
Logs.Write($"[test]{ShelfCode}5.5");
|
||||
Thread.Sleep(1000);
|
||||
Logs.Write($"[后台刷新线程]当前有任务{otherTasks.Count}个需要重新发送!");
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
#region 请求接口
|
||||
//向上层系统获取数据
|
||||
var stockQueryUrl = @"http://10.41.235.10:18989/ztwcs/stockQuery";
|
||||
var dataBody = new StockQueryRequest();
|
||||
@ -234,7 +339,7 @@ namespace WCS.BLL.HardWare
|
||||
var result = ApiHelp.GetDataFromHttp<StockQueryResponse>(stockQueryUrl, dataBody, "POST", true);
|
||||
if (result == null)
|
||||
{
|
||||
Logs.Write("2222", LogsType.StartBoot);
|
||||
//Logs.Write("2222", LogsType.StartBoot);
|
||||
continue;
|
||||
}
|
||||
//获取成功 有数据 绑定对应数据
|
||||
@ -256,8 +361,9 @@ namespace WCS.BLL.HardWare
|
||||
{
|
||||
data = data.Take(7).ToList();
|
||||
}
|
||||
|
||||
int taskid = 1;
|
||||
try
|
||||
{
|
||||
foreach (var item in data)
|
||||
{
|
||||
module.SendTaskId(taskid++, TcpCleint);
|
||||
@ -267,7 +373,13 @@ namespace WCS.BLL.HardWare
|
||||
module.SendMatBatch(item.batch_no, TcpCleint);
|
||||
module.SendMatQty((int)item.qty, TcpCleint);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
module.Reset(TcpCleint);
|
||||
}
|
||||
module.IsNeedRefresh = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
//库存里面无数据
|
||||
@ -277,28 +389,28 @@ namespace WCS.BLL.HardWare
|
||||
//获取成功 无数据
|
||||
module.StandbyNoInfoDisplay(TcpCleint);
|
||||
module.IsNeedRefresh = false;//未获取到库存数据 回没有库位显示信息给硬件
|
||||
//获取失败 跳过此次循环后继续获取
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Logs.Write($"6666", LogsType.StartBoot);
|
||||
Logs.Write($"66666", LogsType.StartBoot);
|
||||
//获取成功 无数据
|
||||
module.StandbyNoInfoDisplay(TcpCleint);
|
||||
module.IsNeedRefresh = false;//未获取到库存数据 回没有库位显示信息给硬件
|
||||
//获取失败 跳过此次循环后继续获取
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Logs.Write($"code!=200", LogsType.StartBoot);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -499,6 +611,8 @@ namespace WCS.BLL.HardWare
|
||||
case 0xA4://标签回到待机模式 请求获取显示数据的信号
|
||||
if (data[TcpCleint.PreFixLength + 3] == 0x02)
|
||||
GoBackStandbyModeReturnProcess(data, boardId);
|
||||
else if (data[TcpCleint.PreFixLength + 3] == 0x05)
|
||||
SelectSuspendTaskProcess(data, boardId);
|
||||
break;
|
||||
case 0xA1:
|
||||
//标签返回入库成功信号
|
||||
@ -510,6 +624,9 @@ namespace WCS.BLL.HardWare
|
||||
//退出入库模式
|
||||
else if (data[TcpCleint.PreFixLength + 3] == 0x03)
|
||||
GoBackStandbyModeReturnProcess(data, boardId);
|
||||
//挂载此出库任务
|
||||
else if (data[TcpCleint.PreFixLength + 3] == 0x04)
|
||||
SuspendTaskProcess(data, boardId);
|
||||
break;
|
||||
case 0xA2:
|
||||
//标签返回出库成功信号
|
||||
@ -560,6 +677,105 @@ namespace WCS.BLL.HardWare
|
||||
//TO DO 所有退出后货架才待机
|
||||
SetCurrentMode(TaskModeEnum.待机模式);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 挂起任务
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
public async void SuspendTaskProcess(byte[] data, int boardId)
|
||||
{
|
||||
//获取当前挂载任务
|
||||
var taskSuspended = DbHelp.db.Queryable<CurrentTask>()
|
||||
.Where(t => t.IsSuspended)
|
||||
.First();
|
||||
if (taskSuspended != null)
|
||||
{
|
||||
Logs.Write($"【挂起任务】已有挂起任务 货架【{taskSuspended.ShelfCode}】模组{taskSuspended.ModuleCode},任务ID{taskSuspended.TaskID},在数据库中!无法挂起第二个");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logs.Write($"【挂起任务】当前没有挂起任务,可以进行任务挂起");
|
||||
}
|
||||
|
||||
//获取对应的模组
|
||||
var module = MXL4Modules.Where(t => t.BoardId == boardId)
|
||||
.FirstOrDefault();
|
||||
if (module != null)
|
||||
{
|
||||
Logs.Write($"【挂起任务】获取到当前进行挂起任务的模组{module.ModuleCode},货架{ShelfCode}");
|
||||
//获取对应任务
|
||||
var taskId = Convert.ToInt32(data[TcpCleint.PreFixLength + 4]);//任务ID
|
||||
Logs.Write($"【挂起任务】获取到当前进行挂起任务的模组{module.ModuleCode},货架{ShelfCode},任务ID{taskId}");
|
||||
var task = DbHelp.db.Queryable<CurrentTask>()
|
||||
.Where(t => t.TaskID == taskId && t.ModuleId == module.ModuleId)
|
||||
.First();
|
||||
if (task != null)
|
||||
{
|
||||
Logs.Write($"【挂起任务】task != null");
|
||||
task.IsSuspended = true;
|
||||
DbHelp.db.Updateable(task).ExecuteCommand();
|
||||
|
||||
await Task.Delay(15);
|
||||
module.IsNeedRefresh = true;
|
||||
Logs.Write($"【挂起任务】模组{module.ModuleCode}已更新为需要刷新!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logs.Write($"【挂起任务】货架【{ShelfCode}】模组{module.ModuleCode},任务ID{taskId},在数据库中未找到对应任务!");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Logs.Write($"【挂起任务】货架【{ShelfCode}】通过板子ID【{boardId}】未找到对应模组!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择挂起任务 挂载至另一个模组
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
public void SelectSuspendTaskProcess(byte[] data, int boardId)
|
||||
{
|
||||
Logs.Write("[选择挂起任务]接收到相关指令!");
|
||||
//获取对应的模组
|
||||
var module = MXL4Modules.Where(t => t.BoardId == boardId)
|
||||
.FirstOrDefault();
|
||||
if (module != null)
|
||||
{
|
||||
Logs.Write($"[选择挂起任务]接收到相关指令!货架{ShelfCode},模组{module.ModuleCode}");
|
||||
//获取当前挂载任务
|
||||
var task = DbHelp.db.Queryable<CurrentTask>()
|
||||
.Where(t => t.IsSuspended)
|
||||
.First();
|
||||
if (task != null)
|
||||
{
|
||||
task.IsSuspended = false;
|
||||
task.ShelfId = ShelfId;
|
||||
task.ModuleId = module.ModuleId;
|
||||
task.ModuleCode = module.ModuleCode;
|
||||
task.IsSuspended = false;
|
||||
task.IsSended = false;
|
||||
|
||||
DbHelp.db.Updateable(task).ExecuteCommand();
|
||||
|
||||
Thread.Sleep(30);
|
||||
module.IsNeedRefresh = true;
|
||||
Logs.Write($"[选择挂起任务]已获取到相关任务,任务已更新为当前模组");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logs.Write($"【选择挂起任务】货架【{ShelfCode}】模组{module.ModuleCode},在数据库中未找到当前挂起的任务!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logs.Write($"【选择挂起任务】货架【{ShelfCode}】通过板子ID【{boardId}】未找到对应模组!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标签返回进入入库模式信号
|
||||
/// </summary>
|
||||
|
@ -104,7 +104,15 @@ namespace WCS.BLL.HardWare
|
||||
/// <param name="tcpClient"></param>
|
||||
public void Reset(TCPClient tcpClient)
|
||||
{
|
||||
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, ResetData));
|
||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, ResetData));
|
||||
|
||||
Task.Run(() => {
|
||||
if (!IsNeedRefresh)
|
||||
{
|
||||
Thread.Sleep(2000);
|
||||
IsNeedRefresh = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void StandbyNoInfoDisplay(TCPClient tcpClient)
|
||||
|
@ -117,10 +117,29 @@ namespace WCS.BLL.Services.Service
|
||||
//生成任务数据
|
||||
foreach (var orderDetail in request.List)
|
||||
{
|
||||
var taskId = list.First();
|
||||
list.RemoveAll(l => l == taskId);
|
||||
|
||||
list = new List<int> { 1, 2, 3, 4, 5, 6, 7,8 };
|
||||
var module = moduleInfo.Where(t => t.ModuleCode == orderDetail.StoreCode).First();
|
||||
|
||||
var currentTaskIds = DbHelp.db.Queryable<CurrentTask>()
|
||||
.Where(t => t.ModuleId == module.Id)
|
||||
.Select(t => t.TaskID)
|
||||
.ToList();
|
||||
var tasksIds = tasks.Where(t => t.ModuleId == module.Id).Select(t => t.TaskID).ToList();
|
||||
|
||||
list.RemoveAll(l =>currentTaskIds.Contains(l));
|
||||
list.RemoveAll(l => tasksIds.Contains(l));
|
||||
|
||||
if (list == null || list.Count <= 0)
|
||||
{
|
||||
return new ResponseCommon<object>
|
||||
{
|
||||
Code = 201,
|
||||
Message = $"操作失败:同一个库位同时只能同时操作八种物料!"
|
||||
};
|
||||
}
|
||||
|
||||
var taskId = list.First();
|
||||
|
||||
var task = new CurrentTask()
|
||||
{
|
||||
ModuleId = module.Id,
|
||||
@ -138,7 +157,7 @@ namespace WCS.BLL.Services.Service
|
||||
MatSpec = string.IsNullOrEmpty(orderDetail.MatSpec) ? "-" : orderDetail.MatSpec,
|
||||
MatBatch = orderDetail.MatBatch,
|
||||
MatSN = orderDetail.MatSN,
|
||||
Qty = orderDetail.Qty
|
||||
Qty = (int)orderDetail.Qty
|
||||
};
|
||||
tasks.Add(task);
|
||||
}
|
||||
|
12
WCS.Model/ApiModel/Home/SetBoardIdRequest.cs
Normal file
12
WCS.Model/ApiModel/Home/SetBoardIdRequest.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WCS.Model.ApiModel.Home
|
||||
{
|
||||
public class SetBoardIdRequest
|
||||
{
|
||||
public string IPPort { get; set; }
|
||||
public int StartId { get; set; }
|
||||
}
|
||||
}
|
@ -79,6 +79,6 @@ namespace WCS.Model.ApiModel.MXL4
|
||||
/// <summary>
|
||||
/// 数量
|
||||
/// </summary>
|
||||
public int Qty { get; set; }
|
||||
public decimal Qty { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ namespace WCS.WebApi.Controllers
|
||||
ShelfTypeId = 3,
|
||||
ShelfId = shelfInfo.Id,
|
||||
ShelfCode = shelfInfo.ShelfCode,
|
||||
BoardId = boardId ++,
|
||||
BoardId = boardId++,
|
||||
LightCount = 1,
|
||||
CleintIp = shelfInfo.ClientIp,
|
||||
GroupName = shelfInfo.GroupName,
|
||||
@ -380,5 +380,249 @@ namespace WCS.WebApi.Controllers
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 进入调试模式
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[Route("goInDebugMode")]
|
||||
[HttpPost(Name = "goInDebugMode")]
|
||||
public async Task<ResponseBase> goInDebugMode(SetBoardIdRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
//获取TCP
|
||||
var client = TCPClientManager.TCPClients
|
||||
.Where(t => t.RemoteIPHost == request.IPPort)
|
||||
.First();
|
||||
if (client == null)
|
||||
{
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 300,
|
||||
Message = "未获取到对应连接,请检查地址",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
//进入调试模式
|
||||
byte[] data = { 0x08, 0x00, 0x00, 0x07, 0xFF, 0xDB, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
client.Send(data);
|
||||
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 200,
|
||||
Message = "指令发送成功",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 300,
|
||||
Message = "指令发送失败" + ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Route("goOutDebugMode")]
|
||||
[HttpPost(Name = "goOutDebugMode")]
|
||||
public async Task<ResponseBase> goOutDebugMode(SetBoardIdRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
//获取TCP
|
||||
var client = TCPClientManager.TCPClients
|
||||
.Where(t => t.RemoteIPHost == request.IPPort)
|
||||
.First();
|
||||
if (client == null)
|
||||
{
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 300,
|
||||
Message = "未获取到对应连接,请检查地址",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
//退出调试模式
|
||||
byte[] data = { 0x08, 0x00, 0x00, 0x07, 0xFF, 0xDB, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
client.Send(data);
|
||||
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 200,
|
||||
Message = "指令发送成功",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 300,
|
||||
Message = "指令发送失败" + ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Route("setId")]
|
||||
[HttpPost(Name = "setId")]
|
||||
public async Task<ResponseBase> setId(SetBoardIdRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
//获取TCP
|
||||
var client = TCPClientManager.TCPClients
|
||||
.Where(t => t.RemoteIPHost == request.IPPort)
|
||||
.First();
|
||||
if (client == null)
|
||||
{
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 300,
|
||||
Message = "未获取到对应连接,请检查地址",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
//退出调试模式
|
||||
byte[] data = { 0x08, 0x00, 0x00, 0x07, 0xFF, 0xDB, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
client.Send(data);
|
||||
|
||||
var boardId = request.StartId;
|
||||
var boardIdData = BitConverter.GetBytes(unchecked((short)boardId));
|
||||
// 检查是否需要交换字节
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
// 如果是小端序系统,则交换字节
|
||||
byte temp = boardIdData[0];
|
||||
boardIdData[0] = boardIdData[1];
|
||||
boardIdData[1] = temp;
|
||||
}
|
||||
|
||||
Thread.Sleep(3000);
|
||||
byte[] data1 = { 0x08, 0x00, 0x00, 0x07, 0xFF, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
data1[6] = boardIdData[0];
|
||||
data1[7] = boardIdData[1];
|
||||
|
||||
client.Send(data1);
|
||||
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 200,
|
||||
Message = "指令发送成功",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 300,
|
||||
Message = "指令发送失败" + ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Route("setLight")]
|
||||
[HttpPost(Name = "setLight")]
|
||||
public async Task<ResponseBase> setLight(SetBoardIdRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
//获取TCP
|
||||
var client = TCPClientManager.TCPClients
|
||||
.Where(t => t.RemoteIPHost == request.IPPort)
|
||||
.First();
|
||||
if (client == null)
|
||||
{
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 300,
|
||||
Message = "未获取到对应连接,请检查地址",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
var boardId = request.StartId;
|
||||
var boardIdData = BitConverter.GetBytes(unchecked((short)boardId));
|
||||
// 检查是否需要交换字节
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
// 如果是小端序系统,则交换字节
|
||||
byte temp = boardIdData[0];
|
||||
boardIdData[0] = boardIdData[1];
|
||||
boardIdData[1] = temp;
|
||||
}
|
||||
byte[] data1 = { 0x08, 0x00, 0x00, 0x07, 0xFF, 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
data1[7] = boardIdData[0];
|
||||
data1[8] = boardIdData[1];
|
||||
|
||||
client.Send(data1);
|
||||
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 200,
|
||||
Message = "指令发送成功",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 300,
|
||||
Message = "指令发送失败" + ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Route("resetByTCP")]
|
||||
[HttpPost(Name = "resetByTCP")]
|
||||
public async Task<ResponseBase> resetByTCP(SetBoardIdRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
//获取TCP
|
||||
var client = TCPClientManager.TCPClients
|
||||
.Where(t => t.RemoteIPHost == request.IPPort)
|
||||
.First();
|
||||
if (client == null)
|
||||
{
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 300,
|
||||
Message = "未获取到对应连接,请检查地址",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
byte[] data = { 0x08, 0x00, 0x00, 0x07, 0xFF, 0xBE, 0x52, 0x54, 0x41, 0x52, 0x54, 0x0A, 0xED };
|
||||
client.Send(data);
|
||||
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 200,
|
||||
Message = "指令发送成功",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ResponseBase<object>()
|
||||
{
|
||||
Code = 300,
|
||||
Message = "指令发送失败" + ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user