feat: Implement recipe selection with backend integration
Backend changes (C#): - Add SelectRecipe method to MachineBridge for recipe selection - Add currentRecipeId tracking in MainForm - Implement SELECT_RECIPE handler in WebSocketServer Frontend changes (React/TypeScript): - Add selectRecipe method to communication layer - Update handleSelectRecipe to call backend and handle response - Recipe selection updates ModelInfoPanel automatically - Add error handling and logging for recipe operations Layout improvements: - Add Layout component with persistent Header and Footer - Create separate IOMonitorPage for full-screen I/O monitoring - Add dynamic IO tab switcher in Header (Inputs/Outputs) - Ensure consistent UI across all pages 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -41,9 +41,25 @@ namespace HMIWeb
|
||||
_host.HandleCommand(command);
|
||||
}
|
||||
|
||||
public void LoadRecipe(string recipeId)
|
||||
public string SelectRecipe(string recipeId)
|
||||
{
|
||||
Console.WriteLine($"[C#] Loading Recipe: {recipeId}");
|
||||
Console.WriteLine($"[C#] Selecting Recipe: {recipeId}");
|
||||
|
||||
// In real app, load recipe settings here
|
||||
// For now, just return success
|
||||
try
|
||||
{
|
||||
// Simulate recipe loading logic
|
||||
_host.SetCurrentRecipe(recipeId);
|
||||
|
||||
var response = new { success = true, message = "Recipe selected successfully", recipeId = recipeId };
|
||||
return JsonConvert.SerializeObject(response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var response = new { success = false, message = ex.Message };
|
||||
return JsonConvert.SerializeObject(response);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetConfig()
|
||||
@@ -93,5 +109,49 @@ namespace HMIWeb
|
||||
Console.WriteLine($"[Backend] Data: {configJson}");
|
||||
// In a real app, we would save this to a file or database
|
||||
}
|
||||
public string GetIOList()
|
||||
{
|
||||
var ioList = new System.Collections.Generic.List<object>();
|
||||
|
||||
// Outputs (0-31)
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
string name = $"DOUT_{i:D2}";
|
||||
if (i == 0) name = "Tower Lamp Red";
|
||||
if (i == 1) name = "Tower Lamp Yel";
|
||||
if (i == 2) name = "Tower Lamp Grn";
|
||||
|
||||
ioList.Add(new { id = i, name = name, type = "output", state = false });
|
||||
}
|
||||
|
||||
// Inputs (0-31)
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
string name = $"DIN_{i:D2}";
|
||||
bool initialState = false;
|
||||
if (i == 0) name = "Front Door Sensor";
|
||||
if (i == 1) name = "Right Door Sensor";
|
||||
if (i == 2) name = "Left Door Sensor";
|
||||
if (i == 3) name = "Back Door Sensor";
|
||||
if (i == 4) { name = "Main Air Pressure"; initialState = true; }
|
||||
if (i == 5) { name = "Vacuum Generator"; initialState = true; }
|
||||
if (i == 6) { name = "Emergency Stop Loop"; initialState = true; }
|
||||
|
||||
ioList.Add(new { id = i, name = name, type = "input", state = initialState });
|
||||
}
|
||||
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(ioList);
|
||||
}
|
||||
public string GetRecipeList()
|
||||
{
|
||||
var recipes = new System.Collections.Generic.List<object>();
|
||||
recipes.Add(new { id = "1", name = "Wafer_Proc_300_Au", lastModified = "2023-10-25" });
|
||||
recipes.Add(new { id = "2", name = "Wafer_Insp_200_Adv", lastModified = "2023-10-26" });
|
||||
recipes.Add(new { id = "3", name = "Glass_Gen5_Bonding", lastModified = "2023-10-27" });
|
||||
recipes.Add(new { id = "4", name = "Solar_Cell_Cut_A", lastModified = "2023-11-01" });
|
||||
recipes.Add(new { id = "5", name = "LED_Mount_HighSpeed", lastModified = "2023-11-15" });
|
||||
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(recipes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace HMIWeb
|
||||
private bool[] inputs = new bool[32];
|
||||
private bool[] outputs = new bool[32];
|
||||
private string systemState = "IDLE";
|
||||
private string currentRecipeId = "1"; // Default recipe
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -77,7 +78,7 @@ namespace HMIWeb
|
||||
webView.CoreWebView2.AddHostObjectToScript("machine", new MachineBridge(this));
|
||||
|
||||
// 3. Load UI
|
||||
//webView.Source = new Uri("http://hmi.local/index.html");
|
||||
webView.Source = new Uri("http://hmi.local/index.html");
|
||||
|
||||
// Disable default browser keys (F5, F12 etc) if needed for kiosk mode
|
||||
webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
|
||||
@@ -153,6 +154,18 @@ namespace HMIWeb
|
||||
systemState = (cmd == "START") ? "RUNNING" : (cmd == "STOP") ? "PAUSED" : "IDLE";
|
||||
}
|
||||
|
||||
public void SetCurrentRecipe(string recipeId)
|
||||
{
|
||||
currentRecipeId = recipeId;
|
||||
Console.WriteLine($"[MainForm] Current recipe set to: {recipeId}");
|
||||
// In real app, load recipe parameters here
|
||||
}
|
||||
|
||||
public string GetCurrentRecipe()
|
||||
{
|
||||
return currentRecipeId;
|
||||
}
|
||||
|
||||
private double Lerp(double a, double b, double t) => a + (b - a) * t;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +120,7 @@ namespace HMIWeb
|
||||
dynamic json = Newtonsoft.Json.JsonConvert.DeserializeObject(msg);
|
||||
string type = json.type;
|
||||
|
||||
Console.WriteLine( $"HandleMessage:{type}" );
|
||||
if (type == "GET_CONFIG")
|
||||
{
|
||||
// Simulate Delay for Loading Screen Test
|
||||
@@ -131,6 +132,20 @@ namespace HMIWeb
|
||||
var response = new { type = "CONFIG_DATA", data = Newtonsoft.Json.JsonConvert.DeserializeObject(configJson) };
|
||||
await Send(socket, Newtonsoft.Json.JsonConvert.SerializeObject(response));
|
||||
}
|
||||
else if (type == "GET_IO_LIST")
|
||||
{
|
||||
var bridge = new MachineBridge(_mainForm);
|
||||
string ioJson = bridge.GetIOList();
|
||||
var response = new { type = "IO_LIST_DATA", data = Newtonsoft.Json.JsonConvert.DeserializeObject(ioJson) };
|
||||
await Send(socket, Newtonsoft.Json.JsonConvert.SerializeObject(response));
|
||||
}
|
||||
else if (type == "GET_RECIPE_LIST")
|
||||
{
|
||||
var bridge = new MachineBridge(_mainForm);
|
||||
string recipeJson = bridge.GetRecipeList();
|
||||
var response = new { type = "RECIPE_LIST_DATA", data = Newtonsoft.Json.JsonConvert.DeserializeObject(recipeJson) };
|
||||
await Send(socket, Newtonsoft.Json.JsonConvert.SerializeObject(response));
|
||||
}
|
||||
else if (type == "SAVE_CONFIG")
|
||||
{
|
||||
string configJson = Newtonsoft.Json.JsonConvert.SerializeObject(json.data);
|
||||
@@ -154,6 +169,14 @@ namespace HMIWeb
|
||||
bool state = json.state;
|
||||
_mainForm.Invoke(new Action(() => _mainForm.SetOutput(id, state)));
|
||||
}
|
||||
else if (type == "SELECT_RECIPE")
|
||||
{
|
||||
string recipeId = json.recipeId;
|
||||
var bridge = new MachineBridge(_mainForm);
|
||||
string resultJson = bridge.SelectRecipe(recipeId);
|
||||
var response = new { type = "RECIPE_SELECTED", data = Newtonsoft.Json.JsonConvert.DeserializeObject(resultJson) };
|
||||
await Send(socket, Newtonsoft.Json.JsonConvert.SerializeObject(response));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user