STKMonitor.js 16.6 KB
layui.config({
    base: "/js/"
}).use(['layer', 'jquery'], function () {
    var layer = layui.layer,
        $ = layui.jquery

    //堆垛机监控属性
    var width = 50;
    var height = 20;
    var STKheight = 40;
    var X = 60;
    var Y = 30;
    var Y2 = Y + (height + STKheight);
    var list = [];

    //立库和堆垛机俯视图
    function GetSTK(stk) {
        STK = stk;
        $.ajax({
            async: false,
            url: "/monitor/STKMonitor/GetRow",
            type: "post",
            data: { Roadway: stk },
            dataType: "json",
            success: function (data) {
                list = [];
                arr = data.data;
                arr.forEach(function (e) {
                    $('#canvas' + stk).drawRect({
                        layer: true,
                        name: "L" + e.Roadway + "" + e.Row + "1",
                        strokeStyle: '#000',
                        strokeWidth: 1,
                        x: X + (width * (e.Row - 1)), y: Y,
                        width: width,
                        height: height,
                    })
                        .drawText({
                            layer: true,
                            name: "T" + e.Roadway + "" + e.Row + "1",
                            fillStyle: '#9cf',
                            strokeStyle: '#25a',
                            strokeWidth: 2,
                            x: X + (width * (e.Row - 1)), y: Y,
                            fontSize: 20,
                            fontFamily: 'Verdana, sans-serif',
                            text: e.Row
                        });
                    $('#canvas' + stk).drawRect({
                        layer: true,
                        name: "L" + e.Roadway + "" + e.Row + "2",
                        strokeStyle: '#000',
                        strokeWidth: 1,
                        x: X + (width * (e.Row - 1)), y: Y2,
                        width: width,
                        height: height,
                    })
                        .drawText({
                            layer: true,
                            name: "T" + e.Roadway + "" + e.Row + "2",
                            fillStyle: '#9cf',
                            strokeStyle: '#25a',
                            strokeWidth: 2,
                            x: X + (width * (e.Row - 1)), y: Y2,
                            fontSize: 20,
                            fontFamily: 'Verdana, sans-serif',
                            text: e.Row
                        });
                    list.push("L" + e.Roadway + "" + e.Row + "1");
                    list.push("L" + e.Roadway + "" + e.Row + "2");
                    list.push("T" + e.Roadway + "" + e.Row + "1");
                    list.push("T" + e.Roadway + "" + e.Row + "2");
                });

                //堆垛机
                $('#canvas' + stk).addLayer({
                    type: 'image',
                    name: 'STK' + stk,
                    source: "/images/STK.gif",
                    x: X + (width * (1 - 1)) - (width * 0.7), y: Y + height - (height * 0.4),
                    width: width + (width * 0.5),
                    height: STKheight * 0.8,
                    fromCenter: false
                })
            }
        });
    }

    var PPSTKMsg = "";
    var PJSTKMsg = "";
    var TBSTKMsg = "";
    var PPRGVMsg = "";
    var TBRGVMsg = "";

    //堆垛机移动 数据解析监控
    function STKMove(stk) {
        var road = Number(stk.SRM_NO) - Number(10);
        //铜箔堆垛机wcs的Y跟wms相反
        //if (road == 4) {
        //    stk.AxisY_NO = Number(27) - Number(stk.AxisY_NO);
        //}
        if (stk.Heart == 0 && road != 1) {
            $('#stk' + road).text('离线');
            $('#stk' + road).css('color', 'dimgray');
        } else {
            $('#canvas' + road).animateLayer('STK' + road, {
                x: X + (width * (stk.AxisY_NO - 1)) - (width * 0.7), y: Y + height - (height * 0.4),
            }, 500);

            $('#stk' + road + '_XYZ').text('Y:' + stk.AxisY_NO + ' Z:' + stk.AxisZ_NO + ";");
            $('#stk' + road + '_XYZ').css('color', 'blue');

            if (stk.Fork1_Task_Type == 0) {
                $('#stk' + road + '_Fork1_Task_Type').text('无任务;');
                $('#stk' + road + '_Fork1_Task_Type').css('color', 'green');
            } else if (stk.Fork1_Task_Type == 1) {
                $('#stk' + road + '_Fork1_Task_Type').text('单步行走;');
                $('#stk' + road + '_Fork1_Task_Type').css('color', 'orange');
            } else if (stk.Fork1_Task_Type == 2) {
                $('#stk' + road + '_Fork1_Task_Type').text('单步走取;');
                $('#stk' + road + '_Fork1_Task_Type').css('color', 'orange');
            } else if (stk.Fork1_Task_Type == 3) {
                $('#stk' + road + '_Fork1_Task_Type').text('单步走放;');
                $('#stk' + road + '_Fork1_Task_Type').css('color', 'orange');
            } else if (stk.Fork1_Task_Type == 4) {
                $('#stk' + road + '_Fork1_Task_Type').text('走取走放;');
                $('#stk' + road + '_Fork1_Task_Type').css('color', 'orange');
            }

            if (stk.SRM_Mode == 5) {
                $('#stk' + road + '_SRM_Mode').text('联机;');
                $('#stk' + road + '_SRM_Mode').css('color', 'green');
            } else if (stk.SRM_Mode == 1) {
                $('#stk' + road + '_SRM_Mode').text('维修;');
                $('#stk' + road + '_SRM_Mode').css('color', 'red');
            } else if (stk.SRM_Mode == 2) {
                $('#stk' + road + '_SRM_Mode').text('手动;');
                $('#stk' + road + '_SRM_Mode').css('color', 'red');
            } else if (stk.SRM_Mode == 3) {
                $('#stk' + road + '_SRM_Mode').text('机载操作;');
                $('#stk' + road + '_SRM_Mode').css('color', 'red');
            } else if (stk.SRM_Mode == 4) {
                $('#stk' + road + '_SRM_Mode').text('单机自动;');
                $('#stk' + road + '_SRM_Mode').css('color', 'red');
            }
            if (stk.SRM_Err == 0 && stk.Fork1_Err == 0) {
                $('#stk' + road + '_SRM_Err').text('无异常;');
                $('#stk' + road + '_SRM_Err').css('color', 'green');
                if (road == 2) {
                    PPSTKMsg = "";
                } else if (road == 3) {
                    PJSTKMsg = "";
                }
                else if (road == 4) {
                    TBSTKMsg = "";
                }
            } else {
                $('#stk' + road + '_SRM_Err').text('异常:' + stk.Error1 + ';');
                $('#stk' + road + '_SRM_Err').css('color', 'red');
                if (road == 2) {
                    PPSTKMsg = "PP卷堆垛机报错";
                } else if (road == 3) {
                    PJSTKMsg = "PP片堆垛机报错";
                }
                else if (road == 4) {
                    TBSTKMsg = "铜箔堆垛机报错";
                }
            }

            if (stk.Fork1_Goods == 0) {
                $('#stk' + road + '_Fork1_Goods').text('无货;' + ' 任务取:X(' + stk.Fork1_Pick_AxisX_NO + ')Y(' + stk.Fork1_Pick_AxisY_NO + ')Z(' + stk.Fork1_Pick_AxisZ_NO + ')' + ' 任务放:X(' + stk.Fork1_Release_AxisX_NO + ')Y(' + stk.Fork1_Release_AxisY_NO + ')Z(' + stk.Fork1_Release_AxisZ_NO + ')');
                $('#stk' + road + '_Fork1_Goods').css('color', 'green');
            } else {
                $('#stk' + road + '_Fork1_Goods').text('有货:' + stk.Fork1_Code + ';' + ' 任务取:X(' + stk.Fork1_Pick_AxisX_NO + ')Y(' + stk.Fork1_Pick_AxisY_NO + ')Z(' + stk.Fork1_Pick_AxisZ_NO + ')' + ' 任务放:X(' + stk.Fork1_Release_AxisX_NO + ')Y(' + stk.Fork1_Release_AxisY_NO + ')Z(' + stk.Fork1_Release_AxisZ_NO + ')');
                $('#stk' + road + '_Fork1_Goods').css('color', 'orange');
            }

            if (stk.Status_Port1 == 1) {
                $('#stk' + road + '_Status_Port1').text(' 站台: 201无货 ');
                $('#stk' + road + '_Status_Port1').css('color', 'green');
            } else {
                $('#stk' + road + '_Status_Port1').text(' 站台: 201有货 ');
                $('#stk' + road + '_Status_Port1').css('color', 'orange');
            }

            if (stk.Status_Port2 == 1) {
                $('#stk' + road + '_Status_Port2').text(' 202无货 ');
                $('#stk' + road + '_Status_Port2').css('color', 'green');
            } else {
                $('#stk' + road + '_Status_Port2').text(' 202有货 ');
                $('#stk' + road + '_Status_Port2').css('color', 'orange');
            }

            if (stk.Status_Port3 == 1) {
                $('#stk' + road + '_Status_Port3').text(' 203无货 ');
                $('#stk' + road + '_Status_Port3').css('color', 'green');
            } else {
                $('#stk' + road + '_Status_Port3').text(' 203有货 ');
                $('#stk' + road + '_Status_Port3').css('color', 'orange');
            }

            if (road != 1) {
                if (stk.Status_Port4 == 1) {
                    $('#stk' + road + '_Status_Port4').text(' 204无货 ');
                    $('#stk' + road + '_Status_Port4').css('color', 'green');
                } else {
                    $('#stk' + road + '_Status_Port4').text(' 204有货 ');
                    $('#stk' + road + '_Status_Port4').css('color', 'orange');
                }
            }

            if (road == 3 || road == 5 || road == 6) {
                if (stk.Status_Port5 == 1) {
                    $('#stk' + road + '_Status_Port5').text(' 205无货 ');
                    $('#stk' + road + '_Status_Port5').css('color', 'green');
                } else {
                    $('#stk' + road + '_Status_Port5').text(' 205有货 ');
                    $('#stk' + road + '_Status_Port5').css('color', 'orange');
                }
                if (stk.Status_Port6 == 1) {
                    $('#stk' + road + '_Status_Port6').text(' 206无货 ');
                    $('#stk' + road + '_Status_Port6').css('color', 'green');
                } else {
                    $('#stk' + road + '_Status_Port6').text(' 206有货 ');
                    $('#stk' + road + '_Status_Port6').css('color', 'orange');
                }
            }

            if (road == 5 || road == 6) {
                if (stk.Status_Port7 == 1) {
                    $('#stk' + road + '_Status_Port7').text(' 207无货 ');
                    $('#stk' + road + '_Status_Port7').css('color', 'green');
                } else {
                    $('#stk' + road + '_Status_Port7').text(' 207有货 ');
                    $('#stk' + road + '_Status_Port7').css('color', 'orange');
                }
                if (stk.Status_Port9 == 1) {
                    $('#stk' + road + '_Status_Port9').text(' 209无货 ');
                    $('#stk' + road + '_Status_Port9').css('color', 'green');
                } else {
                    $('#stk' + road + '_Status_Port9').text(' 209有货 ');
                    $('#stk' + road + '_Status_Port9').css('color', 'orange');
                }
            }
        }
    }

    //Rgv状态监控
    function RGVStatus(rgv) {
        var road = rgv.RGV_NO;
        if (road == 1) {
            road = Number(road) + Number(10);
        }
        if (rgv.Heart == 0) {
            $('#rgv' + road).text('离线');
            $('#rgv' + road).css('color', 'dimgray');
        } else {
            if (rgv.Fork1_Task_Type == 0) {
                $('#rgv' + road + '_Fork1_Task_Type').text('无任务;');
                $('#rgv' + road + '_Fork1_Task_Type').css('color', 'green');
            } else if (rgv.Fork1_Task_Type == 1) {
                $('#rgv' + road + '_Fork1_Task_Type').text('单步行走;');
                $('#rgv' + road + '_Fork1_Task_Type').css('color', 'orange');
            } else if (rgv.Fork1_Task_Type == 2) {
                $('#rgv' + road + '_Fork1_Task_Type').text('单步走取;');
                $('#rgv' + road + '_Fork1_Task_Type').css('color', 'orange');
            } else if (rgv.Fork1_Task_Type == 3) {
                $('#rgv' + road + '_Fork1_Task_Type').text('单步走放;');
                $('#rgv' + road + '_Fork1_Task_Type').css('color', 'orange');
            } else if (rgv.Fork1_Task_Type == 4) {
                $('#rgv' + road + '_Fork1_Task_Type').text('走取走放;');
                $('#rgv' + road + '_Fork1_Task_Type').css('color', 'orange');
            }

            if (rgv.RGV_Mode == 5) {
                $('#rgv' + road + '_RGV_Mode').text('联机;');
                $('#rgv' + road + '_RGV_Mode').css('color', 'green');
            } else if (rgv.RGV_Mode == 1) {
                $('#rgv' + road + '_RGV_Mode').text('维修;');
                $('#rgv' + road + '_RGV_Mode').css('color', 'red');
            } else if (rgv.RGV_Mode == 2) {
                $('#rgv' + road + '_RGV_Mode').text('手动;');
                $('#rgv' + road + '_RGV_Mode').css('color', 'red');
            } else if (rgv.RGV_Mode == 3) {
                $('#rgv' + road + '_RGV_Mode').text('机载操作;');
                $('#rgv' + road + '_RGV_Mode').css('color', 'red');
            } else if (rgv.RGV_Mode == 4) {
                $('#rgv' + road + '_RGV_Mode').text('单机自动;');
                $('#rgv' + road + '_RGV_Mode').css('color', 'red');
            }
            if (rgv.RGV_Err == 0 && rgv.Fork1_Err == 0) {
                $('#rgv' + road + '_RGV_Err').text('无异常;');
                $('#rgv' + road + '_RGV_Err').css('color', 'green');
                if (road == 13) {
                    PPRGVMsg = "";
                }
                else if (road == 14) {
                    TBRGVMsg = "";
                }
            } else {
                $('#rgv' + road + '_RGV_Err').text('异常:' + rgv.Error1 + ';');
                $('#rgv' + road + '_RGV_Err').css('color', 'red');
                if (road == 13) {
                    PPRGVMsg = "PP片RGV报错";
                }
                else if (road == 14) {
                    TBRGVMsg = "铜箔RGV报错";
                }
            }

            if (rgv.Fork1_Goods == 0) {
                $('#rgv' + road + '_Fork1_Goods').text('无货;' + rgv.Fork1_Code + ';' + ' 任务取:X(' + rgv.Fork1_Pick_AxisX_NO + ')Y(' + rgv.Fork1_Pick_AxisY_NO + ')Z(' + rgv.Fork1_Pick_AxisZ_NO + ')' + ' 任务放:X(' + rgv.Fork1_Release_AxisX_NO + ')Y(' + rgv.Fork1_Release_AxisY_NO + ')Z(' + rgv.Fork1_Release_AxisZ_NO + ')');
                $('#rgv' + road + '_Fork1_Goods').css('color', 'green');
            } else {
                $('#rgv' + road + '_Fork1_Goods').text('有货:' + rgv.Fork1_Code + ';' + ' 任务取:X(' + rgv.Fork1_Pick_AxisX_NO + ')Y(' + rgv.Fork1_Pick_AxisY_NO + ')Z(' + rgv.Fork1_Pick_AxisZ_NO + ')' + ' 任务放:X(' + rgv.Fork1_Release_AxisX_NO + ')Y(' + rgv.Fork1_Release_AxisY_NO + ')Z(' + rgv.Fork1_Release_AxisZ_NO + ')');
                $('#rgv' + road + '_Fork1_Goods').css('color', 'orange');
            }
        }
    }

    function PushLoad() {
        var connection = new signalR.HubConnectionBuilder()
            .withUrl("/ChartHub"
            )
            .build();
        connection.on("sendStkData", function (json) {
            json.forEach(function (j) {
                if (j.SRM_NO != 0) {
                    STKMove(j)
                }
            });
        });
        connection.start().then(function () {
        }).catch(function (err) {
            return console.error(err.toString());
        });

        var agvconnection = new signalR.HubConnectionBuilder()
            .withUrl("/ChartHub"
            )
            .build();
        agvconnection.on("sendAgvData", function (json) {
            json.forEach(function (j) {
                if (j.RGV_NO != 0) {
                    RGVStatus(j)
                }
            });
        });
        agvconnection.start().then(function () {
        }).catch(function (err) {
            return console.error(err.toString());
        });
    }

    function Speak() {
        var Msg = "";
        if (PPRGVMsg != "" || PPSTKMsg != "" || PJSTKMsg != "" || TBRGVMsg != "" || TBSTKMsg != "") {
            Msg = PPRGVMsg + PPSTKMsg + PJSTKMsg + TBRGVMsg + TBSTKMsg;
        }
        if (Msg != "") {
            let msg = new SpeechSynthesisUtterance("");
            msg.rate = 0.8// 播放语速
            //msg.pitch = 10 音调高低
            //msg.text = "播放文本"
            msg.volume = 1 //播放音量
            msg.text = Msg
            speechSynthesis.speak(msg);
        }
    }

    //初始加载
    $(document).ready(function () {
        for (var i = 1; i < 7; i++) {
            GetSTK(i);
        }
        PushLoad();
        setInterval(Speak,10000);
    });
});