Skip to content

Commit

Permalink
Change default folder pathes and make example json generation code re…
Browse files Browse the repository at this point in the history
…spect them.

Flush each line to the disk immediately.
Fix incorrect return code for Ctrl+C cancellation.
  • Loading branch information
kutukvpavel authored and kutukvpavel committed Oct 6, 2021
1 parent b65ebbe commit 36649b0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
10 changes: 6 additions & 4 deletions GPIBServer/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public Configuration()
public Configuration(bool init)
{
if (!init) return;
ScriptsFolder = @"..\scripts";
ScriptsFolder = @".\scripts";
ScriptsFilter = "*.json";
OutputFilePath = @"..\output\{{0}}{0:yyyy-MM-dd_HH-mm-ss}.csv";
InstrumentsFolder = @"..\instruments";
OutputFilePath = @".\output\{{0}}{0:yyyy-MM-dd_HH-mm-ss}.csv";
InstrumentsFolder = @".\instruments";
InstrumentsFilter = "*.json";
ControllersFolder = @"..\controllers";
ControllersFolder = @".\controllers";
ControllersFilter = "*.json";
ScriptName = "ExampleScript";
ScriptDevicePathDelimeter = ".";
Expand All @@ -28,6 +28,7 @@ public Configuration(bool init)
OutputRetries = 3;
OutputRetryDelayMilliseconds = 300;
PipeName = "GPIBServer_Broadcast_Pipe";
FlushEachOutputLineImmediately = true;
}

public string ScriptsFilter { get; set; }
Expand All @@ -47,6 +48,7 @@ public Configuration(bool init)
public int OutputRetries { get; set; }
public int OutputRetryDelayMilliseconds { get; set; }
public string PipeName { get; set; }
public bool FlushEachOutputLineImmediately { get; set; }

public string GetFullyQualifiedLogPath()
{
Expand Down
2 changes: 1 addition & 1 deletion GPIBServer/GpibScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public bool Execute(Dictionary<string, GpibController> controllers, Dictionary<s
catch (Exception)
{ }
}
return success;
return success && !src.IsCancellationRequested;
}

public IEnumerable<string> GetRequiredControllerNames()
Expand Down
11 changes: 7 additions & 4 deletions GPIBServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ private static ExitCodes GenerateExampleJson()
};
var ics = new GpibInstrumentCommandSet() { CommandSet = ctrl.CommandSet };
var sc = new GpibScript() { Threads = new GpibThread[] { new GpibThread() } };
string p = Path.Combine(Environment.CurrentDirectory, "example_{0}.json");
Serializer.Serialize(ctrl, string.Format(p, "controller"));
Serializer.Serialize(ics, string.Format(p, "instrument"));
Serializer.Serialize(sc, string.Format(p, "script"));
Serializer.Serialize(ctrl, Path.Combine(
Environment.CurrentDirectory, Configuration.Instance.ControllersFolder, "controller.json"));
Serializer.Serialize(ics, Path.Combine(
Environment.CurrentDirectory, Configuration.Instance.ControllersFolder, "instrument.json"));
Serializer.Serialize(sc, Path.Combine(
Environment.CurrentDirectory, Configuration.Instance.ControllersFolder, "script.json"));
return ExitCodes.OK;
}

Expand All @@ -105,6 +107,7 @@ private static ExitCodes MainHelper(string[] args)
Output.SeparationLabelFormat = Configuration.Instance.OutputSeparationLabelFormat;
Output.Retries = Configuration.Instance.OutputRetries;
Output.RetryDelayMilliseconds = Configuration.Instance.OutputRetryDelayMilliseconds;
Output.FlushEachLine = Configuration.Instance.FlushEachOutputLineImmediately;
}
catch (Exception ex)
{
Expand Down
3 changes: 1 addition & 2 deletions GPIBServer/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"profiles": {
"GPIBServer": {
"commandName": "Project",
"commandLineArgs": "ExampleScript"
"commandName": "Project"
}
}
}
3 changes: 3 additions & 0 deletions GPIBServer/WriterThreadBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace GPIBServer
{
public static partial class Output
{
public static bool FlushEachLine { get; set; }

private abstract class WriterThreadBase<T> : IDisposable
{
public WriterThreadBase(string path, CancellationToken token)
Expand Down Expand Up @@ -75,6 +77,7 @@ private void WriteLine(T data)
try
{
_Writer.WriteLine(line);
if (FlushEachLine) _Writer.Flush();
break;
}
catch (IOException ex)
Expand Down

0 comments on commit 36649b0

Please sign in to comment.