private void button1_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; ushort focasLibHandleMain = ushort.MinValue; Ping ping = new Ping(); PingReply reply = ping.Send(txtIpAddress.Text.Trim(), 4000); if (reply.Status == IPStatus.Success) { short ret = FocasLib.cnc_allclibhndl3(txtIpAddress.Text.Trim(), 8193, 4, out focasLibHandleMain); if (ret == 0) { ret = FocasLib.cnc_freelibhndl(focasLibHandleMain); MessageBox.Show("Successfully connected to CNC machine."); } else { MessageBox.Show("Not able to connect to CNC machine, Please check IP Address, Port No(8193). Return value from function is " + ret + " ."); } } else { MessageBox.Show("Not able to Ping the CNC Machine. Please check the ip address and try again. Ping Status = " + reply.Status); } this.Cursor = Cursors.Default; }
public string ReadCNCId(ushort handle) { string cncIDstr = ""; uint[] cncid = new uint[4]; int ret = FocasLib.cnc_rdcncid(handle, cncid); if (ret == 0) { foreach (var item in cncid) { cncIDstr = cncIDstr + item.ToString("X") + "-"; } } cncIDstr = cncIDstr.Trim('-'); return(cncIDstr);// Base64Encode(cncIDstr); }
public void ReadCNCID(string ipAddress, ushort portNo) { if (String.IsNullOrEmpty(txtIpAddress.Text.Trim())) { MessageBox.Show("Please enter IP address"); return; } this.Cursor = Cursors.WaitCursor; ushort focasLibHandleMain = ushort.MinValue; Ping ping = new Ping(); PingReply reply = ping.Send(ipAddress, 4000); if (reply.Status == IPStatus.Success) { short ret = FocasLib.cnc_allclibhndl3(ipAddress, portNo, 4, out focasLibHandleMain); if (ret == 0) { //txtCncId.Text = ReadCNCId(focasLibHandleMain); CNCIDs = txtIpAddress.Text.PadRight(15) + "[ " + ReadCNCId(focasLibHandleMain) + " ]"; if (!lstCNCID.Items.Contains(CNCIDs)) { lstCNCID.Items.Add(CNCIDs); } } else { MessageBox.Show("Not able to connect to CNC machine, Please check IP Address, Port No (8193). Return value from function is " + ret + " ."); } ret = FocasLib.cnc_freelibhndl(focasLibHandleMain); } else { MessageBox.Show("Not able to Ping the CNC Machine. Please check the ip address and try again. Ping Status = " + reply.Status); } this.Cursor = Cursors.Default; }