コード例 #1
0
        private void LogIn_Gsk(short rowinput, string ipinput)
        {
            IPAddress addr = IPAddress.Parse(ipinput);

            byte[] ip_by = addr.GetAddressBytes();
            //Byte[] ipadd = System.Text.Encoding.Default.GetBytes("192.168.188.121");
            IntPtr hInst = GskApi.GSKRM_CreateInstance(ref ip_by[0], 1);

            if (hInst == IntPtr.Zero)
            {
                Console.WriteLine("Connect failed");
                MessageBox.Show("广州数控" + (rowinput - 9).ToString() + " 号机,连接失败,请检查后重试!");
            }
            else
            {
                Console.WriteLine("GSK Connect successed");
                CGlbFunc.LoginFlag[rowinput] = Constants.LOGINFLAG;
                CGlbFunc.gsktock[rowinput]   = hInst;
                CGlbFunc.ip_info[rowinput]   = ipinput;
                CGlbFunc.id_info[rowinput]   = dtGridView_NC.SelectedCells[Constants.TB_ID].Value.ToString();
                //连接成功存储相关信息到GLOBLE变量
                CGlbFunc.Power_time_today[rowinput] = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //存储每次开机时间用于显示
#if (MARCO_DB)
                LogIn_Enqueue(rowinput);
#endif
            }
        }
コード例 #2
0
 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("请输入正确的厂商名称");
         }
     }
 }