hwh
2024-09-03 2acb2076869b884c69c349e0821ed96c2bc5b9ee
工作台位置监控
6个文件已修改
269 ■■■■ 已修改文件
Admin.NET/WCS.Application/Entity/WcsDevice.cs 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Admin.NET/WCS.Application/Hub/IPlcHub.cs 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Admin.NET/WCS.Application/PLC/PLCTaskAction.cs 104 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Admin.NET/WCS.Application/Service/WcsPlc/WcsPlcService.cs 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Web/src/api/wcs/wcsPlc.ts 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Web/src/views/device/deviceInfo/index.vue 102 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Admin.NET/WCS.Application/Entity/WcsDevice.cs
@@ -4,8 +4,8 @@
/// <summary>
/// 设备信息表
/// </summary>
[SugarTable("WCSPLCDevice","设备信息表")]
public class WcsDevice  : EntityBaseData
[SugarTable("WCSPLCDevice", "设备信息表")]
public class WcsDevice : EntityBaseData
{
    /// <summary>
    /// PlcId
@@ -62,17 +62,27 @@
    [Required]
    [SugarColumn(ColumnName = "PosType", ColumnDescription = "流程字类型")]
    public PLCDataTypeEnum PosType { get; set; }
    /// <summary>
    /// 显示屏ip地址
    /// </summary>
    [SugarColumn(ColumnName = "LedIP", ColumnDescription = "显示屏ip地址", Length = 50)]
    public string? LedIP { get; set; }
    /// <summary>
    /// 描述
    /// </summary>
    [SugarColumn(ColumnName = "Text", ColumnDescription = "描述", Length = 20)]
    public string? Text { get; set; }
    /// <summary>
    /// 位置有物品
    /// </summary>
    [SugarColumn(IsIgnore = true)]
    public bool BoHaveItem { get; set; }
    /// <summary>
    /// 高度
    /// </summary>
    [SugarColumn(IsIgnore = true)]
    public int BoxHeight { get; set; }
}
Admin.NET/WCS.Application/Hub/IPlcHub.cs
@@ -33,5 +33,19 @@
        /// </summary>
        /// <param name="context"></param>
        Task UpdateService(PLCServiceModel context);
        /// <summary>
        /// 下发控制台位置信息
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        Task PublicPosition(PlcPositionInfo context);
    }
    public class PlcPositionInfo
    {
        public string StationNum { get; set; }
        public bool BoHaveItem { get; set; }
        public PLCTypeEnum Type { get; set; }
        public int BoxHeight { get; set; }
    }
}
Admin.NET/WCS.Application/PLC/PLCTaskAction.cs
@@ -13,6 +13,8 @@
    //自刷新
    public static bool boRefresh = false;
    public static List<PlcPositionInfo> listPositionInfo = new List<PlcPositionInfo>();
    private static readonly ISqlSugarClient _db = SqlSugarSetup.ITenant.GetConnectionScope(SqlSugarConst.MainConfigId);
    private static readonly SysCacheService sysCacheService = App.GetRequiredService<SysCacheService>();
    private static readonly IHubContext<PlcHub, IPlcHub> _plcHubContext = App.GetService<IHubContext<PlcHub, IPlcHub>>();
@@ -65,6 +67,7 @@
        StartRead();
        ConnectionStatus();
        StartWatchAlarm();
        StartWatchPosition();
    }
    /// <summary>
    /// 开启读取plc线程
