diff --git a/App.config b/App.config
index 816b022..a2c5664 100644
--- a/App.config
+++ b/App.config
@@ -1,8 +1,12 @@
-
-
-
+
+
+
+
+
+
+
@@ -19,4 +23,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Database.cs b/Database.cs
index 7acedb0..b811f9b 100644
--- a/Database.cs
+++ b/Database.cs
@@ -1,6 +1,7 @@
-using Microsoft.Data.Sqlite;
-using System;
+using System;
using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data.SQLite;
using System.Diagnostics;
using System.Linq;
using System.Text;
@@ -26,7 +27,7 @@ namespace FAtoPA
private bool CreateFSMTable()
{
//Debug.WriteLine("About to execute CreateFSMTable");
- using (var connection = new SqliteConnection(connectionString))
+ using (var connection = new SQLiteConnection(connectionString))
{
try
{
@@ -47,7 +48,7 @@ namespace FAtoPA
}
public bool ClearFSMTable() {
- using (var connection = new SqliteConnection(connectionString))
+ using (var connection = new SQLiteConnection(connectionString))
{
connection.Open();
var deleteCmd = connection.CreateCommand();
@@ -57,7 +58,7 @@ namespace FAtoPA
int result = deleteCmd.ExecuteNonQuery();
return (result > 0);
}
- catch (SqliteException e)
+ catch (SQLiteException e)
{
Debug.WriteLine("Error deleting FSMData: " + e.Message);
}
@@ -68,7 +69,7 @@ namespace FAtoPA
public List GetFSMDatas()
{
List fsmDatas = new List();
- using (var connection = new SqliteConnection(connectionString))
+ using (var connection = new SQLiteConnection(connectionString))
{
connection.Open();
@@ -88,7 +89,7 @@ namespace FAtoPA
public bool AddFSMData(params FSMData[] data)
{
- using(var connection = new SqliteConnection(connectionString))
+ using(var connection = new SQLiteConnection(connectionString))
{
connection.Open();
using (var transaction = connection.BeginTransaction())
@@ -109,7 +110,7 @@ namespace FAtoPA
return false;
}
}
- catch (SqliteException e)
+ catch (SQLiteException e)
{
Debug.WriteLine("Error inserting FSMData: " + e.Message);
transaction.Rollback();
@@ -124,7 +125,7 @@ namespace FAtoPA
public bool RemoveFSMDatabySIID(String SIID)
{
- using (var conn = new SqliteConnection(connectionString))
+ using (var conn = new SQLiteConnection(connectionString))
{
conn.Open();
var deleteCmd = conn.CreateCommand();
@@ -135,7 +136,7 @@ namespace FAtoPA
int result = deleteCmd.ExecuteNonQuery();
return (result > 0);
}
- catch (SqliteException e)
+ catch (SQLiteException e)
{
Debug.WriteLine("Error deleting FSMData: " + e.Message);
return false;
@@ -146,7 +147,7 @@ namespace FAtoPA
private bool CreateModbusTable()
{
//Debug.WriteLine("About to execute CreateModbusTable");
- using (var connection = new SqliteConnection(connectionString))
+ using (var connection = new SQLiteConnection(connectionString))
{
try
{
@@ -167,7 +168,7 @@ namespace FAtoPA
public bool ClearModbusTable()
{
- using (var connection = new SqliteConnection(connectionString))
+ using (var connection = new SQLiteConnection(connectionString))
{
connection.Open();
var deleteCmd = connection.CreateCommand();
@@ -177,7 +178,7 @@ namespace FAtoPA
int result = deleteCmd.ExecuteNonQuery();
return (result > 0);
}
- catch (SqliteException e)
+ catch (SQLiteException e)
{
Debug.WriteLine("Error deleting ModbusData: " + e.Message);
}
@@ -187,7 +188,7 @@ namespace FAtoPA
public Boolean AddModbusData(params ModbusData[] data)
{
- using (var connection = new SqliteConnection(connectionString))
+ using (var connection = new SQLiteConnection(connectionString))
{
connection.Open();
using (var transaction = connection.BeginTransaction())
@@ -208,7 +209,7 @@ namespace FAtoPA
return false;
}
}
- catch (SqliteException e)
+ catch (SQLiteException e)
{
Debug.WriteLine("Error inserting ModbusData: " + e.Message);
transaction.Rollback();
@@ -224,7 +225,7 @@ namespace FAtoPA
public List GetModbusDatas()
{
List modbusDatas = new List();
- using (var connection = new SqliteConnection(connectionString))
+ using (var connection = new SQLiteConnection(connectionString))
{
connection.Open();
@@ -244,7 +245,7 @@ namespace FAtoPA
public bool RemoveModbusDatabySIID(String SIID)
{
- using (var conn = new SqliteConnection(connectionString))
+ using (var conn = new SQLiteConnection(connectionString))
{
conn.Open();
var deleteCmd = conn.CreateCommand();
@@ -255,7 +256,7 @@ namespace FAtoPA
int result = deleteCmd.ExecuteNonQuery();
return (result > 0);
}
- catch (SqliteException e)
+ catch (SQLiteException e)
{
Debug.WriteLine("Error deleting ModbusData: " + e.Message);
return false;
@@ -266,7 +267,7 @@ namespace FAtoPA
private bool CreateVXTable()
{
//Debug.WriteLine("About to execute CreateVXTable");
- using (var connection = new SqliteConnection(connectionString))
+ using (var connection = new SQLiteConnection(connectionString))
{
try
{
@@ -287,7 +288,7 @@ namespace FAtoPA
public bool ClearVXTable()
{
- using (var connection = new SqliteConnection(connectionString))
+ using (var connection = new SQLiteConnection(connectionString))
{
connection.Open();
var deleteCmd = connection.CreateCommand();
@@ -297,7 +298,7 @@ namespace FAtoPA
int result = deleteCmd.ExecuteNonQuery();
return (result > 0);
}
- catch (SqliteException e)
+ catch (SQLiteException e)
{
Debug.WriteLine("Error deleting VXData: " + e.Message);
}
@@ -308,7 +309,7 @@ namespace FAtoPA
public List GetVXDatas()
{
List vxDatas = new List();
- using (var connection = new SqliteConnection(connectionString))
+ using (var connection = new SQLiteConnection(connectionString))
{
connection.Open();
@@ -328,7 +329,7 @@ namespace FAtoPA
public bool RemoveVXDatabySIID(String SIID)
{
- using (var conn = new SqliteConnection(connectionString))
+ using (var conn = new SQLiteConnection(connectionString))
{
conn.Open();
var deleteCmd = conn.CreateCommand();
@@ -339,7 +340,7 @@ namespace FAtoPA
int result = deleteCmd.ExecuteNonQuery();
return (result > 0);
}
- catch (SqliteException e)
+ catch (SQLiteException e)
{
Debug.WriteLine("Error deleting VXData: " + e.Message);
return false;
@@ -348,7 +349,7 @@ namespace FAtoPA
}
public bool AddVXData(params VXData[] data) {
- using(var connection = new SqliteConnection(connectionString))
+ using(var connection = new SQLiteConnection(connectionString))
{
connection.Open();
using (var transaction = connection.BeginTransaction())
@@ -370,7 +371,7 @@ namespace FAtoPA
return false;
}
}
- catch (SqliteException e)
+ catch (SQLiteException e)
{
Debug.WriteLine("Error inserting VXData: " + e.Message);
transaction.Rollback();
@@ -385,7 +386,7 @@ namespace FAtoPA
}
- class FSMData
+ class FSMData : INotifyPropertyChanged
{
public String SIID { get; set; }
public Boolean Enable { get; set; }
@@ -417,6 +418,13 @@ namespace FAtoPA
this.Value = "";
}
+
+ protected void OnPropertyChanged(string propertyName)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
}
class ModbusData
diff --git a/FAtoPA.Net.csproj b/FAtoPA.Net.csproj
index cb23295..c4dda1c 100644
--- a/FAtoPA.Net.csproj
+++ b/FAtoPA.Net.csproj
@@ -1,5 +1,6 @@
+
Debug
@@ -14,6 +15,8 @@
4
true
true
+
+
AnyCPU
@@ -64,6 +67,12 @@
..\..\..\Bosch FA\FSM5000FSI-2.0.21\Release_x64\DataExchangeInterfaces.dll
+
+ packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll
+
+
+ packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll
+
..\..\..\Bosch FA\FSM5000FSI-2.0.21\Release_x64\FSIConfig.dll
@@ -82,9 +91,6 @@
packages\Microsoft.Bcl.AsyncInterfaces.9.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll
-
- packages\Microsoft.Data.Sqlite.Core.9.0.0\lib\netstandard2.0\Microsoft.Data.Sqlite.dll
-
..\..\..\Bosch FA\FSM5000FSI-2.0.21\Release_x64\MPNetCIL.dll
@@ -110,7 +116,17 @@
packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll
+
+
+ packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.119.0\lib\net46\System.Data.SQLite.dll
+
+
+ packages\System.Data.SQLite.EF6.1.0.119.0\lib\net46\System.Data.SQLite.EF6.dll
+
+
+ packages\System.Data.SQLite.Linq.1.0.119.0\lib\net46\System.Data.SQLite.Linq.dll
+
packages\System.IO.Pipelines.9.0.0\lib\net462\System.IO.Pipelines.dll
@@ -204,4 +220,14 @@
+
+
+ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/FSM.cs b/FSM.cs
index fa18635..ec6de69 100644
--- a/FSM.cs
+++ b/FSM.cs
@@ -4,6 +4,7 @@ using FSM5000FSIAPI.Version3;
using System;
using System.CodeDom;
using System.Collections.Generic;
+using System.Data.Entity.Infrastructure.Interception;
using System.Diagnostics;
using System.Linq;
using System.Text;
@@ -47,7 +48,6 @@ namespace FAtoPA
config.PNA = pna;
config.LocalIPAddress = localip;
config.RepositoryLocation = ".\\repository";
- config.AdvancedFSIConfig = new AdvancedFSIConfig();
}
///
@@ -82,7 +82,7 @@ namespace FAtoPA
TraceConsoleWritter outputter = new TraceConsoleWritter();
controller.SetTraceLevel(SourceLevels.Warning); //for support issues please set the level to SourceLevels.Verbose
Result result = controller.Startup(config);
- //Debug.WriteLine("[FSM] Start result = "+result.ToString());
+ Debug.WriteLine("[FSM] Start result = "+result.ToString());
if (result==Result.SUCCESS)
{
Started = true;
@@ -110,7 +110,7 @@ namespace FAtoPA
try
{
Result result = controller.Shutdown();
- //Console.WriteLine("[FSM] Shutdown result = " + result.ToString());
+ Debug.WriteLine("[FSM] Shutdown result = " + result.ToString());
if (_event!=null) _event.ConnectStatus(false, "FSM Stopped");
} catch (Exception e)
{
@@ -149,12 +149,16 @@ namespace FAtoPA
///
public void SetItemType(ItemType devItemType)
{
- Debug.WriteLine($"Item type {devItemType.FunctionalType} ({devItemType.Description})");
+ //Debug.WriteLine($"Item type {devItemType.FunctionalType} ({devItemType.Description})");
if (type_dictionary != null)
{
int type = int.Parse(devItemType.FunctionalType.ToString());
- if (!type_dictionary.ContainsKey(type)) type_dictionary.Add(type, devItemType.Description);
-
+ if (!type_dictionary.ContainsKey(type))
+ {
+ Debug.WriteLine($"Adding key={type}, value={devItemType.Description} to type_dictionary");
+ type_dictionary.Add(type, devItemType.Description);
+ }
+ else Debug.WriteLine($"type_dictionary already have key={type}");
}
}
@@ -178,12 +182,14 @@ namespace FAtoPA
nodeData.Label = devItem.Label;
nodeData.Description = type_dictionary.ContainsKey(type) ? type_dictionary[type] : "Unknown";
node_data.Add(SIID, nodeData);
+ Debug.WriteLine($"Adding SIID={nodeData.SIID} Label={nodeData.Label} Description={nodeData.Description} to node_data");
// notify all listeners
- if (listeners != null)
- foreach (var item in listeners)
+ if (listeners != null)
+ foreach (var item in listeners)
item.DiscoveredSIID(SIID, nodeData);
-
- }
+
+ }
+ else Debug.WriteLine($"node_data already have SIID={SIID}");
}
}
@@ -235,22 +241,23 @@ namespace FAtoPA
{
NodeState prev = nd.State;
nd.State = new NodeState(devItemState);
+ //if (prev != null)
+ //{
+ // Debug.WriteLine($"SIID={SIID} Change LogicalState from {prev.LogicalState} to {nd.State.LogicalState}");
+ //}
+ //else
+ //{
+ // Debug.WriteLine($"SIID={SIID} New LogicalState {nd.State.LogicalState}");
+ //}
// notify all listeners
if (listeners != null)
foreach (var item in listeners)
item.NewState(SIID, prev, nd.State);
- if (prev != null)
- {
- Debug.WriteLine("SIID=" + SIID + " Change LogicalState from " + prev.LogicalState + " to " + nd.State.LogicalState);
- }
- else
- {
- Debug.WriteLine("New State for SIID=" + SIID + " LogicalState=" + nd.State.LogicalState);
- }
- } else Debug.WriteLine("NodeData with SIID " + SIID + " is null");
- } else Debug.WriteLine("node_data doesn't contain SIID " + SIID);
+
+ } else Debug.WriteLine($"NodeData with SIID {SIID} is null");
+ } else Debug.WriteLine($"node_data doesn't contain SIID {SIID}");
} else Debug.WriteLine("node_data is null");
@@ -263,7 +270,7 @@ namespace FAtoPA
///
public void SetMPNetTime(DateTime mpNetTime)
{
- Debug.WriteLine("Time is " + mpNetTime + ".");
+ Debug.WriteLine($"Time is {mpNetTime}");
}
}
@@ -276,7 +283,7 @@ namespace FAtoPA
{
public override void Write(string message)
{
- if (message!=null && message.Length>0) Debug.Write(message);
+ if (message!=null && message.Length>0) Debug.WriteLine(message);
}
public override void WriteLine(string message)
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 35b78c3..0f71c28 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -7,7 +7,10 @@
mc:Ignorable="d"
Loaded="Window_Loaded"
Closing="Window_Closing"
- Title="MainWindow" Height="450" Width="800">
+ Title="MainWindow"
+ MinWidth="800"
+ MinHeight="480"
+ WindowState="Maximized" >
@@ -102,14 +105,22 @@
-
+
-
+
-
+
+
+
+
+
+
+
+
+
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index c6be18b..e5092fb 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -188,23 +188,23 @@ namespace FAtoPA.Net
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Debug.WriteLine("Window Closing");
- timer1s?.Stop();
- fsm?.Stop();
- modbusSlave?.Stop();
- vx3k?.Disconnect();
+ timer1s.Stop();
+ fsm.Stop();
+ modbusSlave.Stop();
+ vx3k.Disconnect();
}
private void btnStartStopFSM_Click(object sender, RoutedEventArgs e)
{
if (FSM.Started)
{
- fsm?.Stop();
+ fsm.Stop();
btnStartStopFSM.Content = "Start FSM Connection";
FSM.Started = false;
}
else
{
- fsm?.Start();
+ fsm.Start();
btnStartStopFSM.Content = "Stop FSM Connection";
FSM.Started = true;
}
@@ -214,7 +214,7 @@ namespace FAtoPA.Net
{
if (ModbusSlave.Started)
{
- modbusSlave?.Stop();
+ modbusSlave.Stop();
btnStartStopModbus.Content = "Start Modbus Connection";
ModbusSlave.Started = false;
}
@@ -222,7 +222,7 @@ namespace FAtoPA.Net
{
if (config != null)
{
- modbusSlave?.Start(config.Modbus_ListenPort);
+ modbusSlave.Start(config.Modbus_ListenPort);
btnStartStopModbus.Content = "Stop Modbus Connection";
ModbusSlave.Started = true;
@@ -235,7 +235,7 @@ namespace FAtoPA.Net
{
if (VX3K.Started)
{
- vx3k?.Disconnect();
+ vx3k.Disconnect();
btnStartStopVX.Content = "Start VX Connection";
VX3K.Started = false;
}
@@ -243,7 +243,7 @@ namespace FAtoPA.Net
{
if (config != null)
{
- vx3k?.Connect(config.VX_TargetIP, config.VX_TargetPort);
+ vx3k.Connect(config.VX_TargetIP, config.VX_TargetPort);
btnStartStopVX.Content = "Stop VX Connection";
VX3K.Started = true;
}
@@ -795,25 +795,21 @@ namespace FAtoPA.Net
private void btnDelSIID_Click(object sender, RoutedEventArgs e)
{
- SIID selected = GetSIID();
- if (selected != null)
+ int selectedindex = FSMTable.SelectedIndex;
+ if (selectedindex >= 0)
{
+ FSMData selected = (FSMData)FSMTable.Items[selectedindex];
MessageBoxResult result = MessageBox.Show("Delete SIID " + selected.ToString() + " ?", "Delete SIID", MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
- if (database != null)
- {
- if (database.RemoveFSMDatabySIID(selected.ToString()))
- {
- FSMTable.ItemsSource = database.GetFSMDatas();
- FSMSIID.Remove(selected.ToString());
- }
- else MessageBox.Show("Failed to delete from database");
- }
- else MessageBox.Show("Database is null");
+ FsmTableMember.Remove(selected);
+ database.RemoveFSMDatabySIID(selected.SIID);
+
}
}
- else MessageBox.Show("Invalid Selection");
+ else MessageBox.Show("Select a row in table to delete");
+
+
}
private void btnClearSIID_Click(object sender, RoutedEventArgs e)
@@ -821,16 +817,9 @@ namespace FAtoPA.Net
MessageBoxResult result = MessageBox.Show("Clear all SIID ?", "Clear SIID", MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
- if (database != null)
- {
- if (database.ClearFSMTable())
- {
- FSMTable.ItemsSource = database.GetFSMDatas();
- FSMSIID.Clear();
- }
- else MessageBox.Show("Failed to clear database");
- }
- else MessageBox.Show("Database is null");
+ FsmTableMember.Clear();
+ database.ClearFSMTable();
+
}
}
@@ -1136,6 +1125,27 @@ namespace FAtoPA.Net
break;
}
}
+
+ private void AddSelectedSIID(object sender, RoutedEventArgs e)
+ {
+ var lbl = DetectedSIID.SelectedItem;
+ if (lbl != null && lbl is Label)
+ {
+ Label selected = (Label)lbl;
+ if (selected.Tag is NodeData)
+ {
+ NodeData data = (NodeData)selected.Tag;
+ FSMData fSMData = new FSMData(data.SIID.ToString(), true, data.Description);
+ if (database.AddFSMData(fSMData))
+ {
+ FsmTableMember.Add(fSMData);
+ database.AddFSMData(fSMData);
+ }
+ else MessageBox.Show("Failed to add to database");
+ }
+ else MessageBox.Show("Selected SIID dont have NodeData");
+ } else MessageBox.Show("No SIID Selected");
+ }
}
// event handler for VX3K
@@ -1282,10 +1292,10 @@ namespace FAtoPA.Net
// Class ini untuk update Table FSM
class FSMTableUpdater : FSMResultInterface
{
+ // dari database
ObservableCollection data;
ListBox listbox;
Label countlabel;
- int count = 0;
public FSMTableUpdater(ObservableCollection data, ListBox listbox, Label countlabel)
{
this.data = data;
@@ -1295,23 +1305,33 @@ namespace FAtoPA.Net
public void DiscoveredSIID(string SIID, NodeData type)
{
- Debug.WriteLine("Discovered SIID : " + SIID + " Type : " + type);
- count++;
- countlabel.Dispatcher.Invoke(() => countlabel.Content = "Count : " + count);
- listbox.Dispatcher.Invoke(() => listbox.Items.Add(new Label() { Content = SIID + " : " + type.ToString() }));
+ Debug.WriteLine("Discovered SIID : " + SIID + " Type : " + type.Description);
+ Application.Current.Dispatcher.Invoke(() =>
+ {
+ listbox.Items.Add(new Label() { Content = $"{SIID} : {type.Label} : {type.Description}", Tag = type });
+ countlabel.Content = "Count : " + listbox.Items.Count;
+ });
+
}
public void NewState(string SIID, NodeState previous, NodeState current)
{
- Debug.WriteLine("New State : " + SIID + " Previous : " + previous + " Current : " + current);
-
- //FSMData dd = data.First(d => d.SIID == SIID);
- //if (dd != null)
- //{
- // dd.LastUpdate = DateTime.Now.ToString();
- // dd.Value = current.LogicalState ?? "Unknown";
- //}
+ Debug.WriteLine("New State : " + SIID + " Previous : " + previous?.LogicalState + " Current : " + current.LogicalState);
+ if (data != null)
+ {
+ foreach (var dd in data)
+ {
+ if (dd.SIID.Equals(SIID))
+ {
+ dd.LastUpdate = DateTime.Now.ToString();
+ dd.Value = current.LogicalState ?? "Unknown";
+ Debug.WriteLine($"Changing row in FSM Table for SIID={SIID} Value={dd.Value}");
+ return;
+ }
+ }
+ }
+ Debug.WriteLine($"FSM Table dont have row with SIID={SIID}");
}
@@ -1320,6 +1340,7 @@ namespace FAtoPA.Net
// Class ini untuk Update Modbus Register dari FSM Update
class ModbusTriggerFromFSM : FSMResultInterface
{
+ // dari database
ObservableCollection source;
ObservableCollection data;
ModbusSlave slave;
diff --git a/packages.config b/packages.config
index 01375b4..4768311 100644
--- a/packages.config
+++ b/packages.config
@@ -1,13 +1,17 @@
+
-
-
+
+
+
+
+