- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading;
- using UnityEngine;
- using UnityEngine.UI;
- public enum NetworkStatus { None, Conn, DisConn };
- public class SocketClilent : MonoBehaviour
- {
- private string IP = "121.151.150.167";
- private int PORT = 15064;
- //private string IP = "127.0.0.1";
- //private int PORT = 6000;
- private Thread thread = null;
- private NetworkStream writeStream;
- private StreamReader readerStream;
- private string QUIT = "q\r\n";
- public TcpClient client = null;
- public NetworkStatus NetworkStatusEvent = NetworkStatus.None;
- public PopupWindow popupWindow;
- public UnityEngine.UI.Text NetState;
- public UnityEngine.UI.InputField IP_Input;
- public UnityEngine.UI.InputField Port_Input;
- public string msg = "camonitorall\r\n";
- private object lockObject = new object();
- private void Start()
- {
- IP_Input.text = IP;
- Port_Input.text = PORT.ToString();
- NetState.text = "DISCONNECTED";
- NetState.color = Color.red;
- }
- private void Update()
- {
- if (NetworkStatusEvent == NetworkStatus.DisConn)
- {
- NetState.text = "DISCONNECTED";
- NetState.color = Color.red;
- NetworkStatusEvent = NetworkStatus.None;
- }
- }
- public void ConnectToServer()
- {
- try
- {
- if (client != null)
- {
- popupWindow.PopupWindowOpen(PopupWindow.MsgType.warning, "이미 연결되어 있습니다.");
- return;
- }
- IP = IP_Input.text;
- if (!int.TryParse(Port_Input.text, out PORT))
- popupWindow.PopupWindowOpen(PopupWindow.MsgType.warning, "유효한 숫자가 아닙니다.");
- client = new TcpClient();
- client.Connect(IP, PORT);
- writeStream = client.GetStream();
- NetState.text = "CONNECTED";
- NetState.color = Color.green;
- NetworkStatusEvent = NetworkStatus.Conn;
- Encoding encode = System.Text.Encoding.UTF8;
- readerStream = new StreamReader(writeStream, encode);
- thread = new Thread(new ThreadStart(Run));
- thread.Start();
- }
- catch (Exception e)
- {
- popupWindow.PopupWindowOpen(PopupWindow.MsgType.error, e.Message);
- DisConnect();
- }
- }
- public void DisConnect()
- {
- if (client == null)
- return;
- NetworkStatusEvent = NetworkStatus.DisConn;
- try
- {
- byte[] quit = Encoding.Default.GetBytes(QUIT);
- writeStream.Write(quit, 0, quit.Length);
- }
- catch (Exception e)
- {
- }
- if (writeStream != null)
- {
- writeStream.Close();
- }
- if (readerStream != null)
- {
- readerStream.Close();
- }
- if (client != null)
- {
- client.Close();
- client = null;
- }
- if (thread != null)
- {
- thread.Abort();
- thread = null;
- }
- }
- public void Run()
- {
- byte[] RequestData = Encoding.Default.GetBytes(msg);
- writeStream.Write(RequestData, 0, RequestData.Length);
- while (true)
- {
- try
- {
- string str = readerStream.ReadLine();
- if (str != null)
- {
- //데이터 파싱 부분 추가
- DataParsing(str);
- }
- else
- {
- break;
- }
- }
- catch (Exception e)
- {
- break;
- }
- }
- DisConnect();
- }
- public void OnApplicationQuit()
- {
- DisConnect();
- }
- //DataPaser 함수 붙이고
- public void DataParsing(string data)
- {
- if (splitData != null && splitData.Length > 3)
- {
- float v;
- if (!float.TryParse(splitData[3], out v))
- {
- return;
- }
- //Debug.Log("data : " + data);
- if (DataType.Length < 3)
- return;
- lock (lockObject)
- {
- if (DataType[1] == "AWS")
- {
- switch (DataType[2])
- {
- case "WINDIR":
- AWS.WINDIR = v;
- break;
- case "WINSPEED":
- //Debug.Log(v);
- AWS.WINSPEED = v;
- break;
- case "TMP":
- AWS.TMP = v;
- break;
- case "HUM":
- AWS.HUM = v;
- break;
- case "RAD":
- AWS.RAD = v;
- break;
- case "RAIN":
- AWS.RAIN = v;
- break;
- default:
- break;
- }
- }
- else if (DataType[1] == "PM10_1")
- {
- switch (DataType[2])
- {
- case "DUST_MASS_CON":
- PM10_1.DUST_MASS_CON = v;
- break;
- //case "BETA_CON":
- // PM10.BETA_CON = v;
- // break;
- //case "HALF_H_AVG":
- // PM10.HALF_H_AVG = v;
- // break;
- case "1H_AVG":
- PM10_1.H1_AVG = v;
- break;
- //case "3H_AVG":
- // PM10.H3_AVG = v;
- // break;
- //case "24H_AVG":
- // PM10.H24_AVG = v;
- // break;
- //case "HEAD_TMP":
- // PM10.HEAD_TMP = v;
- // break;
- //case "CHAMBER_TMP":
- // PM10.CHAMBER_TMP = v;
- // break;
- //case "ORIFICE_TMP":
- // PM10.ORIFICE_TMP = v;
- // break;
- //case "TUBE_TMP":
- // PM10.TUBE_TMP = v;
- // break;
- //case "DIFF_PRESS":
- // PM10.DIFF_PRESS = v;
- // break;
- //case "SUC_CHAMBER_PRESS":
- // PM10.SUC_CHAMBER_PRESS = v;
- // break;
- //case "BARO_PRESS":
- // PM10.BARO_PRESS = v;
- // break;
- //case "HEAD_FLOW":
- // PM10.HEAD_FLOW = v;
- // break;
- //case "NORM_FLOW":
- // PM10.NORM_FLOW = v;
- // break;
- //case "FLOW_RATE":
- // PM10.FLOW_RATE = v;
- // break;
- //case "HEATING_POWER":
- // PM10.HEATING_POWER = v;
- // break;
- //case "REL_HUM":
- // PM10.REL_HUM = v;
- // break;
- //case "RAW_MASS":
- // PM10.RAW_MASS = v;
- // break;
- //case "RC_MASS":
- // PM10.RC_MASS = v;
- // break;
- //case "QLOCK_MASS":
- // PM10.QLOCK_MASS = v;
- // break;
- //case "DENSITY_CMP":
- // PM10.DENSITY_CMP = v;
- // break;
- //case "COMM_ERR_CNT":
- // PM10.COMM_ERR_CNT = v;
- // break;
- //case "BETA_CNT_RATE":
- // PM10.BETA_CNT_RATE = v;
- // break;
- //case "ALPHA_CNT_RATE":
- // PM10.ALPHA_CNT_RATE = v;
- // break;
- //case "AZ_CNT_RATE":
- // PM10.AZ_CNT_RATE = v;
- // break;
- //case "BZ_CNT_RATE":
- // PM10.BZ_CNT_RATE = v;
- // break;
- //case "NAA_FILTER":
- // PM10.NAA_FILTER = v;
- // break;
- //case "RADON_CON":
- // PM10.RADON_CON = v;
- // break;
- //case "LPF_BETA_CON":
- // PM10.LPF_BETA_CON = v;
- // break;
- //case "LPF_OPT_CON":
- // PM10.LPF_OPT_CON = v;
- // break;
- default:
- break;
- }
- }
- else if (DataType[1] == "PM10_2")
- {
- switch (DataType[2])
- {
- case "DUST_MASS_CON":
- PM10_2.DUST_MASS_CON = v;
- break;
- case "1H_AVG":
- PM10_2.H1_AVG = v;
- break;
- default:
- break;
- }
- }
- else if (DataType[1] == "PM10_3")
- {
- switch (DataType[2])
- {
- case "DUST_MASS_CON":
- PM10_3.DUST_MASS_CON = v;
- break;
- case "1H_AVG":
- PM10_3.H1_AVG = v;
- break;
- default:
- break;
- }
- }
- else if (DataType[1] == "PM10_4")
- {
- switch (DataType[2])
- {
- case "DUST_MASS_CON":
- PM10_4.DUST_MASS_CON = v;
- break;
- case "1H_AVG":
- PM10_4.H1_AVG = v;
- break;
- default:
- break;
- }
- }
- else if (DataType[1] == "CNN_1")
- {
- switch (DataType[2])
- {
- case "STS_RUN":
- CNN_1.STS_RUN = v.ToString();
- break;
- case "RB_PWATER":
- CNN_1.RB_PWATER = v;
- break;
- case "RB_TWATER":
- CNN_1.RB_TWATER = v;
- break;
- //0530 새로 추가
- //컨트롤러에 받을 데이터
- case "RB_CNN_POS":
- CNN_1.RB_CNN_POS = v;
- break;
- case "RB_CNN_START_ANG":
- CNN_1.RB_CNN_START_ANG = v;
- break;
- case "RB_CNN_STOP_ANG":
- CNN_1.RB_CNN_STOP_ANG = v;
- break;
- //0530 새로 추가
- }
- }
- else if (DataType[1] == "CNN_2")
- {
- switch (DataType[2])
- {
- case "STS_RUN":
- CNN_2.STS_RUN = v.ToString();
- break;
- case "RB_PWATER":
- CNN_2.RB_PWATER = v;
- break;
- case "RB_TWATER":
- CNN_2.RB_TWATER = v;
- break;
- // 0530 새로 추가
- //컨트롤러에 받을 데이터
- case "RB_CNN_POS":
- CNN_2.RB_CNN_POS = v;
- break;
- case "RB_CNN_START_ANG":
- CNN_2.RB_CNN_START_ANG = v;
- break;
- case "RB_CNN_STOP_ANG":
- CNN_2.RB_CNN_STOP_ANG = v;
- break;
- //0530 새로 추가
- }
- }
- else if (DataType[1] == "MES")
- {
- switch (DataType[2])
- {
- case "STATUS_01":
- MES.STATUS_01 = v.ToString();
- break;
- case "STATUS_02":
- MES.STATUS_02 = v.ToString();
- break;
- case "STATUS_03":
- MES.STATUS_03 = v.ToString();
- break;
- case "STATUS_04":
- MES.STATUS_04 = v.ToString();
- break;
- case "STATUS_05":
- MES.STATUS_05 = v.ToString();
- break;
- case "STATUS_14":
- MES.STATUS_14 = v.ToString();
- break;
- case "POS_01":
- MES.POS_01 = (int)v;
- break;
- case "POS_02":
- MES.POS_02 = (int)v;
- break;
- case "POS_03":
- MES.POS_03 = (int)v;
- break;
- case "POS_04":
- MES.POS_04 = (int)v;
- break;
- case "POS_05":
- MES.POS_05 = (int)v;
- break;
- case "POS_14":
- MES.POS_14 = (int)v;
- break;
- }
- }
- }
- }
- }
- }
2020년 1월 7일 화요일
연결 SocketClient 와 dataParsing
피드 구독하기:
댓글 (Atom)
git rejected error(feat. cherry-pick)
문제 아무 생각 없이 pull을 받지않고 로컬에서 작업! 커밋, 푸시 진행을 해버렷다. push에선 remote와 다르니 당연히 pull을 진행해라고 하지만 로컬에서 작업한 내용을 백업하지 않고 진행하기에는 부담스럽다(로컬작업 유실 가능성) 해결하려...
-
/// < summary > /// 검색 조건과 내용으로 테이블에 있는 데이터를 검색하는 메서드 /// </ summary > /// < param name = "valu...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ...
-
해결책 서비스 > application layer Gateway Service 를 한번 실행해주면 엉킨포트가 풀리는지 어떤지 모르겠지만 된다 포트가 풀린것 확인하려면 명령프롬프트창에 netstat -n 명령을 넣어서 확인할 수 있다...
댓글 없음:
댓글 쓰기