@@ -232,11 +235,11 @@
                    var listAlarm = listAlarmInfo.Where(s => s.PlcIP == modUtil.PlcId.ToString());
                    foreach (var modAlarm in listAlarm)
                    {
                        (var result, var value) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, modAlarm.AlarmCode, "");
                        (var result, var value) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Bit, modAlarm.AlarmCode, "");
                        if (result.IsSucceed)
                        {
                            //假设不为0就算报警
                            if (value != 0)
                            if (Convert.ToBoolean(value) && modAlarm.Status == YesNoEnum.N)
                            {
                                //修改报警状态同时记录报警日志
                                modAlarm.AlarmTime = DateTime.Now;
@@ -248,7 +251,7 @@
                                _plcHubContext.Clients.All.PublicAlarm(modAlarm.Adapt<WcsAlarmInfoOutput>());
                            }
                            //取消报警
                            else if (modAlarm.Status == YesNoEnum.Y)
                            else if (Convert.ToBoolean(value) && modAlarm.Status == YesNoEnum.Y)
                            {
                                modAlarm.AlarmTime = null;
                                modAlarm.Status = YesNoEnum.N;
@@ -263,6 +266,101 @@
        }, cts.Token);
    }
    /// <summary>
    /// 开启位置监控
    /// </summary>
    public static void StartWatchPosition()
    {
        Task.Run(() =>
        {
            while (true)
            {
                //取消线程 关闭PLC连接
                if (cts.Token.IsCancellationRequested)
                {
                    foreach (var modPlcUtil in listPlcUtil)
                    {
                        if (modPlcUtil != null && modPlcUtil.Connected)
                            modPlcUtil.Close();
                    }
                    break;
                    //throw new OperationCanceledException();
                }
                try
                {
                    foreach (var modPlcUtil in listPlcUtil)
                    {
                        if (modPlcUtil == null)
                            break;
                        var listDevice = listPlcDevice.Where(s => s.PlcId == modPlcUtil.PlcId && s.DeviceType == DeviceTypeEnum.Show).ToList();
                        foreach (var modDevice in listDevice)
                        {
                            var modPlc = listPlc.FirstOrDefault(s => s.Id == modDevice.PlcId);
                            (var result, var value) = modPlcUtil.GetPlcDBValue(modDevice.PosType, modDevice.DbNumber, modDevice.PlcPos);
                            if (result.IsSucceed)
                            {
                                if (modPlc.Type == PLCTypeEnum.ConveyorLine)
                                {
                                    //假设不为0就算有东西
                                    if (value != 0 && !modDevice.BoHaveItem)
                                    {
                                        modDevice.BoHaveItem = true;
                                        //下发状态
                                        var modInfo = new PlcPositionInfo() { StationNum = modDevice.StationNum, BoHaveItem = true };
                                        _plcHubContext.Clients.All.PublicPosition(modInfo);
                                        UpdatePosition(modInfo);
                                    }
                                    else if (value == 0 && modDevice.BoHaveItem)
                                    {
                                        modDevice.BoHaveItem = false;
                                        //下发状态
                                        var modInfo = new PlcPositionInfo()
                                        {
                                            StationNum = modDevice.StationNum,
                                            BoHaveItem = false,
                                            Type = modPlc.Type,
                                        };
                                        _plcHubContext.Clients.All.PublicPosition(modInfo);
                                        UpdatePosition(modInfo);
                                    }
                                }
                                else if (modPlc.Type == PLCTypeEnum.StackingMachine)
                                {
                                    //todo:这里的高度可能需要前端展示值和plc的值进行一个换算
                                    var BoxHeight = Convert.ToInt32(value);
                                    if (value != 0 && modDevice.BoxHeight != BoxHeight)
                                    {
                                        modDevice.BoxHeight = BoxHeight;
                                        //下发状态
                                        var modInfo = new PlcPositionInfo() { StationNum = modDevice.StationNum, BoxHeight = BoxHeight };
                                        _plcHubContext.Clients.All.PublicPosition(modInfo);
                                        UpdatePosition(modInfo);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        });
    }
    private static void UpdatePosition(PlcPositionInfo modInfo)
    {
        var modTemp = listPositionInfo.FirstOrDefault(s => s.StationNum == modInfo.StationNum);
        if (modTemp == null)
        {
            listPositionInfo.Add(modInfo);
        }
        else
        {
            modTemp.BoHaveItem = modInfo.BoHaveItem;
        }
    }
    /// <summary>
    /// 停止服务
    /// </summary>
    public static void Stop()
Admin.NET/WCS.Application/Service/WcsPlc/WcsPlcService.cs
@@ -138,5 +138,25 @@
        var modService = new { PLCTaskAction.boRunningState, PLCTaskAction.boOffline, PLCTaskAction.boRefresh };
        return new { listPlc, modService };
    }
    /// <summary>
    /// 获取位置上有没有东西
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "ListPosition")]
    [DisplayName("获取位置上有没有东西")]
    public List<PlcPositionInfo> ListPosition()
    {
        //测试用
        //return new List<PlcPositionInfo>()
        //{
        //    new PlcPositionInfo(){ Type=PLCTypeEnum.ConveyorLine, StationNum="147", BoHaveItem=true },
        //    new PlcPositionInfo(){ Type=PLCTypeEnum.ConveyorLine, StationNum="143", BoHaveItem=true },
        //    new PlcPositionInfo(){ Type=PLCTypeEnum.StackingMachine, StationNum="002", BoxHeight=30 },
        //};
        var list = PLCTaskAction.listPositionInfo.ToList();
        return list;
    }
}
Web/src/api/wcs/wcsPlc.ts
@@ -5,7 +5,8 @@
  UpdateWcsPlc = '/api/wcsPlc/update',
  PageWcsPlc = '/api/wcsPlc/page',
  DetailWcsPlc = '/api/wcsPlc/detail',
  ListStatus='/api/wcsPlc/ListStatus'
  ListStatus = '/api/wcsPlc/ListStatus',
  ListPosition = 'api/wcsPlc/ListPosition'
}
// 增加PLC
@@ -56,3 +57,9 @@
            method: 'get'
        });
