Debug.cs 7.7 KB

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