Beispiel #1
0
        /// <summary>
        /// 连接机床网络
        /// </summary>
        /// <param name="ipr">
        /// 机床ip
        /// </param>
        /// <param name="ipl">
        /// 本地ip
        /// </param>
        /// <param name="port">
        /// 机床端口
        /// </param>
        /// <returns>
        /// true:连接成功
        /// false:连接失败
        /// </returns>
        public static int start_connect(string ipr, string ipl, UInt16 port)
        {
            ipnl  = ipl;
            ipnr  = ipr;
            portn = port;
            int ret;

            // 初始化
            ret = Api.HNC_NetInit(ipnl, 9090, "DataC");
            if (ret != 0)
            {
                //MessageBox.Show("初始化失败");
                return(1);
            }

            // 连接
            ret = Api.HNC_NetConnect(ipnr, portn);

            Thread.Sleep(10);

            // 检测是否已连接
            if (Api.HNC_NetIsConnect(ipnr, portn) == 0)
            {
                iscon = true;
                return(0);
            }
            else
            {
                return(2);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 连接机床网络
        /// </summary>
        /// <param name="ipr">
        /// 机床ip
        /// </param>
        /// <param name="ipl">
        /// 本地ip
        /// </param>
        /// <param name="port">
        /// 机床端口
        /// </param>
        /// <returns>
        /// true:连接成功
        /// false:连接失败
        /// </returns>
        public static bool start_connect(string ipr, string ipl, UInt16 port)
        {
            ipnl  = ipl;
            ipnr  = ipr;
            portn = port;
            int ret;

            // 初始化
            ret = Api.HNC_NetInit(ipnl, 9090, "NCVM");
            if (ret != 0)
            {
                MessageBox.Show("初始化失败");
            }

            // 连接
            ret = Api.HNC_NetConnect(ipnr, portn);

            Thread.Sleep(10);

            // 检测是否已连接
            if (Api.HNC_NetIsConnect(ipnr, portn) == 0)
            {
                iscon = true;
            }
            return(iscon);
        }
Beispiel #3
0
        private void LogIn_Hnc(short rowinput, string ipinput)
        {
            string ip             = ipinput;
            ushort port           = 21;
            short  ActiveClientNo = HncApi.HNC_NetConnect(ip, port);

            if (ActiveClientNo >= 0)
            {
                Console.WriteLine("HZ Connect successed");
                CGlbFunc.LoginFlag[rowinput]        = Constants.LOGINFLAG; //登陆标志位
                CGlbFunc.clientNo[rowinput]         = ActiveClientNo;
                CGlbFunc.ip_info[rowinput]          = ip;
                CGlbFunc.port_info[rowinput]        = port;                                                      //连接成功存储相关信息到GLOBLE变量
                CGlbFunc.Power_time_today[rowinput] = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:sss.ffff"); //存储每次开机时间用于显示
#if (MARCO_DB)
                LogIn_Enqueue(rowinput);
#endif
            }
            else
            {
                MessageBox.Show("连接失败,请检查后重试!");  //华中数控连接成功会返回一个大于等于0的clientno
            }
        }
 private void button1_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(txtIP.Text.Trim()) || string.IsNullOrWhiteSpace(txtPort.Text.Trim()))
     {
         MessageBox.Show("请输入IP地址和端口号!");
         return;
     }
     else
     {
         ip   = txtIP.Text;
         port = Convert.ToUInt16(txtPort.Text);
         if (this.txtFac.Text == "华中数控")
         {
             clientno = HncApi.HNC_NetConnect(ip, port);
             if (clientno >= 0)
             {
                 this.Test.Text      = "连接成功";
                 this.Test.BackColor = Color.Green;
                 UpdateTheText_hz();
             }
             else
             {
                 this.Test.Text      = "测试连接";
                 this.Test.BackColor = Color.WhiteSmoke;
                 MessageBox.Show("连接失败,请检查后重试!");
             }
         }
         else if (this.txtFac.Text == "广州数控")
         {
             IPAddress addr  = IPAddress.Parse(ip);
             byte[]    ip_by = addr.GetAddressBytes();
             //Byte[] ipadd = System.Text.Encoding.Default.GetBytes("192.168.188.121");
             gskTocket = GskApi.GSKRM_CreateInstance(ref ip_by[0], 1);
             if (gskTocket == IntPtr.Zero)
             {
                 this.Test.Text      = "测试连接";
                 this.Test.BackColor = Color.WhiteSmoke;
                 MessageBox.Show("连接失败,请检查后重试!");
             }
             else
             {
                 Console.WriteLine("Connect successed");
                 this.Test.Text      = "连接成功";
                 this.Test.BackColor = Color.Green;
                 UpdateTheText_gsk();
             }
         }
         else if (this.txtFac.Text == "沈阳高精")
         {
             char[] ipaddr = ip.ToCharArray();
             Int32  retval = GjApi.connect430ToNC(ref gjclient, ipaddr, port);
             if (retval == 0)
             {
                 Console.WriteLine("gaojing Connect successed");
                 this.Test.Text      = "连接成功";
                 this.Test.BackColor = Color.Green;
                 UpdateTheText_gj();
             }
             else
             {
                 this.Test.Text      = "测试连接";
                 this.Test.BackColor = Color.WhiteSmoke;
                 MessageBox.Show("连接失败,请检查后重试!");
             }
         }
         else
         {
             MessageBox.Show("请输入正确的厂商名称");
         }
     }
 }