// 获取位置上有没有东西
export const listPosition = () =>
    request({
            url: Api.ListPosition,
            method: 'get'
        });
Web/src/views/device/deviceInfo/index.vue
@@ -37,9 +37,9 @@
            </el-col>
            <el-col :span="21">
                <div class="card-page">
                    <el-button type="primary" :plain="isPlain1" @click="floorTogglePlain(1)">一层平面</el-button>
                    <el-button type="primary" :plain="isPlain2" @click="floorTogglePlain(2)">二层平面</el-button>
                    <el-button type="primary" :plain="isPlain3" @click="floorTogglePlain(3)">三层平面</el-button>
                    <el-button type="primary" :plain="floorStates.isPlain1" @click="floorTogglePlain(1)">一层平面</el-button>
                    <el-button type="primary" :plain="floorStates.isPlain2" @click="floorTogglePlain(2)">二层平面</el-button>
                    <el-button type="primary" :plain="floorStates.isPlain3" @click="floorTogglePlain(3)">三层平面</el-button>
                </div>
                <div style="margin: 40px; height: 50%;">
                    <div class="grid-container-line">
@@ -71,7 +71,7 @@
<script lang="ts" setup>
import { ref, reactive, onMounted } from 'vue';
import { listStatus } from '/@/api/wcs/wcsPlc';
import { listStatus, listPosition } from '/@/api/wcs/wcsPlc';
import { signalR } from './signalR';
const state = ref<any>({});
@@ -83,6 +83,24 @@
    state.value = res.data.result.modService;
    stackers.value = res.data.result.listPlc.filter(s => s.type == 0);
    conveyors.value = res.data.result.listPlc.filter(s => s.type == 1 || s.type == 4);
    var res2 = await listPosition();
    res2.data.result.forEach(s => {
        if (s.type == 0) {
            // 更新堆垛机数据
            const foundCell = cellsDataLine.value.find(cell => cell.Code === s.stationNum);
            if (foundCell) {
                //修改高度
                foundCell.BoxHeight = s.boxHeight;
            }
        }
        else if (s.type == 1) {
            // 更新输送线数据
            updateCellData(cellsDataOne, s);
            updateCellData(cellsDataTwo, s);
            updateCellData(cellsDataThree, s);
        }
    });
};
handleQuery();
@@ -110,19 +128,46 @@
    signalR.on('UpdateService', (data: any) => {
        state.value = data;
    });
    signalR.off('PublicPosition');
    signalR.on('PublicPosition', (data: any) => {
        if (data.type == 1) {
            // 更新输送线数据
            updateCellData(cellsDataOne, data);
            updateCellData(cellsDataTwo, data);
            updateCellData(cellsDataThree, data);
        }
        else if (data.type == 0) {
            // 更新堆垛机数据
            const foundCell = cellsDataLine.value.find(cell => cell.Code === data.stationNum);
            if (foundCell) {
                //修改高度
                foundCell.BoxHeight = data.boxHeight;
            }
        }
    });
});
const handleSwitchChange = (field: string, value: boolean) => {
    signalR.invoke('UpdateService',state.value);
    signalR.invoke('UpdateService', state.value);
};
// 更新输送线数据的通用函数
function updateCellData(cellsData: any[], data: any) {
    const foundCell = cellsData.find(cell => cell.Code === data.stationNum);
    if (foundCell) {
        if (data.boHaveItem) {
            foundCell.IsUse = 1;
        }
        else {
            foundCell.IsUse = 0;
        }
    }
}
const activeName = ['1', '2', '3'];
const value1 = ref(false);
const value2 = ref(false);
const value3 = ref(false);
//堆垛机数据
const cellsDataLine = [
const cellsDataLine = ref([
    { Id: 1, Code: '001', LineCode: '', EndLocat: '', IsShow: 1, IsUse: 0, BoxHeight: 10 },
    { Id: 2, Code: '002', LineCode: '01', EndLocat: '01010101', IsShow: 0, IsUse: 0, BoxHeight: 10 },
    { Id: 3, Code: '003', LineCode: '', EndLocat: '', IsShow: 1, IsUse: 0, BoxHeight: 10 },
@@ -174,7 +219,7 @@
    { Id: 49, Code: '049', LineCode: '', EndLocat: '', IsShow: 1, IsUse: 0, BoxHeight: 10 },
    { Id: 50, Code: '050', LineCode: '10', EndLocat: '', IsShow: 0, IsUse: 0, BoxHeight: 10 },
    { Id: 51, Code: '051', LineCode: '', EndLocat: '', IsShow: 1, IsUse: 0, BoxHeight: 10 },
];
]);
//一层输送线数据
const cellsDataOne = [
@@ -1924,29 +1969,26 @@
//输送线数据
let cellsData = ref(cellsDataOne);
const isPlain1 = ref(false);//一层
const isPlain2 = ref(true);//二层
const isPlain3 = ref(true);//三层
// 层平面状态
const floorStates = ref({
    isPlain1: false,
    isPlain2: true,
    isPlain3: true
});
//切换层平面
function floorTogglePlain(buttonNumber) {
    if (buttonNumber === 1) {
        isPlain1.value = !isPlain1.value;
        isPlain2.value = true;
        isPlain3.value = true;
    const floorData = [cellsDataOne, cellsDataTwo, cellsDataThree];
        cellsData.value = cellsDataOne;
    } else if (buttonNumber === 2) {
        isPlain2.value = !isPlain2.value;
        isPlain1.value = true;
        isPlain3.value = true;
        cellsData.value = cellsDataTwo;
    } else if (buttonNumber === 3) {
        isPlain3.value = !isPlain3.value;
        isPlain1.value = true;
        isPlain2.value = true;
        cellsData.value = cellsDataThree;
    if (buttonNumber >= 1 && buttonNumber <= 3) {
        const index = buttonNumber - 1;
        floorStates.value = {
            isPlain1: index !== 0,
            isPlain2: index !== 1,
            isPlain3: index !== 2
        };
        cellsData.value = floorData[index];
    }
}
</script>