Debug.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. try
  99. {
  100. SendMessage(this.Handle, WM_SETREDRAW, false, 0);
  101. }
  102. catch (Exception e) { MessageBox.Show(e.StackTrace); }*/
  103. for (int i = 0; i < text.Length; i++)
  104. {
  105. AppendMessage += Convert.ToString(text[i], 16);
  106. AppendMessage += " ";
  107. }
  108. AppendMessage += "\r\n";
  109. tbReceived.AppendText(AppendMessage);
  110. if (tbReceived.Lines.Length > nLimitLines)
  111. {
  112. LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
  113. while ((tempLines.Count - nLimitLines) > 0)
  114. {
  115. tempLines.RemoveFirst();
  116. }
  117. tbReceived.Lines = tempLines.ToArray();
  118. }
  119. try
  120. {
  121. SendMessage(this.Handle, WM_SETREDRAW, true, 0);
  122. }
  123. catch { return; }
  124. tbReceived.Select(tbReceived.Text.Length, 0);
  125. tbReceived.ScrollToCaret();
  126. }
  127. catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
  128. }
  129. public void Data_Send(byte[] text)
  130. {
  131. string AppendMessage = "\n[TX]";
  132. int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
  133. try
  134. {
  135. for (int i = 0; i < text.Length; i++)
  136. {
  137. AppendMessage += Convert.ToString(text[i], 16);
  138. }
  139. tbReceived.AppendText(AppendMessage);
  140. try
  141. {
  142. SendMessage(this.Handle, WM_SETREDRAW, false, 0);
  143. }
  144. catch { return; }
  145. if (tbReceived.Lines.Length > nLimitLines)
  146. {
  147. LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
  148. while ((tempLines.Count - nLimitLines) > 0)
  149. {
  150. tempLines.RemoveFirst();
  151. }
  152. tbReceived.Lines = tempLines.ToArray();
  153. }
  154. try
  155. {
  156. SendMessage(this.Handle, WM_SETREDRAW, true, 0);
  157. }
  158. catch { return; }
  159. tbReceived.Select(tbReceived.Text.Length, 0);
  160. tbReceived.ScrollToCaret();
  161. }
  162. finally { }
  163. }
  164. public void Serial_ClassSet(object serial)
  165. {
  166. this.serial = (Serial)serial;
  167. }
  168. private void Button_Send_Click(object sender, EventArgs e)
  169. {
  170. try
  171. {
  172. this.serial.Serial_DataSend(Encoding.ASCII.GetBytes(textBox_senddata.Text));
  173. }
  174. catch (System.Exception ex)
  175. {
  176. MessageBox.Show(ex.Message);
  177. }
  178. }
  179. private void Button_Clear_Click(object sender, EventArgs e)
  180. {
  181. try
  182. {
  183. this.tbReceived.Text = "";
  184. }
  185. finally { }
  186. }
  187. public void hex_to_ascii_radiobuttonConvert()
  188. {
  189. radioButton_hex.Checked = true;
  190. radioButton_ascii.Checked = false;
  191. }
  192. public void ascii_to_hex_radiobuttonConvert()
  193. {
  194. radioButton_ascii.Checked = true;
  195. radioButton_hex.Checked = false;
  196. }
  197. public void Debug_Main_Form_Get(object frm)
  198. {
  199. this.main_form = (Main_Form)frm;
  200. }
  201. }
  202. }