Debug.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. //Add code
  11. using System.Runtime.InteropServices; //ini파일 로드 필요라이브러리
  12. namespace RF_TRIO_PLL_ZIG
  13. {
  14. public partial class Debug : Form
  15. {
  16. Main_Form main_form;
  17. int LineLimit = 500;
  18. [DllImport("user32.dll")]
  19. public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
  20. private const int WM_SETREDRAW = 11;
  21. Serial serial;
  22. public RadioButton RadioButton_ascii { get => radioButton_ascii; set => radioButton_ascii = value; }
  23. public RadioButton RadioButton_hex { get => radioButton_hex; set => radioButton_hex = value; }
  24. public Debug()
  25. {
  26. InitializeComponent();
  27. }
  28. #if true
  29. public void Data_Recv_Str(string text)
  30. {
  31. int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
  32. try
  33. {
  34. try
  35. {
  36. SendMessage(this.Handle, WM_SETREDRAW, false, 0);
  37. }
  38. catch (Exception e) { MessageBox.Show(e.StackTrace); }
  39. if (tbReceived.Lines.Length > nLimitLines)
  40. {
  41. LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
  42. while ((tempLines.Count - nLimitLines) > 0)
  43. {
  44. tempLines.RemoveFirst();
  45. }
  46. tbReceived.Lines = tempLines.ToArray();
  47. }
  48. try
  49. {
  50. SendMessage(this.Handle, WM_SETREDRAW, true, 0);
  51. }
  52. catch { return; }
  53. tbReceived.AppendText(text);
  54. tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택...
  55. tbReceived.ScrollToCaret();
  56. }
  57. catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
  58. }
  59. #endif
  60. #if false
  61. public void Data_Recv_Hex(byte[] text)
  62. {
  63. int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
  64. try
  65. {
  66. try
  67. {
  68. SendMessage(this.Handle, WM_SETREDRAW, false, 0);
  69. }
  70. catch (Exception e) { MessageBox.Show(e.StackTrace); }
  71. if (tbReceived.Lines.Length > nLimitLines)
  72. {
  73. LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
  74. while ((tempLines.Count - nLimitLines) > 0)
  75. {
  76. tempLines.RemoveFirst();
  77. }
  78. tbReceived.Lines = tempLines.ToArray();
  79. }
  80. try
  81. {
  82. SendMessage(this.Handle, WM_SETREDRAW, true, 0);
  83. }
  84. catch { return; }
  85. tbReceived.AppendText(text.ToString());
  86. tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택...
  87. tbReceived.ScrollToCaret();
  88. }
  89. catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
  90. }
  91. #endif
  92. public void Data_Recv_Hex(byte[] text)
  93. {
  94. string AppendMessage = "";
  95. int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
  96. try
  97. {
  98. for (int i = 0; i < text.Length; i++)
  99. {
  100. AppendMessage += Convert.ToString(text[i], 16);
  101. }
  102. tbReceived.AppendText(AppendMessage);
  103. try
  104. {
  105. SendMessage(this.Handle, WM_SETREDRAW, false, 0);
  106. }
  107. catch { return; }
  108. if (tbReceived.Lines.Length > nLimitLines)
  109. {
  110. LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
  111. while ((tempLines.Count - nLimitLines) > 0)
  112. {
  113. tempLines.RemoveFirst();
  114. }
  115. tbReceived.Lines = tempLines.ToArray();
  116. }
  117. try
  118. {
  119. SendMessage(this.Handle, WM_SETREDRAW, true, 0);
  120. }
  121. catch { return; }
  122. tbReceived.Select(tbReceived.Text.Length, 0);
  123. tbReceived.ScrollToCaret();
  124. }
  125. catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
  126. }
  127. public void Data_Send(byte[] text)
  128. {
  129. string AppendMessage = "\n[TX]";
  130. int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
  131. try
  132. {
  133. for (int i = 0; i < text.Length; i++)
  134. {
  135. AppendMessage += Convert.ToString(text[i], 16);
  136. }
  137. tbReceived.AppendText(AppendMessage);
  138. try
  139. {
  140. SendMessage(this.Handle, WM_SETREDRAW, false, 0);
  141. }
  142. catch { return; }
  143. if (tbReceived.Lines.Length > nLimitLines)
  144. {
  145. LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
  146. while ((tempLines.Count - nLimitLines) > 0)
  147. {
  148. tempLines.RemoveFirst();
  149. }
  150. tbReceived.Lines = tempLines.ToArray();
  151. }
  152. try
  153. {
  154. SendMessage(this.Handle, WM_SETREDRAW, true, 0);
  155. }
  156. catch { return; }
  157. tbReceived.Select(tbReceived.Text.Length, 0);
  158. tbReceived.ScrollToCaret();
  159. }
  160. finally { }
  161. }
  162. public void Serial_ClassSet(object serial)
  163. {
  164. this.serial = (Serial)serial;
  165. }
  166. private void Button_Send_Click(object sender, EventArgs e)
  167. {
  168. try
  169. {
  170. this.serial.Serial_DataSend(Encoding.ASCII.GetBytes(textBox_senddata.Text));
  171. }
  172. catch (System.Exception ex)
  173. {
  174. MessageBox.Show(ex.Message);
  175. }
  176. }
  177. private void Button_Clear_Click(object sender, EventArgs e)
  178. {
  179. try
  180. {
  181. this.tbReceived.Text = "";
  182. }
  183. finally { }
  184. }
  185. public void hex_to_ascii_radiobuttonConvert()
  186. {
  187. radioButton_hex.Checked = true;
  188. radioButton_ascii.Checked = false;
  189. }
  190. public void ascii_to_hex_radiobuttonConvert()
  191. {
  192. radioButton_ascii.Checked = true;
  193. radioButton_hex.Checked = false;
  194. }
  195. public void Debug_Main_Form_Get(object frm)
  196. {
  197. this.main_form = (Main_Form)frm;
  198. }
  199. }
  200. }