概要
elm327の研究やってみた。
練習問題やってみた。
練習問題
c#で、ELM327のエミュレータを書け。
サンプルコード
using System;
using System.IO.Ports;
using System.Threading;
using System.Globalization;
public class ELM327 {
public string talk(string a) {
string res = "";
string ans = "4" + a.Substring(1, 2) + " ";
if (a.Substring(0, 3) == "ATZ")
res += "ELM327 v1.4";
else if (a.Substring(0, 2) == "AT")
res += "OK";
else if (a.Substring(0, 5) == "01 00")
res += "41 00 FF FF FC FF";
else if (a.Substring(0, 5) == "01 01")
res += "41 01 84 07 61 00";
else if (a.Substring(0, 5) == "01 20")
res += "41 20 FF FF FC FF";
else if (a.Substring(0, 5) == "01 40")
res += "41 40 FF FF FC FF";
else if (a.Substring(0, 5) == "01 60")
res += "41 60 FF FF FC FF";
else if (a.Substring(0, 5) == "01 80")
res += "41 80 FF FF FC FF";
else if (a.Substring(0, 5) == "01 A0")
res += "41 A0 FF FF FC FF";
else if (a.Substring(0, 5) == "01 C0")
res += "41 C0 FF FF FC FF";
else if (a.Substring(0, 2) == "01")
res += ans + "00 00 00 00";
else if (a.Substring(0, 2) == "03")
res += "43 03 00 03 01 03\r\n43 13 01 04";
else if (a.Substring(0, 5) == "09 02")
res += "49 02 1Z3768470804";
else
{
res += ans + " NO DATA\n";
}
return res;
}
}
public class Program {
public static void Main() {
var elm = new ELM327();
bool flg = true;
while (flg)
{
string a;
Console.Write(">");
a = Console.ReadLine();
var len = a.Length;
if (a == "")
flg = false;
Console.WriteLine(elm.talk(a));
}
Console.WriteLine("bai!");
}
}
実行結果
>elm1
>ATZ
ELM327 v1.4
>01 00
41 00 FF FF FC FF
>01 22
41 00 00 00 00
以上。