LabelParam.cs 7.4 KB
using CodeLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace DeviceLibrary
{
    //[Serializable]
    //public class ReelParam
    //{
    //    /// <summary>
    //    /// 创建新出入库信息
    //    /// </summary>
    //    /// <param name="wareNo">二维码内容</param>
    //    /// <param name="platew">宽度</param>
    //    /// <param name="plateh">高度</param>
    //    /// <param name="IsNg">是否是入库NG料</param>
    //    /// <param name="ngMsg">NG消息</param>
    //    public ReelParam(string wareNo = "", int platew = 0, int plateh = 0, bool _IsNg = false, string ngMsg = "")
    //    {
    //        WareCode = wareNo;
    //        PlateW = platew;
    //        PlateH = plateh;
    //        IsNg = _IsNg;
    //        NgMsg = ngMsg;
    //    }
    //    /// <summary>
    //    /// 物品二维码信息
    //    /// </summary>
    //    public string WareCode { get; set; }
    //    /// <summary>
    //    /// 库位号
    //    /// </summary>
    //    public string PosID { get; set; }
    //    public string bitmapfilename = "";
    //    public List<CodeInfo> codeInfos { get; set; }
    //    /// <summary>
    //    /// 料盘高度
    //    /// </summary>
    //    public int PlateH { get; set; }
    //    /// <summary>
    //    /// 料盘宽度
    //    /// </summary>
    //    public int PlateW { get; set; }
    //    /// <summary>
    //    /// 是否是入料NG料
    //    /// </summary>
    //    public bool IsNg = false;
    //    /// <summary>
    //    /// 入料NG消息
    //    /// </summary>
    //    public string NgMsg = "";
    //    /// <summary>
    //    /// 物料编码
    //    /// </summary>
    //    public string PN { get; set; }
    //    /// <summary>
    //    /// 数量
    //    /// </summary>
    //    public int QTY { get; set; } = 0;
    //    /// <summary>
    //    /// 厂家代码
    //    /// </summary>
    //    public string FC { get; set; }
    //    /// <summary>
    //    /// 唯一序列号
    //    /// </summary>
    //    public string RI { get; set; }
    //    /// <summary>
    //    /// 批次号
    //    /// </summary>
    //    public string Batch { get; set; }
    //    public bool ReelOnFixture { get; internal set; } = false;

    //    public int HeightPos = 0;
    //    public ReelParam clone()
    //    {
    //        ReelParam dstobject;
    //        using (MemoryStream mStream = new MemoryStream())
    //        {
    //            BinaryFormatter bf = new BinaryFormatter();
    //            bf.Serialize(mStream, this);
    //            mStream.Seek(0, SeekOrigin.Begin);//指定当前流的位置为流的开头。
    //            dstobject = (ReelParam)bf.Deserialize(mStream);
    //            mStream.Close();
    //        }
    //        return dstobject;
    //    }

    //    public string ToStr()
    //    {
    //        if (IsNg)
    //        {
    //            return crc.GetString(L.in_store_ng,"入库NG")+ $":{NgMsg}[{WareCode}]";
    //        }
    //        else
    //        {

    //            return crc.GetString(L.posnum, "库位号") + $":[{PosID}][{WareCode}] ";
    //        }
    //    }

    //}
    [Serializable]
    class BoxStorePosition {
        
        /// <summary>
        /// 旋转轴取料点
        /// </summary>
        public int Middle_P2;

        /// <summary>
        /// 升降轴取料高点
        /// </summary>
        public int UpDown_PH;
        /// <summary>
        /// 升降轴取料低点
        /// </summary>
        public int UpDown_PL;

        /// <summary>
        /// 进出轴取料点
        /// </summary>
        public int InOut_P2;

        /// <summary>
        /// 压紧轴高点
        /// </summary>
        public int Comp_PH;
        /// <summary>
        /// 压紧轴压紧点
        /// </summary>
        public int Comp_PL;

        public string posid;
        public ReelParam Reel;

        public BoxStorePosition(Robot_Config Config, ACStorePosition aCStorePosition, ReelParam reel) {
            Middle_P2 = aCStorePosition.XAxis_Position_P2;
            InOut_P2 = aCStorePosition.InOutAxis_Position_P3;
            UpDown_PH = aCStorePosition.UpDownAxis_IHPosition_P3;
            UpDown_PL = aCStorePosition.UpDownAxis_ILPosition_P4;


            int BagHigh = aCStorePosition.BagHigh;
            if (FixtureConfig.GetFixtureHeight(aCStorePosition.BagWidth, aCStorePosition.BagHigh, out int actualheight))
                BagHigh = actualheight;

            Comp_PH = Config.Comp_P2 - Config.Comp_PoToMM * (BagHigh - 70 + Config.Comp_PH_MM);

            int ReelHeight = reel.PlateH;
            if (FixtureConfig.GetFixtureHeight(reel.PlateW, reel.PlateH, out int actualheight1))
                ReelHeight = actualheight1;

            Comp_PL = Config.Comp_P2 - Config.Comp_PoToMM * (ReelHeight - 70);
            Comp_PH = Comp_PH < 0 ? 0 : Comp_PH;
            Comp_PL = Comp_PL < 0 ? 0 : Comp_PL;
            posid = aCStorePosition.PositionNum;
            Reel = reel.clone();
            LogUtil.info($"BSP:{posid},Comp_PH:{Comp_PH}={Config.Comp_P2}-({BagHigh}-{70}+{Config.Comp_PH_MM})*{Config.Comp_PoToMM},Comp_PL:{Comp_PL}={ReelHeight},{JsonHelper.SerializeObject(this)}");
        }
        public const string ngdoor = "单料口";

        public BoxStorePosition(Robot_Config Config, StoreSide storeSide, ReelParam reel)
        {
            int Height = reel.PlateH;
            if (FixtureConfig.GetFixtureHeight(reel.PlateW, reel.PlateH, out int actualheight))
                Height = actualheight;

            Comp_PH = Config.Comp_P2 - Config.Comp_PoToMM * (Height - 70 + Config.Comp_PH_MM);
            Comp_PL = Config.Comp_P2 - Config.Comp_PoToMM * (Height - 70);
            Comp_PH = Comp_PH < 0 ? 0 : Comp_PH;
            Comp_PL = Comp_PL < 0 ? 0 : Comp_PL;
            if (storeSide == StoreSide.NGDoor)
            {
                Middle_P2 = Config.Middle_P2;
                InOut_P2 = Config.InOut_P2;
                UpDown_PH = Config.UpDown_P2;
                UpDown_PL = Config.UpDown_P3;
                posid = ngdoor;
            }
            Reel = reel.clone();
            LogUtil.info($"BSP:{posid},Comp_PL:{Comp_PL}={reel.PlateH},{JsonHelper.SerializeObject(this)}");
        }
        public static BoxStorePosition GetFixPos(Robot_Config Config, ReelParam reel) {
            var fixpos = "fix#" + reel.PlateW.ToString();

            var ac = CSVPositionReader<ACStorePosition>.GetPositon(fixpos);
            if (ac == null)
                return null;

            var p = new BoxStorePosition(Config, ac, reel);
            return p;
        }
        public BoxStorePosition clone()
        {
            BoxStorePosition dstobject;
            using (MemoryStream mStream = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(mStream, this);
                mStream.Seek(0, SeekOrigin.Begin);//指定当前流的位置为流的开头。
                dstobject = (BoxStorePosition)bf.Deserialize(mStream);
                mStream.Close();
            }
            return dstobject;
        }
    }
    public enum StoreSide
    {
        NGDoor,
        String,
        Fix,
        Clamp
    }
}