public void UpdateTheText_ht(short num) { //获取版本信息 IntPtr ret = new IntPtr(); ret = HtApi.GetSysteminfo(num); if (ret != null)//获取成功 { SYSTEM_INFO sysinfo = new SYSTEM_INFO(); sysinfo = (SYSTEM_INFO)Marshal.PtrToStructure(ret, typeof(SYSTEM_INFO)); //系统id newnc.strNC_ID = sysinfo.systemid; this.txtid.Text = newnc.strNC_ID; //系统总版本号 newnc.strNC_Version_Num_1 = sysinfo.systemver; this.txtver1.Text = newnc.strNC_Version_Num_1.ToString(); //系统型号 newnc.strNC_Num = sysinfo.systemtype; this.txtxinhao.Text = newnc.strNC_Num; //系统编号 newnc.shrNCno = num; this.txtnum.Text = newnc.shrNCno.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_Ht(short rowinput, string ipinput) { string ip = ipinput; ushort pt = 6665; string port = pt.ToString(); try { //为什么要系统编号,是将ip和端口号与编号相互绑定,之后通过编号就能进行连接断开重连的操作?? int res = HtApi.ClientConnectServer(rowinput - 15, ip, port); if (res == 0) { Console.WriteLine("航天数控连接成功"); CGlbFunc.LoginFlag[rowinput] = Constants.LOGINFLAG; //登陆标志位 //CGlbFunc.clientNo[rowinput] = ActiveClientNo; CGlbFunc.ip_info[rowinput] = ip; CGlbFunc.port_info[rowinput] = pt; //连接成功存储相关信息到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("连接失败,请检查后重试!"); } } catch (Exception ex) { Console.WriteLine(ex); MessageBox.Show("连接失败"); } }
private void LogOff_Ht(short rowinput, string ipinput) { HtApi.DeleteServer(rowinput - 14); 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 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 if (this.txtFac.Text == "航天数控") { string fip = ip.ToString(); string fport = port.ToString(); short num = Convert.ToInt16(cmbnum.Text); int res = HtApi.ClientConnectServer(num, fip, fport); if (res == 0) { Console.WriteLine("航天数控连接成功"); this.Test.Text = "连接成功"; this.Test.BackColor = Color.Green; UpdateTheText_ht(num); } else { this.Test.Text = "测试连接"; this.Test.BackColor = Color.WhiteSmoke; Console.WriteLine("航天数控连接失败"); MessageBox.Show("连接失败,请检查后重试!"); } MessageBox.Show("请输入正确的厂商名称"); } } }