public MainForm() { Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal; InitializeComponent(); _rootFolder = Properties.Settings.Default.RootFolder; string appDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); if (!string.IsNullOrEmpty(appDir)) { if (string.IsNullOrEmpty(_rootFolder) || !Directory.Exists(_rootFolder)) { _rootFolder = appDir; } } _responseDir = _rootFolder; _lastPortCount = -1; _configData = new CommThread.ConfigData(); UpdateDirectoryList(_rootFolder); UpdateResponseFiles(_responseDir); _commThread = new CommThread(); UpdatePorts(); timerUpdate.Enabled = true; UpdateDisplay(); }
private bool SendBmwfast(byte[] sendData) { if (_dataStream == null) { return(false); } byte[] telBuffer = new byte[sendData.Length + 1]; Array.Copy(sendData, telBuffer, sendData.Length); int sendLength = telBuffer[0] & 0x3F; if (sendLength == 0) { // with length byte sendLength = telBuffer[3] + 4; } else { sendLength += 3; } telBuffer[sendLength] = CommThread.CalcChecksumBmwFast(telBuffer, sendLength); sendLength++; try { _dataStream.Write(telBuffer, 0, sendLength); } catch (Exception) { return(false); } return(true); }
private bool BmwFastTest(bool lline = false) { byte[] identRequest = { 0x82, 0x12, 0xF1, 0x1A, 0x80 }; byte[] identResponse = { 0xBC, 0xF1, 0x12, 0x5A, 0x80, 0x00, 0x00, 0x07, 0x80, 0x81, 0x25, 0x00, 0x00, 0x00, 0x12, 0x4C, 0x50, 0x20, 0x08, 0x02, 0x15, 0x08, 0x08, 0x02, 0x30, 0x39, 0x34, 0x37, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x79, 0x51, 0x46, 0x31, 0x65, 0x57, 0x28, 0x30, 0x30, 0x38, 0x39, 0x51, 0x39, 0x30, 0x30, 0x30, 0x38, 0x39, 0x51, 0x39, 0x30, 0x41, 0x39, 0x34, 0x37, 0x42 }; if (lline) { byte[] sendTel = new byte[identRequest.Length + 1]; Array.Copy(identRequest, sendTel, identRequest.Length); sendTel[sendTel.Length - 1] = CommThread.CalcChecksumBmwFast(sendTel, sendTel.Length - 1); byte[] adapterTel = CreateAdapterTelegram(sendTel, sendTel.Length, 10400, KLINEF1_PARITY_NONE, true); try { _dataStream.Write(adapterTel, 0, adapterTel.Length); } catch (Exception) { return(false); } } else { if (!SendBmwfast(identRequest)) { return(false); } } byte[] response = new byte[0x100]; if (!lline) { // receive echo int echoLength = ReceiveBmwFast(response); if (echoLength != identRequest.Length) { return(false); } } int dataLength = ReceiveBmwFast(response); if (dataLength != identResponse.Length) { return(false); } return(!identResponse.Where((t, i) => response[i] != t).Any()); }
public void PostAdditionalInfo(DataObject data) { Status = ServerStatus.Starting; StopPost(); WorkerThread = new CommThread(this, data); WorkerThread.Name = "AddInfoThread"; WorkerThread.PostType = PostType.AdditionalInformation; WorkerThread.Start(); }
public void PostAnalysis(DataObject data) { Status = ServerStatus.Starting; StopPost(); WorkerThread = new CommThread(this, data); WorkerThread.Name = "PostAnalysisThread"; WorkerThread.PostType = PostType.Analysis; WorkerThread.Start(); }
private byte[] CreateAdapterTelegram(byte[] sendData, int length, int baudRate, byte parity, bool useLline) { byte telType = 0x02; byte[] resultArray = new byte[length + ((telType == 0x00) ? 9 : 11)]; resultArray[0] = 0x00; // header resultArray[1] = telType; // telegram type uint baudHalf; byte flags1 = KLINEF1_NO_ECHO; if (baudRate == 115200) { baudHalf = 0; } else { baudHalf = (uint)(baudRate >> 1); if (useLline) { flags1 |= KLINEF1_USE_LLINE; } flags1 |= parity; } byte flags2 = 0x00; //flags2 |= KLINEF2_KWP1281_DETECT; resultArray[2] = (byte)(baudHalf >> 8); // baud rate / 2 high resultArray[3] = (byte)baudHalf; // baud rate / 2 low resultArray[4] = flags1; // flags 1 if (telType == 0x00) { resultArray[5] = 0x00; // interbyte time resultArray[6] = (byte)(length >> 8); // telegram length high resultArray[7] = (byte)length; // telegram length low Array.Copy(sendData, 0, resultArray, 8, length); resultArray[resultArray.Length - 1] = CommThread.CalcChecksumBmwFast(resultArray, resultArray.Length - 1); } else { resultArray[5] = flags2; // flags 2 resultArray[6] = 0x00; // interbyte time resultArray[7] = KWP1281_TIMEOUT; // KWP1281 timeout resultArray[8] = (byte)(length >> 8); // telegram length high resultArray[9] = (byte)length; // telegram length low Array.Copy(sendData, 0, resultArray, 10, length); resultArray[resultArray.Length - 1] = CommThread.CalcChecksumBmwFast(resultArray, resultArray.Length - 1); } return(resultArray); }
private int ReceiveBmwFast(byte[] receiveData) { if (_dataStream == null) { return(0); } try { // header byte _dataStream.ReadTimeout = 2000; for (int i = 0; i < 4; i++) { int data; try { data = _dataStream.ReadByte(); } catch (Exception) { data = -1; } if (data < 0) { while (_dataStream.DataAvailable) { try { _dataStream.ReadByte(); } catch (Exception) { break; } } return(0); } receiveData[i] = (byte)data; } if ((receiveData[0] & 0x80) != 0x80) { // 0xC0: Broadcast while (_dataStream.DataAvailable) { try { _dataStream.ReadByte(); } catch (Exception) { break; } } return(0); } int recLength = receiveData[0] & 0x3F; if (recLength == 0) { // with length byte recLength = receiveData[3] + 4; } else { recLength += 3; } for (int i = 0; i < recLength - 3; i++) { int data; try { data = _dataStream.ReadByte(); } catch (Exception) { data = -1; } if (data < 0) { while (_dataStream.DataAvailable) { try { _dataStream.ReadByte(); } catch (Exception) { break; } } return(0); } receiveData[i + 4] = (byte)data; } if (CommThread.CalcChecksumBmwFast(receiveData, recLength) != receiveData[recLength]) { while (_dataStream.DataAvailable) { try { _dataStream.ReadByte(); } catch (Exception) { break; } } return(0); } return(recLength); } catch (Exception) { return(0); } }