public int setWifiMode(wifiMode mode, int timeoutMs = 50) { byte[] toSend = MakeByteArrayFromString("AT+CWMODE_CUR=" + mode + "\r\n"); uart.Write(toSend, 0, toSend.Length); int byteCount = 1; byte[] rx = new byte[byteCount]; long start = DateTime.Now.Ticks; long now; while (lex.isDone == false) { System.Threading.Thread.Sleep(1); if (uart.BytesToRead > 0) { start = DateTime.Now.Ticks; int readCnt = uart.Read(rx, 0, byteCount); lex.process(rx); } else { CheckPresence(); now = DateTime.Now.Ticks; if (now - start > (timeoutMs) * TimeSpan.TicksPerMillisecond || !modulePresent) { lex.isDone = true; } } } lex.clearDoneFlag(); if (lex.lines.Contains("OK")) { lex.clearLines(); return(0); } return(-1); }
public int setWifiMode(wifiMode mode, int timeoutMs = 50) { byte[] toSend = MakeByteArrayFromString("AT+CWMODE_CUR=" + mode + "\r\n"); return(transaction(toSend, timeoutMs, "OK")); }