using NJ_ZC;
using NPOI.SS.Formula.Functions;
using OpcBasic;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using SystemFramework;

namespace MesWork
{
    public partial class Temp { }
    /// <summary>
    /// 
    /// </summary>
    public partial class MesWorkForm
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt_Robot"></param>
        private void LoadDevice(ScadaConfig appConfig)
        {
            foreach (var mu in appConfig.MachineTool)
            {
                var Enable = mu.Enable;
                var Type = mu.Type;
                var ConnectStr = mu.ConnectStr;
                var Id = mu.Id;
                var Name = mu.Name;
                var DataTimeInterval = Convert.ToInt32(mu.DataTimeInterval);
                var AxesTimeInterval = Convert.ToInt32(mu.AxesTimeInterval);
                var Joints = mu.Joints;

                var TagID_Clamp = mu.TagID_Clamp;
             

                var IP = "";
                var Port = 0;

                if (Enable == "1")
                {
                    switch (Type.ToUpper())
                    {
                        case "ROBOTFANUC":
                            {
                                if (!ConnectStr.Contains(":"))
                                {
                                    MessageBox.Show("Json文件中，ConnectStr 值格式错误！");
                                    Process.GetCurrentProcess().Kill();
                                }
                                IP = ConnectStr.Split(':')[0];
                                Port = Convert.ToInt32(ConnectStr.Split(':')[1]);
                                var fanuc = new B_Robot_Fanuc();
                                fanuc.Start(IP, Port, AxesTimeInterval, DataTimeInterval, "CurrentPose", "", Id, Name, Joints);
                                dc_Robot.Add($"{Type}|{Id}", fanuc);
                            }
                            break;
                        case "ROBOTKUKA":
                            {
                                if (!ConnectStr.Contains(":"))
                                {
                                    MessageBox.Show("Json文件中，ConnectStr 值格式错误！");
                                    Process.GetCurrentProcess().Kill();
                                }
                                IP = ConnectStr.Split(':')[0];
                                Port = Convert.ToInt32(ConnectStr.Split(':')[1]);
                                var kuka = new B_Robot_Kuka();
                                kuka.Start(IP, Port, AxesTimeInterval, DataTimeInterval, "$axis_act", "$OUT[8]", Id, Name, Joints);
                                dc_Robot.Add($"{Type}|{Id}", kuka);
                            }
                            break;
                        case "ROBOTABB":
                            {
                                if (!ConnectStr.Contains(":"))
                                {
                                    MessageBox.Show("Json文件中，ConnectStr 值格式错误！");
                                    Process.GetCurrentProcess().Kill();
                                }
                                IP = ConnectStr.Split(':')[0];
                                var cname = ConnectStr.Split(':')[1];
                                var abb = new B_Robot_Abb();
                                abb.Start(IP, cname, AxesTimeInterval, DataTimeInterval, Id, Name, Joints);
                                dc_Robot.Add($"{Type}|{Id}", abb);
                            }
                            break;  
                        case "ROBOTEPSON":
                            {
                                if (!ConnectStr.Contains(":"))
                                {
                                    MessageBox.Show("Json文件中，ConnectStr 值格式错误！");
                                    Process.GetCurrentProcess().Kill();
                                }
                                IP = ConnectStr.Split(':')[0];
                                Port = Convert.ToInt32(ConnectStr.Split(':')[1]);
                                var espon = new B_Robot_Espon();
                                espon.Start(IP, Port, AxesTimeInterval, DataTimeInterval, Id, Name, Joints, TagID_Clamp);
                                dc_Robot.Add($"{Type}|{Id}", espon);
                            }
                            break;
                        case "AXIS":
                            {
                                var b_Read_N_Axis = new B_Read_N_Axis();
                                b_Read_N_Axis.Start(AxesTimeInterval, DataTimeInterval, ConnectStr, Joints, Id, Name);
                                dc_Name_Axis.Add($"{Type}|{Id}|{ConnectStr}", b_Read_N_Axis);
                            }
                            break;  
                        case "AXIS_CARD":
                            {
                                var b_Read_N_AxisCard = new B_Read_N_AxisCard();
                                b_Read_N_AxisCard.Start(AxesTimeInterval, DataTimeInterval, ConnectStr, Joints);
                                dc_Name_Axis_Card.Add($"{Type}|{Id}|{ConnectStr}", b_Read_N_AxisCard);
                            }
                            break;
                        case "AGV":
                            {
                                agvRead = new AgvRead();
                                agvRead.Start(ConnectStr,AxesTimeInterval, DataTimeInterval, Id, Name);
                            }
                            break; 
                        case "CNCEDM":
                            {
                                IP = ConnectStr.Split(':')[0];
                                Port = Convert.ToInt32(ConnectStr.Split(':')[1]);

                                var edm = new B_Cnc_Edm();
                                edm.Start(IP, Port, AxesTimeInterval, DataTimeInterval, Id, Name, Joints);

                                dc_Robot.Add($"{Type}|{Id}", edm);
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
             

        }
    
      


    }
} 




