Skip to content

Instantly share code, notes, and snippets.

@clausjoergensen
Created December 14, 2011 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clausjoergensen/1475994 to your computer and use it in GitHub Desktop.
Save clausjoergensen/1475994 to your computer and use it in GitHub Desktop.
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