立体仓库WCS系统-输送机(Convery)控制

这个代码段定义了一个名为ConveryPLC的类,用于管理输送机的PLC数据。类中包含了初始化数据、读取和解析PLC信息、重新连接PLC、以及处理不同事件的功能。类还维护了多个列表来存储输送机的状态信息,并提供了读取和写入PLC数据的方法。

using WCS.Common;
using WCS.Entity;
using WCS.Entity.Convery;
using WCS.Entity.SRM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Data;
using System.Threading.Tasks;
using Common.Log;

namespace Core.Library.PLCManager
{
    /// <summary>
    /// 输送机PLC
    /// </summary>
    public class ConveryPLC : PLCHelper
    {
        public LogHelper stalog = new LogHelper("Convery");
        public static List<ConveryEntity> lsRFID = new List<ConveryEntity>();
        public static List<ConveryEntity> StationsInfo = new List<ConveryEntity>();
        public List<ConveryGroupEntity> lstRead1 = new List<ConveryGroupEntity>();
        public List<ConveryGroupEntity> lstRead2 = new List<ConveryGroupEntity>();
        public static List<ConveryItemCode> lstItemCode = new List<ConveryItemCode>();
        public static bool IsInit = false;
        private string local_ip;
        private readonly object objLoc = new object();
        public Dictionary<string,bool> PLCConnectStatus = new Dictionary<string,bool>();

        private delegate void ReadOPCInfos(object info);
        private event ReadOPCInfos ReadEquipOPCInfo;
        private delegate void ReConnetPLC(string ip, int retryCount);
        private event ReConnetPLC STAReConnectPLC;

        public delegate  void ModeOf1200();
        public event ModeOf1200 mode1200;

        private string _GuidID;
        private static readonly object obj = new object();


        public string GuidID
        {
            get
            {
                if (string.IsNullOrEmpty(_GuidID))
                {
                    _GuidID = Guid.NewGuid().ToString();
                }
                return _GuidID;
            }
            set { _GuidID = value; }
        }

        public void InitData(List<ConveryEntity> lst, ref string error)
        {
            try
            {
                foreach (var item in lst as List<ConveryEntity>)
                {
                    local_ip = item.Key_ip;
                    if (!PLCList.ContainsKey(local_ip))
                    {
                        PLCList.Add(local_ip, new OPCServer(local_ip, 1));
                        if (PLCList[local_ip].Connect())
                        {
                            if (!PLCConnectStatus.ContainsKey(item.Key_ip))
                            {
                                PLCConnectStatus.Add(item.Key_ip, true);
                            }
                        }
                        else
                        {
                            if (!PLCConnectStatus.ContainsKey(item.Key_ip))
                            {
                                PLCConnectStatus.Add(item.Key_ip, false);
                            }
                        }
                    }
                    ConveryInit(item, local_ip);
                }
                ShowMsg("Init", "输送机初始化化完成");
                IsInit = true;
            }
            catch (Exception ex)
            {
                error = ex.Message + ex.Source + ex.StackTrace;
            }
        }

     

        public ConveryPLC()
        {
            ReadEquipOPCInfo += new ReadOPCInfos(BatchReadConveryInfo);
            this.STAReConnectPLC += new ReConnetPLC(ReConnect);
            QueueSpeech.Start();

          
        }
        /// <summary>
        /// 初始化输送机
        /// </summary>
        /// <param name="si"></param>
        private void ConveryInit(ConveryEntity si, string strlocal_ip)
        {
            if (si.config == "Convery" || si.config == "SetInfo" || si.config == "Other")
            {
                if (int.Parse(si.Belong) < 24)
                {
                    if (lstRead1.Exists(it => it.key_ip.ToString().Trim() == si.Key_ip && it.Belong == si.Belong))
                    {
                        ConveryGroupEntity cr = lstRead1.Find(it => it.key_ip.ToString().Trim() == strlocal_ip && it.Belong == si.Belong.Trim());
                        if (cr != null)
                        {
                            int index = ((int.Parse(si.StationNo) - cr.currentStatioNo));
                            if (index > 1)  index = index - 1;
                            cr.length += si.length * index;
                            cr.currentStatioNo = int.Parse(si.StationNo);
                            cr.lststation.Add(si);
                        }
                    }
                    else
                    {
                        ConveryGroupEntity cr = new ConveryGroupEntity();
                        cr.value = si.value;
                        cr.length = si.length;
                        cr.key_ip = si.Key_ip;
                        cr.DBAddress = si.DBAddress;
                        cr.lststation.Add(si);
                        cr.currentStatioNo = int.Parse(si.StationNo);
                        cr.Belong = si.Belong;
                        lstRead1.Add(cr);
                    }
                }
                else
                {
                    if (lstRead2.Exists(it => it.key_ip.ToString().Trim() == si.Key_ip && it.Belong == si.Belong))
                    {
                        ConveryGroupEntity cr = lstRead2.Find(it => it.key_ip.ToString().Trim() == strlocal_ip && it.Belong == si.Belong.Trim());
                        if (cr != null)
                        {
                            int index = ((int.Parse(si.StationNo) - cr.currentStatioNo));
                        &n

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

meslog

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值