一、业务背景
MES项目实施过程中,尤其车间现场操作终端,车间本身嘈杂,操作工不是一直处在终端前,需要业务驱动声光报警设备,提示操作工,总结以下几个业务场景:
1.工单开工、暂停和完工需要提示现场操作人员;
2.工单提报异常需要提示现场操作人员;
3.工艺发生变更需要提示现场操作人员;
4.工单取消或者变更数量需要提示现场操作人员;
二、业务设计
基于以上需求,硬件设备通常选用USB声光报警塔灯,基于目前大部分B/S架构下的MES系统,如何让MES系统依据业务数据变化自动化调用报警灯,显示不同颜色以及报警声。
本方案通过设计一个基于操作终端windows系统WebAPI服务,MES系统根据业务调用对应WebAPI服务,API服务调用不同虚拟COM服务,需要参考USB报警灯SDK开发包,实现报警灯指定动作。
三、代码实现
WebAPI服务提供:
(1)报警灯连接服务
[Route("connect")]
[HttpGet]
public IHttpActionResult Connect(string com)
{
SerialPortUtils.OpenClosePort(com, 9600);
string name = "connect success";
return Ok(new { name });
}
(2)红色灯服务
[Route("red")]
[HttpGet]
public IHttpActionResult RedLight()
{
SerialPortUtils.OpenClosePort(SerialPortUtils.SerialPortName,9600);
SerialPortUtils.CloseGreen(false);
SerialPortUtils.CloseYellow(false);
byte[] sendata = new byte[2];
sendata[0] = 0x41;
sendata[1] = 0x10;
SerialPortUtils.SendData(sendata);
SerialPortUtils.OpenClosePort(SerialPortUtils.SerialPortName, 9600);
string result = "red light";
return Ok(new { result });
}
(2)绿色灯服务
[Route("green")]
[HttpGet]
public IHttpActionResult GreenLight()
{
SerialPortUtils.OpenClosePort(SerialPortUtils.SerialPortName, 9600);
SerialPortUtils.CloseRed(false);
SerialPortUtils.CloseYellow(false);
byte[] sendata = new byte[2];
sendata[0] = 0x44;
sendata[1] = 0x40;
SerialPortUtils.SendData(sendata);
SerialPortUtils.OpenClosePort(SerialPortUtils.SerialPortName, 9600);
string result = "green light";
return Ok(new { result });
}
(3)黄色灯服务
[Route("yellow")]
[HttpGet]
public IHttpActionResult YellowLight()
{
SerialPortUtils.OpenClosePort(SerialPortUtils.SerialPortName, 9600);
SerialPortUtils.CloseRed(false);
SerialPortUtils.CloseGreen(false);
byte[] sendata = new byte[1];
sendata[0] = 0x42;
SerialPortUtils.SendData(sendata);
SerialPortUtils.OpenClosePort(SerialPortUtils.SerialPortName, 9600);
string result = "yellow light";
return Ok(new { result });
}
(4)蜂鸣服务
[Route("bleep")]
[HttpGet]
public IHttpActionResult Bleep()
{
SerialPortUtils.OpenClosePort(SerialPortUtils.SerialPortName, 9600);
SerialPortUtils.CloseBleep(false);
byte[] sendata = new byte[2];
sendata[0] = 0x48;
sendata[1] = 0x3f;
SerialPortUtils.SendData(sendata);
System.Threading.Thread.Sleep(3000);
SerialPortUtils.CloseBleep(false);
SerialPortUtils.OpenClosePort(SerialPortUtils.SerialPortName, 9600);
string result = "bleep success";
return Ok(new { result });
}
四、用途价值
有效实现B/S架构下MES与OT层设备(激光打码机、声光报警、AGV、检测设备、行程执行器等)数据交互和控制,达到业务数据自动驱动设备执行的多种数字化应用场景。