123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace FPER
- {
- // 현장도면 회로 창 클래스
- public partial class FormDevice : Form
- {
- // 회로번호
- // 예시 : MI010110161
- // 설명 : MI (입력) - 01 (수신기) - 01 (통신보드) - 1 (채널계통) - 016 (중계기) - 1 (포인트)
- public string devID = "";
- // 메인 폼 파라미터
- MDIParent mdi;
- //public int ioType = 0;
- // 생성자
- public FormDevice(MDIParent ParentForm)
- {
- // 컴포넌트 초기화
- InitializeComponent();
- // 메인폼
- this.mdi = ParentForm;
- }
- //public void SetDeviceType(int ioType) {
- // this.ioType = ioType;
- // if (this.ioType == 1) {
- // this.groupBox1.Visible = false;
- // this.button1.Visible = true;
- // }
- // else if (this.ioType == 2) {
- // this.groupBox1.Visible = true;
- // this.button1.Visible = false;
- // }
- // else {
- // this.groupBox1.Visible = false;
- // this.button1.Visible = false;
- // }
- //}
- // 회로 정보 문구 설정
- public void SetDeviceInformText(string txt)
- {
- this.textBox1.Text = txt;
- this.textBox1.Select(0, 0);
- }
- // 회로 상태 문구 설정
- public void SetDeciceStatusText(string txt)
- {
- this.textBox2.Text = txt;
- this.textBox2.Select(0, 0);
- }
- /*
- public void SetDeviceImage(string imgpath) {// 회로 이미지 설정
- if (imgpath != "") {
- Image loadicon = new Bitmap(new Bitmap(imgpath), pictureBox1.Width - 6, pictureBox1.Height - 6);
- this.pictureBox1.Padding = new Padding(3);
- this.pictureBox1.Image = loadicon;
- }
- }
- */
- // 회로 이미지 설정
- public void SetDeviceImage(Image img)
- {
- if (img != null)
- {
- Image loadicon = new Bitmap(new Bitmap(img), pictureBox1.Width - 6, pictureBox1.Height - 6);
- this.pictureBox1.Padding = new Padding(3);
- this.pictureBox1.Image = loadicon;
- }
- }
- // 창 사라지는 타이머
- int hideLevel = 100;
- int hideCount = 0;
- private void timerHide_Tick(object sender, EventArgs e)
- {
- //if (hideLevel < 10) {
- // this.Visible = false;
- //}
- if (this.hideCount >= 300)
- {
- this.Visible = false;
- }
- else if (this.hideCount >= 200)
- {
- this.hideLevel = hideLevel - 5;
- this.Opacity = ((double)hideLevel) / 100.0;
- }
- else
- {
- this.hideCount++;
- }
- this.Update();
- }
- // 보임,안보임 변경 함수
- private void FormDevice_VisibleChanged(object sender, EventArgs e)
- {
- if (this.Visible == true)
- {
- this.hideLevel = 100;
- this.Opacity = 100;
- this.hideCount = 0;
- this.timerHide.Start();
- }
- else
- {
- this.timerHide.Stop();
- }
- }
- // 창 클릭 함수
- private void FormDevice_MouseClick(object sender, MouseEventArgs e)
- {
- this.Visible = false;
- }
- private void FormDevice_Deactivate(object sender, EventArgs e)
- {
- }
- // 입력쓰기 시험 테스트 : ON
- private void button_InputTest_ON_Click(object sender, EventArgs e)
- {
- if (devID == null || devID.Trim().Length == 0)
- MessageBox.Show("디바이스 정보가 없습니다");
- else
- Test_InputTest(true);
- }
- // 입력쓰기 시험 테스트 : OFF
- private void button_InputTest_OFF_Click(object sender, EventArgs e)
- {
- if (devID == null || devID.Trim().Length == 0)
- MessageBox.Show("디바이스 정보가 없습니다");
- else
- Test_InputTest(false);
- }
- // 입력쓰기 시험 테스트 : true 면 on, false 면 off
- private void Test_InputTest(bool OnOff)
- {
- if (MessageBox.Show(string.Format("입력 강제 시험을 하겠습니까? 출력 연동이 될수 있습니다."), "입력 시험", MessageBoxButtons.OKCancel) == DialogResult.OK)
- {
- // 메인폼
- SocketUI ui = mdi.ui;
- // 임시 데이타 (혹시 다른곳에서 접근할지 모르므로 안전하게 치환하여 사용함)
- string temp_devID = devID;
- // 수신기 아이디
- int Receive_ID = int.Parse(temp_devID.Substring(2, 2));
- // 통신보드 아이디
- int Board_ID = int.Parse(temp_devID.Substring(4, 2));
- // 채널계통 번호
- int Loop_No = int.Parse(temp_devID.Substring(6, 1));
- // 중계기 아이디
- int Repeater_ID = int.Parse(temp_devID.Substring(7, 3));
- // 포인트 아이디
- int Device_ID = int.Parse(devID.Substring(10, 1));
- // 포트번호 아이디
- int CommID = 1;
- //명령생성 및 실행
- //중계기 설정 데이터를 CmdInfo에 넣어준다..
- CmdInfo cmd = new CmdInfo(
- prt_cmd_define.write_repeater_input_unit,
- mdi.myReceiverID,
- CommID,
- Loop_No,
- Board_ID,
- Repeater_ID,
- null);
- // 장치별로 감지하는
- switch (Device_ID)
- {
- case 1:
- if (OnOff == true)
- cmd.CommandData = (byte)0xFC; // 1111 1100
- else
- cmd.CommandData = (byte)0xFF; // 1111 1111
- break;
- case 2:
- if (OnOff == true)
- cmd.CommandData = (byte)0xF3; // 1111 0011
- else
- cmd.CommandData = (byte)0xF1; // 1111 0001
- break;
- case 3:
- if (OnOff == true)
- cmd.CommandData = (byte)0xCF; // 1100 1111
- else
- cmd.CommandData = (byte)0xDF; // 1101 1111
- break;
- case 4:
- if (OnOff == true)
- cmd.CommandData = (byte)0x3F; // 0011 1111
- else
- cmd.CommandData = (byte)0x7F; // 0111 1111
- break;
- }
- // 실제 패킷
- ui.runCommand(cmd);
- }
- }
- }
- }
|