FormDevice.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace FPER
  9. {
  10. // 현장도면 회로 창 클래스
  11. public partial class FormDevice : Form
  12. {
  13. // 회로번호
  14. // 예시 : MI010110161
  15. // 설명 : MI (입력) - 01 (수신기) - 01 (통신보드) - 1 (채널계통) - 016 (중계기) - 1 (포인트)
  16. public string devID = "";
  17. // 메인 폼 파라미터
  18. MDIParent mdi;
  19. //public int ioType = 0;
  20. // 생성자
  21. public FormDevice(MDIParent ParentForm)
  22. {
  23. // 컴포넌트 초기화
  24. InitializeComponent();
  25. // 메인폼
  26. this.mdi = ParentForm;
  27. }
  28. //public void SetDeviceType(int ioType) {
  29. // this.ioType = ioType;
  30. // if (this.ioType == 1) {
  31. // this.groupBox1.Visible = false;
  32. // this.button1.Visible = true;
  33. // }
  34. // else if (this.ioType == 2) {
  35. // this.groupBox1.Visible = true;
  36. // this.button1.Visible = false;
  37. // }
  38. // else {
  39. // this.groupBox1.Visible = false;
  40. // this.button1.Visible = false;
  41. // }
  42. //}
  43. // 회로 정보 문구 설정
  44. public void SetDeviceInformText(string txt)
  45. {
  46. this.textBox1.Text = txt;
  47. this.textBox1.Select(0, 0);
  48. }
  49. // 회로 상태 문구 설정
  50. public void SetDeciceStatusText(string txt)
  51. {
  52. this.textBox2.Text = txt;
  53. this.textBox2.Select(0, 0);
  54. }
  55. /*
  56. public void SetDeviceImage(string imgpath) {// 회로 이미지 설정
  57. if (imgpath != "") {
  58. Image loadicon = new Bitmap(new Bitmap(imgpath), pictureBox1.Width - 6, pictureBox1.Height - 6);
  59. this.pictureBox1.Padding = new Padding(3);
  60. this.pictureBox1.Image = loadicon;
  61. }
  62. }
  63. */
  64. // 회로 이미지 설정
  65. public void SetDeviceImage(Image img)
  66. {
  67. if (img != null)
  68. {
  69. Image loadicon = new Bitmap(new Bitmap(img), pictureBox1.Width - 6, pictureBox1.Height - 6);
  70. this.pictureBox1.Padding = new Padding(3);
  71. this.pictureBox1.Image = loadicon;
  72. }
  73. }
  74. // 창 사라지는 타이머
  75. int hideLevel = 100;
  76. int hideCount = 0;
  77. private void timerHide_Tick(object sender, EventArgs e)
  78. {
  79. //if (hideLevel < 10) {
  80. // this.Visible = false;
  81. //}
  82. if (this.hideCount >= 300)
  83. {
  84. this.Visible = false;
  85. }
  86. else if (this.hideCount >= 200)
  87. {
  88. this.hideLevel = hideLevel - 5;
  89. this.Opacity = ((double)hideLevel) / 100.0;
  90. }
  91. else
  92. {
  93. this.hideCount++;
  94. }
  95. this.Update();
  96. }
  97. // 보임,안보임 변경 함수
  98. private void FormDevice_VisibleChanged(object sender, EventArgs e)
  99. {
  100. if (this.Visible == true)
  101. {
  102. this.hideLevel = 100;
  103. this.Opacity = 100;
  104. this.hideCount = 0;
  105. this.timerHide.Start();
  106. }
  107. else
  108. {
  109. this.timerHide.Stop();
  110. }
  111. }
  112. // 창 클릭 함수
  113. private void FormDevice_MouseClick(object sender, MouseEventArgs e)
  114. {
  115. this.Visible = false;
  116. }
  117. private void FormDevice_Deactivate(object sender, EventArgs e)
  118. {
  119. }
  120. // 입력쓰기 시험 테스트 : ON
  121. private void button_InputTest_ON_Click(object sender, EventArgs e)
  122. {
  123. if (devID == null || devID.Trim().Length == 0)
  124. MessageBox.Show("디바이스 정보가 없습니다");
  125. else
  126. Test_InputTest(true);
  127. }
  128. // 입력쓰기 시험 테스트 : OFF
  129. private void button_InputTest_OFF_Click(object sender, EventArgs e)
  130. {
  131. if (devID == null || devID.Trim().Length == 0)
  132. MessageBox.Show("디바이스 정보가 없습니다");
  133. else
  134. Test_InputTest(false);
  135. }
  136. // 입력쓰기 시험 테스트 : true 면 on, false 면 off
  137. private void Test_InputTest(bool OnOff)
  138. {
  139. if (MessageBox.Show(string.Format("입력 강제 시험을 하겠습니까? 출력 연동이 될수 있습니다."), "입력 시험", MessageBoxButtons.OKCancel) == DialogResult.OK)
  140. {
  141. // 메인폼
  142. SocketUI ui = mdi.ui;
  143. // 임시 데이타 (혹시 다른곳에서 접근할지 모르므로 안전하게 치환하여 사용함)
  144. string temp_devID = devID;
  145. // 수신기 아이디
  146. int Receive_ID = int.Parse(temp_devID.Substring(2, 2));
  147. // 통신보드 아이디
  148. int Board_ID = int.Parse(temp_devID.Substring(4, 2));
  149. // 채널계통 번호
  150. int Loop_No = int.Parse(temp_devID.Substring(6, 1));
  151. // 중계기 아이디
  152. int Repeater_ID = int.Parse(temp_devID.Substring(7, 3));
  153. // 포인트 아이디
  154. int Device_ID = int.Parse(devID.Substring(10, 1));
  155. // 포트번호 아이디
  156. int CommID = 1;
  157. //명령생성 및 실행
  158. //중계기 설정 데이터를 CmdInfo에 넣어준다..
  159. CmdInfo cmd = new CmdInfo(
  160. prt_cmd_define.write_repeater_input_unit,
  161. mdi.myReceiverID,
  162. CommID,
  163. Loop_No,
  164. Board_ID,
  165. Repeater_ID,
  166. null);
  167. // 장치별로 감지하는
  168. switch (Device_ID)
  169. {
  170. case 1:
  171. if (OnOff == true)
  172. cmd.CommandData = (byte)0xFC; // 1111 1100
  173. else
  174. cmd.CommandData = (byte)0xFF; // 1111 1111
  175. break;
  176. case 2:
  177. if (OnOff == true)
  178. cmd.CommandData = (byte)0xF3; // 1111 0011
  179. else
  180. cmd.CommandData = (byte)0xF1; // 1111 0001
  181. break;
  182. case 3:
  183. if (OnOff == true)
  184. cmd.CommandData = (byte)0xCF; // 1100 1111
  185. else
  186. cmd.CommandData = (byte)0xDF; // 1101 1111
  187. break;
  188. case 4:
  189. if (OnOff == true)
  190. cmd.CommandData = (byte)0x3F; // 0011 1111
  191. else
  192. cmd.CommandData = (byte)0x7F; // 0111 1111
  193. break;
  194. }
  195. // 실제 패킷
  196. ui.runCommand(cmd);
  197. }
  198. }
  199. }
  200. }