public void set_fastread_flag(OBDIIParameterCode code, bool flag, bool quiet) { if (!quiet) { logger.Debug("Fastread flag of " + code.ToString() + "is enabled."); } content_table[code].FastReadEnable = flag; }
//Communication on 1PID private void communicateOnePID(OBDIIParameterCode code) { //Clean up serial port buffer DiscardInBuffer(); String outMsg; outMsg = MODECODE.ToString("X2") + content_table[code].PID.ToString("X2") + content_table[code].ReturnByteLength.ToString("X1"); Write(outMsg + "\r"); //logger.Debug("ELM327OUT:" + outMsg); String inMsg = ""; try { Int32 returnValue; //inMsg = ReadTo("\r"); // Read to next prompt char of '>' inMsg = ReadTo(">"); // Discard after the char of \r // (discard all after \r) // (This routine is implemented to make countermeasure in the case of multiple message returned. inMsg = discardStringAfterChar(inMsg, '\r'); //logger.Debug("ELM327IN:" + inMsg); inMsg = inMsg.Replace(">", "").Replace("\n", "").Replace("\r", ""); if (inMsg.Equals("")) { return; } //logger.Debug("Filtered ELM327IN:" + inMsg); returnValue = Convert.ToInt32(inMsg.Remove(0, 4), 16); content_table[code].RawValue = returnValue; } catch (TimeoutException ex) { logger.Warn("ELM327COM timeout. " + ex.GetType().ToString() + " " + ex.Message); communicateRealtimeIsError = true; } catch (FormatException ex) { logger.Warn("String conversion to Int32 was failed " + ex.GetType().ToString() + " " + ex.Message + " Received string Is : " + inMsg); //communicateRealtimeIsError = true; } catch (ArgumentOutOfRangeException ex) { logger.Warn("String conversion to Int32 was failed " + ex.GetType().ToString() + " " + ex.Message + " Received string Is : " + inMsg); //communicateRealtimeIsError = true; } }
protected override void processReceivedJSONMessage(string receivedJSONmode, string message, WebSocketSession session) { var sessionparam = (ELM327WebsocketSessionParam)session.Items["Param"]; switch (receivedJSONmode) { //ELM327 COM all reset case (ResetJSONFormat.ModeCode): sessionparam.reset(); send_response_msg(session, "ELM327COM session RESET. All send parameters are disabled."); break; case (ELM327COMReadJSONFormat.ModeCode): ELM327COMReadJSONFormat msg_obj_elm327read = JsonConvert.DeserializeObject <ELM327COMReadJSONFormat>(message); msg_obj_elm327read.Validate(); OBDIIParameterCode target_code = (OBDIIParameterCode)Enum.Parse(typeof(OBDIIParameterCode), msg_obj_elm327read.code); bool flag = msg_obj_elm327read.flag; if (msg_obj_elm327read.read_mode == ELM327COMReadJSONFormat.FastReadModeCode) { sessionparam.FastSendlist[target_code] = flag; } else { sessionparam.SlowSendlist[target_code] = flag; } send_response_msg(session, "EM327COM session read flag for : " + target_code.ToString() + " read_mode :" + msg_obj_elm327read.read_mode + " set to : " + flag.ToString()); break; case (ELM327SLOWREADIntervalJSONFormat.ModeCode): ELM327SLOWREADIntervalJSONFormat msg_obj_interval = JsonConvert.DeserializeObject <ELM327SLOWREADIntervalJSONFormat>(message); msg_obj_interval.Validate(); elm327com.SlowReadInterval = msg_obj_interval.interval; send_response_msg(session, "ELM327COM slowread interval to : " + msg_obj_interval.interval.ToString()); break; default: throw new JSONFormatsException("Unsuppoted mode property."); } }
public void set_fastread_flag(OBDIIParameterCode code, bool flag) { set_fastread_flag(code, flag, false); }
public bool get_fastread_flag(OBDIIParameterCode code) { return(content_table[code].FastReadEnable); }
public bool get_slowread_flag(OBDIIParameterCode code) { return(content_table[code].SlowReadEnable); }
public string get_unit(OBDIIParameterCode code) { return(content_table[code].Unit); }
public Int32 get_raw_value(OBDIIParameterCode code) { return(content_table[code].RawValue); }
public double get_value(OBDIIParameterCode code) { return(content_table[code].Value); }
//Communication on 1PID private void communicateOnePID(OBDIIParameterCode code, int errorRetryCount) { //Clean up serial port buffer DiscardInBuffer(); String outMsg; String outPID = content_table[code].PID.ToString("X2"); int returnByteLength = content_table[code].ReturnByteLength; outMsg = MODECODE.ToString("X2") + outPID + returnByteLength.ToString("X1"); Write(outMsg + "\r"); //logger.Debug("ELM327OUT:" + outMsg); String inMsg = ""; try { Int32 returnValue; //inMsg = ReadTo("\r"); // Read to next prompt char of '>' inMsg = ReadTo(">"); // Discard after the char of \r // (discard all after \r) // (This routine is implemented to make countermeasure in the case of multiple message returned. inMsg = discardStringAfterChar(inMsg, '\r'); //logger.Debug("ELM327IN:" + inMsg); // Get ECU data. inMsg = inMsg.Replace(">", "").Replace("\n", "").Replace("\r", ""); // Check ECU data format. if (inMsg.Equals("")) { throw new FormatException("Return message at communicateOnePID() is empty."); } else if (inMsg.Contains("NO DATA")) { logger.Warn("ELM327 returns NO DATA." + " OutPID :" + outPID + " Code : " + code.ToString()); return; } String inPID = inMsg.Substring(2, 2); if (!inPID.Equals(outPID)) { throw new FormatException("PID return from ELM327 does not match with commanded PID." + "outPID : " + outPID + " inPID :" + inPID); } //logger.Debug("Filtered ELM327IN:" + inMsg); returnValue = Convert.ToInt32(inMsg.Remove(0, 4), 16); content_table[code].RawValue = returnValue; } catch (TimeoutException ex) { logger.Error("ELM327COM timeout. " + ex.GetType().ToString() + " " + ex.Message); communicateRealtimeIsError = true; } catch (FormatException ex) { logger.Warn(ex.GetType().ToString() + " " + ex.Message + " Received string Is : " + inMsg); if (errorRetryCount < PID_COMMUNICATE_RETRY_MAX) { logger.Warn("Retry communication" + " OutPID :" + outPID + " Code : " + code.ToString()); communicateOnePID(code, errorRetryCount + 1); } else { logger.Error("PID communication retry count exceeds maximum (" + PID_COMMUNICATE_RETRY_MAX.ToString() + ")"); communicateRealtimeIsError = true; } } catch (ArgumentOutOfRangeException ex) { logger.Warn(ex.GetType().ToString() + " " + ex.Message + " Received string Is : " + inMsg); if (errorRetryCount < PID_COMMUNICATE_RETRY_MAX) { logger.Warn("Retry communication" + " OutPID :" + outPID + " Code : " + code.ToString()); communicateOnePID(code, errorRetryCount + 1); } else { logger.Error("PID communication retry count exceeds maximum (" + PID_COMMUNICATE_RETRY_MAX.ToString() + ")"); communicateRealtimeIsError = true; } } }
private void communicateOnePID(OBDIIParameterCode code) { this.communicateOnePID(code, 0); }