Debug.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. int LineLimit = 500;
  17. [DllImport("user32.dll")]
  18. public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
  19. private const int WM_SETREDRAW = 11;
  20. Serial serial;
  21. public RadioButton RadioButton_ascii { get => radioButton_ascii; set => radioButton_ascii = value; }
  22. public RadioButton RadioButton_hex { get => radioButton_hex; set => radioButton_hex = value; }
  23. public Debug()
  24. {
  25. InitializeComponent();
  26. }
  27. #if true
  28. public void Data_Recv_Str(string text)
  29. {
  30. int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
  31. try
  32. {
  33. try
  34. {
  35. SendMessage(this.Handle, WM_SETREDRAW, false, 0);
  36. }
  37. catch (Exception e) { MessageBox.Show(e.StackTrace); }
  38. if (tbReceived.Lines.Length > nLimitLines)
  39. {
  40. LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
  41. while ((tempLines.Count - nLimitLines) > 0)
  42. {
  43. tempLines.RemoveFirst();
  44. }
  45. tbReceived.Lines = tempLines.ToArray();
  46. }
  47. try
  48. {
  49. SendMessage(this.Handle, WM_SETREDRAW, true, 0);
  50. }
  51. catch { return; }
  52. tbReceived.AppendText(text);
  53. tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택...
  54. tbReceived.ScrollToCaret();
  55. }
  56. catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
  57. }
  58. #endif
  59. #if false
  60. public void Data_Recv_Hex(byte[] text)
  61. {
  62. int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
  63. try
  64. {
  65. try
  66. {
  67. SendMessage(this.Handle, WM_SETREDRAW, false, 0);
  68. }
  69. catch (Exception e) { MessageBox.Show(e.StackTrace); }
  70. if (tbReceived.Lines.Length > nLimitLines)
  71. {
  72. LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
  73. while ((tempLines.Count - nLimitLines) > 0)
  74. {
  75. tempLines.RemoveFirst();
  76. }
  77. tbReceived.Lines = tempLines.ToArray();
  78. }
  79. try
  80. {
  81. SendMessage(this.Handle, WM_SETREDRAW, true, 0);
  82. }
  83. catch { return; }
  84. tbReceived.AppendText(text.ToString());
  85. tbReceived.SelectionStart = tbReceived.Text.Length;//맨 마지막 선택...
  86. tbReceived.ScrollToCaret();
  87. }
  88. catch { try { SendMessage(this.Handle, WM_SETREDRAW, true, 0); } catch { return; } }
  89. }
  90. #endif
  91. public void Data_Send(byte[] text)
  92. {
  93. string AppendMessage = "\n[TX]";
  94. int nLimitLines = Convert.ToInt32(LineLimit); //제한 라인 수
  95. try
  96. {
  97. for (int i = 0; i < text.Length; i++)
  98. {
  99. AppendMessage += Convert.ToString(text[i], 16);
  100. }
  101. tbReceived.AppendText(AppendMessage);
  102. try
  103. {
  104. SendMessage(this.Handle, WM_SETREDRAW, false, 0);
  105. }
  106. catch { return; }
  107. if (tbReceived.Lines.Length > nLimitLines)
  108. {
  109. LinkedList<string> tempLines = new LinkedList<string>(tbReceived.Lines);
  110. while ((tempLines.Count - nLimitLines) > 0)
  111. {
  112. tempLines.RemoveFirst();
  113. }
  114. tbReceived.Lines = tempLines.ToArray();
  115. }
  116. try
  117. {
  118. SendMessage(this.Handle, WM_SETREDRAW, true, 0);
  119. }
  120. catch { return; }
  121. tbReceived.Select(tbReceived.Text.Length, 0);
  122. tbReceived.ScrollToCaret();
  123. }
  124. finally { }
  125. }
  126. public void Serial_ClassSet(object serial)
  127. {
  128. this.serial = (Serial)serial;
  129. }
  130. private void Button_Send_Click(object sender, EventArgs e)
  131. {
  132. try
  133. {
  134. this.serial.Serial_DataSend(Encoding.ASCII.GetBytes(textBox_senddata.Text));
  135. }
  136. catch (System.Exception ex)
  137. {
  138. MessageBox.Show(ex.Message);
  139. }
  140. }
  141. private void Button_Clear_Click(object sender, EventArgs e)
  142. {
  143. try
  144. {
  145. this.tbReceived.Text = "";
  146. }
  147. finally { }
  148. }
  149. public void hex_to_ascii_radiobuttonConvert()
  150. {
  151. radioButton_hex.Checked = true;
  152. radioButton_ascii.Checked = false;
  153. }
  154. public void ascii_to_hex_radiobuttonConvert()
  155. {
  156. radioButton_ascii.Checked = true;
  157. radioButton_hex.Checked = false;
  158. }
  159. }
  160. }