private void LogOff_Gj(short rowinput, string ipinput) { GjApi.disconnect430ToNC(CGlbFunc.clientNo[rowinput]); //关闭一个实例,没有返回值 CGlbFunc.LoginFlag[rowinput] = Constants.LOGOFFLAG; CGlbFunc.clientNo[rowinput] = -1; CGlbFunc.ip_info[rowinput] = ipinput; //连接成功存储相关信息到GLOBLE变量 #if (MARCO_DB) LogIn_Enqueue(rowinput); #endif }
private void UpdateTheText_gj() { int ret32 = 0; StringBuilder strrusult = new StringBuilder(); this.txtnum.Text = gjclient.ToString(); newnc.shrNCno = (short)gjclient; /*系统ID*/ this.txtid.Text = "G" + ip.Remove(0, 4); newnc.strNC_ID = "G" + ip.Remove(0, 4); /*版本号1 软件版本号*/ ret32 = GjApi.get430StatusStaticVal(gjclient, 2541, strrusult); if (ret32 == 0) { this.txtver1.Text = strrusult.ToString(); newnc.strNC_Version_Num_1 = strrusult.ToString(); } /*版本号2 硬件版本号*/ ret32 = GjApi.get430StatusStaticVal(gjclient, 2543, strrusult); if (ret32 == 0) { this.txtver2.Text = strrusult.ToString(); newnc.strNC_Version_Num_2 = strrusult.ToString(); } /*版本号3 系统内核版本号*/ ret32 = GjApi.get430StatusStaticVal(gjclient, 2545, strrusult); if (ret32 == 0) { this.txtver3.Text = strrusult.ToString(); newnc.strNC_Version_Num_3 = strrusult.ToString(); } /*型号*/ ret32 = GjApi.get430StatusStaticVal(gjclient, 2541, strrusult); if (ret32 == 0) { this.txtxinhao.Text = strrusult.ToString(); newnc.strNC_Num = strrusult.ToString(); } newnc.tDatatime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:sss.ffff"); this.txtdt.Text = newnc.tDatatime; newnc.strNC_factr = this.txtFac.Text; newnc.strIP = ip; newnc.strPort = port; newnc.strNC_state = "未登录"; }
private void LogIn_Gj(short rowinput, string ipinput) { char[] ip = ipinput.ToCharArray(); ushort port = 5005; int ActiveClientNo = -1; Int32 retval = GjApi.connect430ToNC(ref ActiveClientNo, ip, port); if (retval == 0) { Console.WriteLine("HZ Connect successed"); CGlbFunc.LoginFlag[rowinput] = Constants.LOGINFLAG; //登陆标志位 CGlbFunc.clientNo[rowinput] = (short)ActiveClientNo; CGlbFunc.ip_info[rowinput] = ipinput; CGlbFunc.port_info[rowinput] = port; //连接成功存储相关信息到GLOBLE变量 CGlbFunc.Power_time_today[rowinput] = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //存储每次开机时间用于显示 #if (MARCO_DB) LogIn_Enqueue(rowinput); #endif } else { MessageBox.Show("连接失败,请检查后重试!"); //申请存储空间nmlServerArray失败返回值是-1,无地址或端口返回值是-2,“不存在编号为**的机器”时函数返回值是-3,“与NC建立连接时出错”时函数返回值是-,4,执行正常则函数返回值是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("请输入正确的厂商名称"); } } }