/// <summary> /// Initialize ELM327COM websocket client. /// </summary> /// <param name="url">URL of the server.</param> /// <param name="codes">Parameter code list</param> /// <returns></returns> private WebSocket initializeELM327COMWSClient(string url, List <OBDIIParameterCode> codes) { if (codes.Count == 0) { return(null); } const WebSocketType WSType = WebSocketType.ELM327; WebSocket wsClient = new WebSocket(url); wsClient.Opened += (sender, e) => { foreach (OBDIIParameterCode code in codes) { // Send read packet both slow and fast readmode. ELM327COMReadJSONFormat sendcode = new ELM327COMReadJSONFormat(); sendcode.code = code.ToString(); sendcode.read_mode = ELM327COMReadJSONFormat.SlowReadModeCode; sendcode.flag = true; wsClient.Send(sendcode.Serialize()); sendcode.read_mode = ELM327COMReadJSONFormat.FastReadModeCode; wsClient.Send(sendcode.Serialize()); } }; wsClient.Error += (sender, e) => wsErrorMsg(WSType.ToString(), e.Exception.ToString(), e.Exception.Message); wsClient.Closed += (sender, e) => wsClosedReconnect(WSType.ToString(), wsClient); wsClient.MessageReceived += (sender, e) => parseVALMessage(e.Message, WSType); return(wsClient); }
/// <summary> /// Initialize ArduinoCOM websocket client /// </summary> /// <param name="url">URL of the server</param> /// <param name="codes">parameter code list to activate</param> /// <returns></returns> private WebSocket initializeArduinoCOMWSClient(string url, List <ArduinoParameterCode> codes) { if (codes.Count == 0) { return(null); } const WebSocketType WSType = WebSocketType.ARDUINO; WebSocket wsClient = new WebSocket(url); wsClient.Opened += (sender, e) => { foreach (ArduinoParameterCode code in codes) { ArduinoWSSendJSONFormat sendcode = new ArduinoWSSendJSONFormat(); sendcode.code = code.ToString(); sendcode.flag = true; ArduinoWSIntervalJSONFormat definitervalcode = new ArduinoWSIntervalJSONFormat(); definitervalcode.interval = DEFI_ARDUINO_PACKET_INTERVAL; wsClient.Send(sendcode.Serialize()); wsClient.Send(definitervalcode.Serialize()); } }; wsClient.Error += (sender, e) => wsErrorMsg(WSType.ToString(), e.Exception.ToString(), e.Exception.Message); wsClient.Closed += (sender, e) => wsClosedReconnect(WSType.ToString(), wsClient); wsClient.MessageReceived += (sender, e) => parseVALMessage(e.Message, WSType); return(wsClient); }