[chronojump] Encoder capture Init try/catch on sp.Open()
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Encoder capture Init try/catch on sp.Open()
- Date: Fri, 23 Feb 2018 18:01:07 +0000 (UTC)
commit 14e10b2e115caccda1c1346d9854abd28ae6a67c
Author: Xavier de Blas <xaviblas gmail com>
Date: Fri Feb 23 19:00:08 2018 +0100
Encoder capture Init try/catch on sp.Open()
src/encoderCapture.cs | 15 ++++++++++++---
src/gui/encoder.cs | 8 +++++++-
2 files changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/src/encoderCapture.cs b/src/encoderCapture.cs
index 5bf2f61..86e9d2f 100644
--- a/src/encoderCapture.cs
+++ b/src/encoderCapture.cs
@@ -112,7 +112,7 @@ public abstract class EncoderCapture
//if cont (continuous mode), then will not end when too much time passed before start
- public void InitGlobal (int widthG, int heightG, int time, int timeEnd,
+ public bool InitGlobal (int widthG, int heightG, int time, int timeEnd,
bool cont, string eccon, string port, bool capturingInertialBG, bool showOnlyBars,
bool simulated)
{
@@ -130,12 +130,19 @@ public abstract class EncoderCapture
rand = new Random(40);
SimulatedReset();
}
- else if(! simulated && ! capturingInertialBG) {
+ else if(! simulated && ! capturingInertialBG)
+ {
LogB.Debug("runEncoderCaptureCsharp start port:", port);
sp = new SerialPort(port);
sp.BaudRate = 115200;
LogB.Information("sp created");
- sp.Open();
+
+ try {
+ sp.Open();
+ } catch {
+ LogB.Information("Error: Cannot open port");
+ return false;
+ }
LogB.Information("sp opened");
}
@@ -203,6 +210,8 @@ public abstract class EncoderCapture
cancel = false;
finish = false;
+
+ return true;
}
protected virtual void initSpecific()
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 593a585..453568c 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -5340,7 +5340,7 @@ public partial class ChronoJumpWindow
else { //action == encoderActions.CAPTURE_IM)
eCapture = new EncoderCaptureIMCalc();
- eCapture.InitGlobal(
+ bool success = eCapture.InitGlobal(
encoder_capture_signal_drawingarea.Allocation.Width,
encoder_capture_signal_drawingarea.Allocation.Height,
preferences.encoderCaptureTimeIM,
@@ -5351,6 +5351,12 @@ public partial class ChronoJumpWindow
false,
false,
false);
+ if(! success)
+ {
+ new DialogMessage(Constants.MessageTypes.WARNING,
+ Catalog.GetString("Sorry, cannot start capture."));
+ return;
+ }
encoderRProcCapture.CutByTriggers = Preferences.TriggerTypes.NO_TRIGGERS;
//do not cutByTriggers on inertial, yet.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]