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 } }
private void LogOff_Gsk(short rowinput, string ipinput) { GskApi.GSKRM_CloseInstance(CGlbFunc.gsktock[rowinput]);//关闭一个实例,没有返回值 CGlbFunc.LoginFlag[rowinput] = Constants.LOGOFFLAG; CGlbFunc.gsktock[rowinput] = IntPtr.Zero; CGlbFunc.ip_info[rowinput] = ipinput; //连接成功存储相关信息到GLOBLE变量 #if (MARCO_DB) LogIn_Enqueue(rowinput); #endif }
private void UpdateTheText_gsk() { Byte[] aCNCtype = new Byte[20]; IntPtr retptr = new IntPtr(); Int32 ret = GskApi.GSKRM_GetConnectState(gskTocket); if (ret == 1) { GskApi.GSKRM_GetCncTypeName(gskTocket, aCNCtype); //型号读取接口会报错 retptr = InfoApi.GSKRM_GetVersionInfo(gskTocket); try { VERS_INFO structure = new VERS_INFO(); //int size = Marshal.SizeOf(typeof(VERS_INFO)); //IntPtr allocIntPtr = Marshal.AllocHGlobal(size); //分配内存,返回一个指针 structure = (VERS_INFO)Marshal.PtrToStructure(retptr, typeof(VERS_INFO)); newnc.strNC_ID = structure.softWareNumber; this.txtid.Text = newnc.strNC_ID; newnc.strNC_Version_Num_1 = structure.armVersion; this.txtver1.Text = newnc.strNC_Version_Num_1; newnc.strNC_Version_Num_2 = structure.dspVersion; this.txtver2.Text = newnc.strNC_Version_Num_2; newnc.strNC_Version_Num_3 = structure.FPGAVersion; this.txtver3.Text = newnc.strNC_Version_Num_3; newnc.strNC_Version_Num_4 = structure.hardVersion; this.txtver4.Text = newnc.strNC_Version_Num_4; newnc.strNC_Version_Num_5 = structure.sysVersion; this.txtver5.Text = newnc.strNC_Version_Num_5; } catch (Exception ex) { Console.WriteLine(ex); } finally { GskApi.GSKRM_CloseInstance(gskTocket); } this.txtxinhao.Text = System.Text.Encoding.Default.GetString(aCNCtype); newnc.tDatatime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:sss.ffff"); this.txtdt.Text = newnc.tDatatime; newnc.strNC_Num = this.txtxinhao.Text; newnc.strNC_factr = this.txtFac.Text; newnc.strIP = ip; newnc.strPort = port; newnc.strNC_state = "未登录"; } else { MessageBox.Show("连接断开"); } }
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("请输入正确的厂商名称"); } } }