Created
December 14, 2011 10:11
-
-
Save clausjoergensen/1475994 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void IsAlive() | |
{ | |
int counter = 0; | |
int threadId = Thread.CurrentThread.ManagedThreadId; | |
while (keepCheckingConnection) | |
{ | |
Thread.Sleep(1000); | |
if (counter != 60) | |
{ | |
counter++; | |
continue; | |
} | |
counter = 0; | |
if (keepCheckingConnection) | |
{ | |
bool success = false; | |
lock (portLock) | |
{ | |
SerialComPort.DataReceived -= Port_DataReceived; | |
SerialComPort.DataReceived += SerialDataReceived; | |
try | |
{ | |
if (SerialComPort.IsOpen) | |
SerialComPort.Close(); | |
SerialComPort.Open(); | |
EnterCommandMode(); | |
success = ModemIsReady(); | |
if (success) | |
success = IsConnectedTo(PhoneNumber); | |
EnterDataMode(); | |
if (success) | |
success = GetMeterModemSignalStrength(); | |
} | |
catch (Exception exception) | |
{ | |
success = false; | |
HandleException(exception); | |
} | |
Thread.Sleep(200); | |
SerialComPort.DataReceived -= SerialDataReceived; | |
SerialComPort.DataReceived += Port_DataReceived; | |
SerialComPort.Close(); | |
} | |
Thread.Sleep(1000); | |
if (GsmStatus != GsmStatusEventArgs.Status.Error) | |
{ | |
isConnected = success; | |
OnGsmStatusChanged(GsmStatus, success ? Resources.GSMStatus_Connected : Resources.GSMStatus_Disconnected, PhoneNumber); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment