Upgrade (develop) - GCI - GciBridge - big change
This commit is contained in:
+1
-1
@@ -82,7 +82,7 @@
|
||||
this.lblConfigSource.Name = "lblConfigSource";
|
||||
this.lblConfigSource.Size = new System.Drawing.Size(75, 13);
|
||||
this.lblConfigSource.TabIndex = 2;
|
||||
this.lblConfigSource.Text = "ConfigSource:";
|
||||
this.lblConfigSource.Text = "GciConfigSource:";
|
||||
//
|
||||
// cmbConfigSource
|
||||
//
|
||||
|
||||
@@ -160,9 +160,15 @@ namespace GenesisCordonelInterface.UI.StaraTuraAPI_GenesisCordonelInterface
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates PortConfig from UI values.
|
||||
/// Creates a public GCI port configuration object from UI input values.
|
||||
/// </summary>
|
||||
private PortConfig? CreatePortConfig(string portName, string baudRateText)
|
||||
/// <param name="portName">Name of the port (e.g. COM3).</param>
|
||||
/// <param name="baudRateText">Baud rate entered in the UI.</param>
|
||||
/// <returns>
|
||||
/// Instance of <see cref="GciPublicModels.GciPortConfig"/> or null if port name is empty.
|
||||
/// </returns>
|
||||
/// <exception cref="Exception">Thrown when baud rate is invalid.</exception>
|
||||
private GciPublicModels.GciPortConfig CreateGciPortConfig(string portName, string baudRateText)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(portName))
|
||||
return null;
|
||||
@@ -170,35 +176,37 @@ namespace GenesisCordonelInterface.UI.StaraTuraAPI_GenesisCordonelInterface
|
||||
if (!int.TryParse(baudRateText, out int baudRate))
|
||||
throw new Exception($"Invalid baud rate for port {portName}.");
|
||||
|
||||
var cfg = new PortConfig
|
||||
return new GciPublicModels.GciPortConfig
|
||||
{
|
||||
PortName = portName,
|
||||
Type = "Serial"
|
||||
Type = "Serial",
|
||||
};
|
||||
|
||||
var sp = cfg.GetSerialPort();
|
||||
if (sp == null)
|
||||
throw new Exception($"Serial port object was not created for {portName}.");
|
||||
|
||||
sp.BaudRate = baudRate;
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private ConfigSource GetConfigSource()
|
||||
/// <summary>
|
||||
/// Gets selected configuration source from UI and maps it to public GCI model.
|
||||
/// </summary>
|
||||
/// <returns>Selected <see cref="GciPublicModels.GciConfigSource"/>.</returns>
|
||||
/// <exception cref="Exception">Thrown when no value is selected.</exception>
|
||||
private GciPublicModels.GciConfigSource GetConfigSource()
|
||||
{
|
||||
if (cmbConfigSource.SelectedItem == null)
|
||||
throw new Exception("ConfigSource is not selected.");
|
||||
throw new Exception("Config source is not selected.");
|
||||
|
||||
return (ConfigSource)cmbConfigSource.SelectedItem;
|
||||
return (GciPublicModels.GciConfigSource)cmbConfigSource.SelectedItem;
|
||||
}
|
||||
|
||||
private PasswordSource GetPasswordSource()
|
||||
/// <summary>
|
||||
/// Gets selected password source from UI and maps it to public GCI model.
|
||||
/// </summary>
|
||||
/// <returns>Selected <see cref="GciPublicModels.GciPasswordSource"/>.</returns>
|
||||
/// <exception cref="Exception">Thrown when no value is selected.</exception>
|
||||
private GciPublicModels.GciPasswordSource GetPasswordSource()
|
||||
{
|
||||
if (cmbPasswordSource.SelectedItem == null)
|
||||
throw new Exception("PasswordSource is not selected.");
|
||||
throw new Exception("Password source is not selected.");
|
||||
|
||||
return (PasswordSource)cmbPasswordSource.SelectedItem;
|
||||
return (GciPublicModels.GciPasswordSource)cmbPasswordSource.SelectedItem;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -221,15 +229,19 @@ namespace GenesisCordonelInterface.UI.StaraTuraAPI_GenesisCordonelInterface
|
||||
|
||||
await ExecuteApiActionAsync(async () =>
|
||||
{
|
||||
var result = await _api.InitOneMeterFromExternAsync(
|
||||
slot,
|
||||
GetConfigSource(),
|
||||
GetPasswordSource(),
|
||||
CreatePortConfig(txtRequestPort.Text, txtRequestBaudRate.Text),
|
||||
CreatePortConfig(txtStreamingPort.Text, txtStreamingBaudRate.Text));
|
||||
var request = new GciPublicModels.GciInitSlotRequest
|
||||
{
|
||||
SlotId = slot,
|
||||
ConfigSource = GetConfigSource(),
|
||||
PasswordSource = GetPasswordSource(),
|
||||
RequestPort = CreateGciPortConfig(txtRequestPort.Text, txtRequestBaudRate.Text),
|
||||
StreamingPort = CreateGciPortConfig(txtStreamingPort.Text, txtStreamingBaudRate.Text)
|
||||
};
|
||||
|
||||
var result = await _api.InitSlotAsync(request);
|
||||
|
||||
if (!result.Success)
|
||||
throw new Exception(result.ErrorMessage);
|
||||
throw new Exception(result.Message);
|
||||
|
||||
MessageBox.Show("Meter initialized.");
|
||||
});
|
||||
@@ -251,10 +263,10 @@ namespace GenesisCordonelInterface.UI.StaraTuraAPI_GenesisCordonelInterface
|
||||
|
||||
await ExecuteApiActionAsync(async () =>
|
||||
{
|
||||
var result = await _api.ConnectOneMeterAsync(slot);
|
||||
var result = await _api.ConnectOneSlotAsync(slot);
|
||||
|
||||
if (!result.Success)
|
||||
throw new Exception(result.ErrorMessage);
|
||||
throw new Exception(result.Message);
|
||||
|
||||
MessageBox.Show($"Connected.\r\nPCB ID: {result.PcbId}");
|
||||
});
|
||||
@@ -280,7 +292,6 @@ namespace GenesisCordonelInterface.UI.StaraTuraAPI_GenesisCordonelInterface
|
||||
MessageBox.Show("Disconnected.");
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads PCB ID asynchronously.
|
||||
/// </summary>
|
||||
@@ -297,8 +308,13 @@ namespace GenesisCordonelInterface.UI.StaraTuraAPI_GenesisCordonelInterface
|
||||
|
||||
await ExecuteApiActionAsync(async () =>
|
||||
{
|
||||
string pcbId = await _api.GetPcbIdAsync(slot);
|
||||
MessageBox.Show($"PCB ID: {pcbId}");
|
||||
GciPublicModels.GciGetPcbIdResult result =
|
||||
await _api.GetPcbIdAsync(slot);
|
||||
|
||||
if (!result.Success)
|
||||
throw new Exception(result.Message);
|
||||
|
||||
MessageBox.Show($"PCB ID: {result.PcbId}");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -345,10 +361,10 @@ namespace GenesisCordonelInterface.UI.StaraTuraAPI_GenesisCordonelInterface
|
||||
|
||||
foreach (int slot in slots)
|
||||
{
|
||||
var result = await _api.ConnectOneMeterAsync(slot);
|
||||
var result = await _api.ConnectOneSlotAsync(slot);
|
||||
|
||||
if (!result.Success)
|
||||
throw new Exception($"Slot {slot}: {result.ErrorMessage}");
|
||||
throw new Exception($"Slot {slot}: {result.Message}");
|
||||
}
|
||||
|
||||
MessageBox.Show("Selected meters connected.");
|
||||
|
||||
+2
-2
@@ -66,10 +66,10 @@ namespace GenesisCordonelInterface.UI.StaraTuraAPI_GenesisCordonelInterface
|
||||
|
||||
foreach (int slot in _api.GetSelectedSlots())
|
||||
{
|
||||
var result = await _api.ConnectOneMeterAsync(slot);
|
||||
var result = await _api.ConnectOneSlotAsync(slot);
|
||||
|
||||
if (!result.Success)
|
||||
throw new Exception($"Slot {slot}: {result.ErrorMessage}");
|
||||
throw new Exception($"Slot {slot}: {result.Message}");
|
||||
}
|
||||
|
||||
MessageBox.Show("Selected meters connected.");
|
||||
|
||||
Reference in New Issue
Block a user