private void Connect_Click(object sender, EventArgs e)
{
if (bpPort == null)
{
if (ComPort.SelectedIndex >= 0)
{
string port = ComPort.SelectedItem as string;
bpPort = new BPPort(port);
bpPort.WaitResponse += new BPPort.WaitResponseEventHandle(bpPort_WaitResponse);
bpPort.RecieveData += new BPPort.RecieveDataEventHandle(bpPort_RecieveData);
bpPort.SendStarted += new BPPort.SendStartedEventHandle(bpPort_SendStarted);
bpPort.SendEnded += new BPPort.SendEndedEventHandle(bpPort_SendEnded);
try
{
if (bpPort.Connect() == BP_RESPONSE.OK)
{
Connect.Text = "F8 - Disconnect";
groupCommand.Enabled = groupMode.Enabled = true;
Mode.SelectedIndex = ((int)bpPort.Mode) - 1;
StatusText(bpPort.FirmwareVersion);
if (bpPort.Info() == BP_RESPONSE.OK)
DisplayPins();
SetAutoUpdate();
return;
}
bpPort = null;
StatusText("BusPirate not found");
}
catch (Exception ex)
{
LogError(ex.Message);
}
}
}
else
{
TimerStop();
Connect.Text = "F8 - Connect";
groupCommand.Enabled = groupMode.Enabled = false;
bpPort.Disconnect();
bpPort = null;
}
}