Class1.cs 7.6 KB
using CodeLibrary;
using RemoteSheardObject;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;


[Serializable]
public class RemoteLoad
{
    /// <summary>
    /// 动作
    /// </summary>
    public string Action;
    public long Seq;
    /// <summary>
    /// 设备名称
    /// </summary>
    public string GroupName;
    /// <summary>
    /// 物料信息
    /// </summary>
    public RequestLoadInfo RequestLoadInfo;
}
[Serializable]
public class RequestLoadInfo
{
    /// <summary>
    /// 目的地设备名称
    /// </summary>
    public string DeviceGroupName;
    /// <summary>
    /// 托盘类型
    /// </summary>
    public string TrayType;
    /// <summary>
    /// 是否空托盘
    /// </summary>
    public bool IsEmpty;
    /// <summary>
    /// 料盘数据
    /// </summary>
    public ReelParam LoadParam;
    //public DoorStatusE DoorStatus;

    [Newtonsoft.Json.JsonIgnore]
    public TrayTypeE GetTrayType
    {
        get
        {
            try
            {
                return (TrayTypeE)Enum.Parse(typeof(TrayTypeE), TrayType);
            }
            catch
            {
                return TrayTypeE.None;
            }
        }
    }
}
public enum RobotStatusE
{
    INROBOT, BOXDOOR, FINISHED
}
/// <summary>
/// 治具类型
/// </summary>
public enum TrayTypeE
{
    None,
    /// <summary>
    /// 流水线料盘托盘
    /// </summary>
    MTP1,    //流水线料盘托盘
    /// <summary>
    /// 流水线治具托盘
    /// </summary>
    MTP2,    //流水线治具托盘
    /// <summary>
    /// 料串
    /// </summary>
    S007,    //料串
    /// <summary>
    /// Tray料格
    /// </summary>
    M03,    //Tray料格
    /// <summary>
    /// PCB料格
    /// </summary>
    M02,    //PCB料格
    /// <summary>
    /// PizzaBOX料格
    /// </summary>
    M01,    //PizzaBOX料格
    /// <summary>
    /// ShoeBOX料格
    /// </summary>
    M04,    //ShoeBOX料格

}
[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;
        codeInfos = new List<CodeInfo>();
    }
    /// <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; }
    public float Weight { 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; }
    public string DC { get; set; }
    /// <summary>
    /// 批次号
    /// </summary>
    public string Batch { get; set; }
    public string cid { get; set; }
    public string SubCID{ get; set; }



    public bool ReelOnFixture { get; set; } = false;
    public bool IsInStore { get; set; }

    public int HeightPos = 0;
    public string RFID = "";

    public virtual 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 $":{NgMsg}[{WareCode}][{RFID}][{PlateW}x{PlateH}][{cid}]";
        }
        else
        {

            return $":[{PosID}][{WareCode}][{RFID}][{PlateW}x{PlateH}][{cid},{SubCID}]";
        }
    }
    bool islog = false;
    /// <summary>
    /// NG口位置,1=左侧,2=右侧
    /// </summary>
    /// <param name="NgPos"></param>
    /// <param name="isInstore"></param>
    public virtual void logresult(int NgPos = 0,bool isInstore=true)
    {
        if (!islog)
        {
            islog = true;
            var datetime = DateTime.Now;
            string countfile = $".\\Logs\\NGLOG_{datetime:yyyyMMdd}.csv";
            Directory.CreateDirectory(".\\Logs\\");
            if (!File.Exists(countfile))
            {
                StreamWriter sw1 = new StreamWriter(countfile, true, Encoding.GetEncoding("GB2312"));
                sw1.WriteLine($"WareCode,SN,PN,Date,NgMsg");
                sw1.Close();
                sw1.Dispose();
            }
            try
            {
                var sw = new StreamWriter(countfile, true, Encoding.GetEncoding("GB2312"));
                //var sw = File.Open(countfile, FileMode.Append, FileAccess.Write);
                // string s = $"\r\n{ReeID},{PN},{PlateW}x{PlateH},{ReelDest},{NgMsg},{QTY},{WareCode}";
                //var b = Encoding.GetEncoding("gb2312").GetBytes(s);
                //sw.Write(b, 0, b.Length);
                sw.WriteLine($"{WareCode},{RI},{PN},{datetime:yyyy/MM/dd HH:mm:ss},{NgMsg}");
                sw.Close();
                sw.Dispose();
            }
            catch { }
            Task.Run(()=> {
                NgMsgData ngMsgData = new NgMsgData();
                ngMsgData.ngPos = NgPos;
                ngMsgData.ngMsg = NgMsg;
                ngMsgData.barcode = WareCode;
                ngMsgData.type = isInstore?"1":"0";
                ngMsgData.posName = getposname(PosID);
                TheLine.uploadNgReel(ngMsgData);
            });
        }
        string getposname(string posid) { 
            switch(posid)
            {
                case "NG_7_1":
                    return "R-SLOT1";
                case "NG_13_1":
                    return "R-SLOT2";
                case "NG_13_2":
                    return "R-SLOT3";
                case "DoorL4":
                    return "L-SLOT1";
                case "NG_BOX_1NG":
                    return "L-SLOT2";
                case "NG_BOX_2NG":
                    return "L-SLOT3";
                case "NG_BOX_3NG":
                    return "L-SLOT4";
                default:
                    return posid;
            }
        }
    }
}
public enum DoorStatusE {
    Busy,
    Free,
    CanInStore,
    CanOutStore,
    CanInOut,
}

public enum RemoteResult
{
    None,
    Timeout,
    False,
    True
}


[Serializable]
public class MTP
{
    /// <summary>
    /// 料盘托盘
    /// </summary>
    public static readonly string MTP1 = "MTP1";

    /// <summary>
    /// 治具托盘
    /// </summary>
    public static readonly string MTP2 = "MTP2";
}