Debug.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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_Send(byte[] text)
  93. {
  94. string AppendMessage = "\n[TX]";
  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. finally { }
  126. }
  127. public void Serial_ClassSet(object serial)
  128. {
  129. this.serial = (Serial)serial;
  130. }
  131. private void Button_Send_Click(object sender, EventArgs e)
  132. {
  133. try
  134. {
  135. this.serial.Serial_DataSend(Encoding.ASCII.GetBytes(textBox_senddata.Text));
  136. }
  137. catch (System.Exception ex)
  138. {
  139. MessageBox.Show(ex.Message);
  140. }
  141. }
  142. private void Button_Clear_Click(object sender, EventArgs e)
  143. {
  144. try
  145. {
  146. this.tbReceived.Text = "";
  147. }
  148. finally { }
  149. }
  150. public void hex_to_ascii_radiobuttonConvert()
  151. {
  152. radioButton_hex.Checked = true;
  153. radioButton_ascii.Checked = false;
  154. }
  155. public void ascii_to_hex_radiobuttonConvert()
  156. {
  157. radioButton_ascii.Checked = true;
  158. radioButton_hex.Checked = false;
  159. }
  160. public void Debug_Main_Form_Get(object frm)
  161. {
  162. this.main_form = (Main_Form)frm;
  163. }
  164. }
  165. }