소스 검색

Log, Data Update

Sonjiwon 3 년 전
부모
커밋
88cd905382

+ 64 - 0
InkjetScale/InkjetScale.BusinessLogic.Scale/InkjetScale.BusinessLogic.Scale.csproj

@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{577C09AA-94AB-4F4F-9398-A93586049D1D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>InkjetScale.BusinessLogic.Scale</RootNamespace>
+    <AssemblyName>InkjetScale.BusinessLogic.Scale</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <Deterministic>true</Deterministic>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Prism, Version=8.1.97.5141, Culture=neutral, PublicKeyToken=40ee6c3a2184dc59, processorArchitecture=MSIL">
+      <HintPath>..\packages\Prism.Core.8.1.97\lib\net47\Prism.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="ScaleManager.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="packages.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\InkjetScale.BusinessLogic.Calculation\InkjetScale.BusinessLogic.Calculation.csproj">
+      <Project>{74C4EB8F-0A6F-47A0-AFDA-158FB056C0C1}</Project>
+      <Name>InkjetScale.BusinessLogic.Calculation</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\InkjetScale.Common\InkjetScale.Common.csproj">
+      <Project>{BC7536F1-00FA-4970-8460-22B63D280108}</Project>
+      <Name>InkjetScale.Common</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 36 - 0
InkjetScale/InkjetScale.BusinessLogic.Scale/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 
+// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
+// 이러한 특성 값을 변경하세요.
+[assembly: AssemblyTitle("InkjetScale.BusinessLogic.Scale")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("InkjetScale.BusinessLogic.Scale")]
+[assembly: AssemblyCopyright("Copyright ©  2022")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 
+// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
+// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
+[assembly: ComVisible(false)]
+
+// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
+[assembly: Guid("577c09aa-94ab-4f4f-9398-a93586049d1d")]
+
+// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
+//
+//      주 버전
+//      부 버전 
+//      빌드 번호
+//      수정 버전
+//
+// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
+// 기본값으로 할 수 있습니다.
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 123 - 0
InkjetScale/InkjetScale.BusinessLogic.Scale/ScaleManager.cs

@@ -0,0 +1,123 @@
+using InkjetScale.BusinessLogic.Calculation;
+using InkjetScale.Common;
+using InkjetScale.Common.Events;
+using Prism.Events;
+using System;
+using System.Collections.Generic;
+using System.IO.Ports;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace InkjetScale.BusinessLogic.Scale
+{
+    public class ScaleManager
+    {
+        public SerialPort Scale = null;
+        
+        eCommand command;
+        bool isThreadUse = false;
+        IEventAggregator ea = null;
+        Thread readThread = null;
+
+        public ScaleManager(IEventAggregator eventAggregator)
+        {
+            readThread = new Thread(GetCurrentValue);
+            this.ea = eventAggregator;
+            this.Scale = new SerialPort();
+        }
+
+
+        public void InitSerial()
+        {
+            Scale.PortName = "COM2";
+            Scale.BaudRate = 9600;
+            Scale.DataBits = 8;
+            Scale.StopBits = StopBits.One;
+            Scale.Parity = Parity.None;
+        }
+
+        public void Open()
+        {
+            var ports = SerialPort.GetPortNames();
+            if (ports == null || !ports.Contains("COM2"))
+                return;
+
+            if (!Scale.IsOpen)
+            {
+                Scale.Open();
+                Scale.Encoding = Encoding.Default;
+                Scale.DataReceived += new SerialDataReceivedEventHandler(SerialDataReceived);
+
+                readThread.Start();
+            }
+        }
+
+        public void Dispose()
+        {
+            if (Scale.IsOpen)
+            {
+                isThreadUse = false;
+                readThread.Join();
+                Scale.Close();
+            }
+        }
+
+        private void SerialDataReceived(object sender, SerialDataReceivedEventArgs e)
+        {
+            Thread.Sleep(50);
+
+            byte[] ReceiveByte = new byte[28];
+            int count = this.Scale.Read(ReceiveByte, 0, 28);
+            // S S      12.3 mg\r\n
+            if (!isThreadUse)
+                isThreadUse = true;
+
+            ScaleMessagePubEvent(ReceiveByte , count);
+        }
+
+        private void ScaleMessagePubEvent(byte[] receiveByte, int count)
+        {
+            var d = new ReceiveMessageEventArgs()
+            {
+                Command = this.command,
+                ReceiveByte = receiveByte,
+                ReceiveCount = count,
+                IsThreadUse = this.isThreadUse,
+            };
+            this.ea.GetEvent<ReceiveMessageEvent>().Publish(d);
+        }
+
+        public void SendCommand(string com)
+        {
+            if (!Scale.IsOpen)
+                return;
+
+            if (com != null)
+            {
+                Thread.Sleep(50);
+                isThreadUse = false;
+                Enum.TryParse(com, out this.command);
+                Scale.Write(command.ToString() + Environment.NewLine);
+            }
+        }
+
+        private void GetCurrentValue()
+        {
+            while (Scale.IsOpen)
+            {
+                Thread.Sleep(500);
+                if (!isThreadUse)
+                    continue;
+                else
+                {
+                    command = eCommand.S;
+                    Scale.Write(command.ToString() + Environment.NewLine);
+                }
+            }
+        }
+
+    }
+
+}

+ 4 - 0
InkjetScale/InkjetScale.BusinessLogic.Scale/packages.config

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="Prism.Core" version="8.1.97" targetFramework="net472" />
+</packages>

+ 1 - 1
InkjetScale/InkjetScale.Common/Events/PubSubEvents.cs

@@ -8,6 +8,6 @@ using System.Threading.Tasks;
 namespace InkjetScale.Common.Events
 {
     public class SerialConnectEvent : PubSubEvent<SerialEventArgs> { };
+    public class ReceiveMessageEvent : PubSubEvent<ReceiveMessageEventArgs> { };
     public class ViewLogEvent : PubSubEvent<ViewLogArgs> { };
-    public class SystemExitEvent : PubSubEvent<bool> { };
 }

+ 12 - 0
InkjetScale/InkjetScale.Common/Events/PubSubModel.cs

@@ -14,9 +14,21 @@ namespace InkjetScale.Common.Events
 
     public class ViewLogArgs : EventArgs
     {
+        public DateTime Time { get; set; }
+        public bool IsRegister { get; set; }
         public eHeadList Head { get; set; }
         public double Weight { get; set; }
         public double pl { get; set; }
     }
 
+    public class ReceiveMessageEventArgs : EventArgs
+    {
+        public bool IsThreadUse { get; set; }
+        public eCommand Command { get; set; }
+        public byte[] ReceiveByte { get; set; }
+        public int ReceiveCount { get; set; }
+    }
+
+
+
 }

+ 1 - 0
InkjetScale/InkjetScale.GUI.LogViews/LogViewModule.cs

@@ -16,6 +16,7 @@ namespace InkjetScale.GUI.LogViews
         public void OnInitialized(IContainerProvider containerProvider)
         {
             ViewModelLocationProvider.Register<Views.ScaleLogView, Views.ScaleLogViewModel>();
+            ViewModelLocationProvider.Register<Views.RegisteredWeightView, Views.RegisteredWeightViewModel>();
         }
 
         public void RegisterTypes(IContainerRegistry containerRegistry)

+ 149 - 8
InkjetScale/InkjetScale.GUI.LogViews/Views/RegisteredWeightView.xaml

@@ -1,12 +1,153 @@
 <UserControl x:Class="InkjetScale.GUI.LogViews.Views.RegisteredWeightView"
-             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
-             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-             xmlns:local="clr-namespace:InkjetScale.GUI.LogViews.Views"
-             mc:Ignorable="d" 
-             d:DesignHeight="450" d:DesignWidth="800">
+                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+                 xmlns:local="clr-namespace:InkjetScale.GUI.LogViews.Views"
+                 mc:Ignorable="d" 
+                 xmlns:prism="http://prismlibrary.com/"
+                 prism:ViewModelLocator.AutoWireViewModel="True"
+                 xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
+                 d:DesignHeight="952.94" d:DesignWidth="500">
+
     <Grid>
-            
+
+        <Grid.RowDefinitions>
+            <RowDefinition Height="*"/>
+            <RowDefinition Height="*"/>
+            <RowDefinition Height="*"/>
+        </Grid.RowDefinitions>
+
+        <Grid Grid.Row="0">
+            <Border CornerRadius="10" Background="{DynamicResource PrimaryHueMidBrush}" BorderBrush="#0075ce" Padding="5" BorderThickness="2" Margin="5">
+                <Grid>
+                    
+                    <Grid.RowDefinitions>
+                        <RowDefinition Height="30"/>
+                        <RowDefinition/>
+                    </Grid.RowDefinitions>
+
+                    <Grid Grid.Row="0">
+                        <StackPanel Orientation="Horizontal" Margin="10, 0,0,0">
+                            <materialDesign:PackIcon Kind="DatabaseOutline" Height="32" Width="32" VerticalAlignment="Center" Foreground="White"/>
+                            <Button Style="{StaticResource MaterialDesignRaisedButton}" Command="{Binding ClearCommand}"  
+                                                HorizontalAlignment="Center" VerticalAlignment="Center" Background="{x:Null}" BorderThickness="0" >
+                                <TextBlock Margin="8,0,0,0" VerticalAlignment="Center" Style="{DynamicResource MaterialDesignSubtitle1TextBlock}" 
+                                           Text="HeadPack1" Foreground="White"/>
+                            </Button>
+                        </StackPanel>
+                    </Grid>
+
+
+                    <Grid Grid.Row="1">
+                        <DataGrid Margin="0 8 0 0" ItemsSource="{Binding HeadPack1DataList}" CanUserSortColumns="True" 
+                                  CanUserAddRows="False" AutoGenerateColumns="False" materialDesign:DataGridAssist.CellPadding="13 8 8 8" 
+                                  materialDesign:DataGridAssist.ColumnHeaderPadding="8" IsReadOnly="True" Background="LightBlue">
+                            <DataGrid.Columns>
+                                <DataGridTextColumn Binding="{Binding Time ,StringFormat='{}{0:HH:mm:ss}'}" Header="  Time" Width="*" FontSize="13"
+                                            EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
+                                <DataGridTextColumn Binding="{Binding Head}" Header="  Head" Width="1.2*" FontSize="13"
+                                            EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
+                                <DataGridTextColumn Binding="{Binding Weight}" Header="  Weight(mg)" FontSize="13"
+                                        EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" Width="1.2*" />
+                                <DataGridTextColumn Binding="{Binding pl}" Header="  pl" Width="*" FontSize="13"
+                                            EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
+                            </DataGrid.Columns>
+                        </DataGrid>
+                    </Grid>
+                    
+                </Grid>
+
+            </Border>
+        </Grid>
+
+        <Grid Grid.Row="1">
+            <Border CornerRadius="10" Background="{DynamicResource PrimaryHueMidBrush}" BorderBrush="#0075ce" Padding="5" BorderThickness="2" Margin="5">
+                <Grid>
+
+                    <Grid.RowDefinitions>
+                        <RowDefinition Height="30"/>
+                        <RowDefinition/>
+                    </Grid.RowDefinitions>
+
+                    <Grid Grid.Row="0">
+                        <StackPanel Orientation="Horizontal" Margin="10, 0,0,0">
+                            <materialDesign:PackIcon Kind="DatabaseOutline" Height="32" Width="32" VerticalAlignment="Center" Foreground="White"/>
+                            <Button Style="{StaticResource MaterialDesignRaisedButton}" Command="{Binding ClearCommand}"  
+                                                HorizontalAlignment="Center" VerticalAlignment="Center" Background="{x:Null}" BorderThickness="0" >
+                                <TextBlock Margin="8,0,0,0" VerticalAlignment="Center" Style="{DynamicResource MaterialDesignSubtitle1TextBlock}" 
+                                           Text="HeadPack2" Foreground="White"/>
+                            </Button>
+                        </StackPanel>
+                    </Grid>
+
+                    <Grid Grid.Row="1">
+                        <DataGrid Margin="0 8 0 0" ItemsSource="{Binding HeadPack2DataList}" CanUserSortColumns="True" 
+                                  CanUserAddRows="False" AutoGenerateColumns="False" materialDesign:DataGridAssist.CellPadding="13 8 8 8" 
+                                  materialDesign:DataGridAssist.ColumnHeaderPadding="8" IsReadOnly="True" Background="LightBlue">
+                            <DataGrid.Columns>
+                                <DataGridTextColumn Binding="{Binding Time ,StringFormat='{}{0:HH:mm:ss}'}" Header="  Time" Width="*" FontSize="13"
+                                            EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
+                                <DataGridTextColumn Binding="{Binding Head}" Header="  Head" Width="1.2*" FontSize="13"
+                                            EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
+                                <DataGridTextColumn Binding="{Binding Weight}" Header="  Weight(mg)" FontSize="13"
+                                        EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" Width="1.2*" />
+                                <DataGridTextColumn Binding="{Binding pl}" Header="  pl" Width="*" FontSize="13"
+                                            EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
+                            </DataGrid.Columns>
+                        </DataGrid>
+                    </Grid>
+
+                </Grid>
+
+            </Border>
+        </Grid>
+
+        <Grid Grid.Row="2">
+            <Border CornerRadius="10" Background="{DynamicResource PrimaryHueMidBrush}" BorderBrush="#0075ce" Padding="5" BorderThickness="2" Margin="5">
+                <Grid>
+
+                    <Grid.RowDefinitions>
+                        <RowDefinition Height="30"/>
+                        <RowDefinition/>
+                    </Grid.RowDefinitions>
+
+                    <Grid Grid.Row="0">
+                        <StackPanel Orientation="Horizontal" Margin="10, 0,0,0">
+                            <materialDesign:PackIcon Kind="DatabaseOutline" Height="32" Width="32" VerticalAlignment="Center" Foreground="White"/>
+                            <Button Style="{StaticResource MaterialDesignRaisedButton}" Command="{Binding ClearCommand}"  
+                                                HorizontalAlignment="Center" VerticalAlignment="Center" Background="{x:Null}" BorderThickness="0" >
+                                <TextBlock Margin="8,0,0,0" VerticalAlignment="Center" Style="{DynamicResource MaterialDesignSubtitle1TextBlock}" 
+                                           Text="HeadPack3" Foreground="White"/>
+                            </Button>
+                        </StackPanel>
+                    </Grid>
+
+
+                    <Grid Grid.Row="1">
+                        <DataGrid Margin="0 8 0 0" ItemsSource="{Binding HeadPack3DataList}" CanUserSortColumns="True" 
+                                  CanUserAddRows="False" AutoGenerateColumns="False" materialDesign:DataGridAssist.CellPadding="13 8 8 8" 
+                                  materialDesign:DataGridAssist.ColumnHeaderPadding="8" IsReadOnly="True" Background="LightBlue">
+                            <DataGrid.Columns>
+                                <DataGridTextColumn Binding="{Binding Time ,StringFormat='{}{0:HH:mm:ss}'}" Header="  Time" Width="*" FontSize="13"
+                                            EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
+                                <DataGridTextColumn Binding="{Binding Head}" Header="  Head" Width="1.2*" FontSize="13"
+                                            EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
+                                <DataGridTextColumn Binding="{Binding Weight}" Header="  Weight(mg)" FontSize="13"
+                                        EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" Width="1.2*" />
+                                <DataGridTextColumn Binding="{Binding pl}" Header="  pl" Width="*" FontSize="13"
+                                            EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
+                            </DataGrid.Columns>
+                        </DataGrid>
+                    </Grid>
+
+                </Grid>
+
+            </Border>
+        </Grid>
+
+
+
     </Grid>
+
 </UserControl>

+ 7 - 0
InkjetScale/InkjetScale.GUI.LogViews/Views/RegisteredWeightView.xaml.cs

@@ -20,9 +20,16 @@ namespace InkjetScale.GUI.LogViews.Views
     /// </summary>
     public partial class RegisteredWeightView : UserControl
     {
+        RegisteredWeightViewModel ViewModel => this.DataContext as RegisteredWeightViewModel;
         public RegisteredWeightView()
         {
             InitializeComponent();
+            this.Loaded += RegisteredWeightView_Loaded;
+        }
+
+        private void RegisteredWeightView_Loaded(object sender, RoutedEventArgs e)
+        {
+            ViewModel.Init();
         }
     }
 }

+ 41 - 2
InkjetScale/InkjetScale.GUI.LogViews/Views/RegisteredWeightViewModel.cs

@@ -1,12 +1,51 @@
-using System;
+using InkjetScale.Common.Events;
+using Prism.Events;
+using Prism.Mvvm;
+using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
 namespace InkjetScale.GUI.LogViews.Views
 {
-    internal class RegisteredWeightViewModel
+    internal class RegisteredWeightViewModel : BindableBase
     {
+
+        private ObservableCollection<ViewLogArgs> headPack1DataList;
+        public ObservableCollection<ViewLogArgs> HeadPack1DataList { get => this.headPack1DataList; set => SetProperty(ref this.headPack1DataList, value); }
+
+        private ObservableCollection<ViewLogArgs> headPack2DataList;
+        public ObservableCollection<ViewLogArgs> HeadPack2DataList { get => this.headPack2DataList; set => SetProperty(ref this.headPack2DataList, value); }
+
+        private ObservableCollection<ViewLogArgs> headPack3DataList;
+        public ObservableCollection<ViewLogArgs> HeadPack3DataList { get => this.headPack3DataList; set => SetProperty(ref this.headPack3DataList, value); }
+
+        IEventAggregator ea = null;
+
+        public RegisteredWeightViewModel(IEventAggregator eventAggregator)
+        {
+            this.ea = eventAggregator;
+
+            HeadPack1DataList = new ObservableCollection<ViewLogArgs>();
+            HeadPack2DataList = new ObservableCollection<ViewLogArgs>();
+            HeadPack3DataList = new ObservableCollection<ViewLogArgs>();
+
+            this.ea.GetEvent<ViewLogEvent>().Subscribe(ViewLogSubEvent, ThreadOption.UIThread);
+        }
+
+        internal void Init()
+        {
+
+        }
+
+        private void ViewLogSubEvent(ViewLogArgs obj)
+        {
+            if (!obj.IsRegister)
+                return;
+
+
+        }
     }
 }

+ 25 - 11
InkjetScale/InkjetScale.GUI.LogViews/Views/ScaleLogView.xaml

@@ -4,10 +4,10 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:InkjetScale.GUI.LogViews.Views"
+             mc:Ignorable="d" 
              xmlns:prism="http://prismlibrary.com/"
              prism:ViewModelLocator.AutoWireViewModel="True"
              xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
-             mc:Ignorable="d" 
              d:DesignHeight="952.94" d:DesignWidth="400">
     <Border Background="{DynamicResource PrimaryHueMidBrush}" Padding="5" BorderThickness="2" Margin="5" CornerRadius="5">
 
@@ -18,23 +18,37 @@
             </Grid.RowDefinitions>
 
             <Grid Grid.Row="0">
-                <StackPanel Orientation="Horizontal" Grid.Row="0" Margin="10, 0,0,0">
-                    <materialDesign:PackIcon Kind="AlignHorizontalCentre" Height="32" Width="32" VerticalAlignment="Center" />
-                    <Button Style="{StaticResource MaterialDesignRaisedButton}" Command="{Binding ClearCommand}"  
+                <Grid.ColumnDefinitions>
+                    <ColumnDefinition Width="3*"/>
+                    <ColumnDefinition Width="*"/>
+                </Grid.ColumnDefinitions>
+
+                <Grid Grid.Column="0">
+                    <StackPanel Orientation="Horizontal" Margin="10, 0,0,0">
+                        <materialDesign:PackIcon Kind="AlignHorizontalCentre" Height="32" Width="32" VerticalAlignment="Center" />
+                        <Button Style="{StaticResource MaterialDesignRaisedButton}" Command="{Binding ClearCommand}"  
                                                 HorizontalAlignment="Center" VerticalAlignment="Center" Background="{x:Null}" BorderThickness="0" >
-                        <TextBlock Margin="8,0,0,0" VerticalAlignment="Center" Style="{DynamicResource MaterialDesignSubtitle1TextBlock}" Text="Measurement Log" />
-                    </Button>
-                </StackPanel>
+                            <TextBlock Margin="8,0,0,0" VerticalAlignment="Center" Style="{DynamicResource MaterialDesignSubtitle1TextBlock}" Text="Measurement Log" />
+                        </Button>
+                    </StackPanel>
+                </Grid>
+
+                <Grid Grid.Column="1">
+                    <Button Content="Set" Command="{Binding RegisterCommand}" HorizontalAlignment="Center" VerticalAlignment="Center" Background="{x:Null}" />
+                </Grid>
+
             </Grid>
 
             <Grid Grid.Row="1">
-                <DataGrid Margin="0 8 0 0" ItemsSource="{Binding MeasurementList}" CanUserSortColumns="True" CanUserAddRows="False" AutoGenerateColumns="False" 
-                                      materialDesign:DataGridAssist.CellPadding="13 8 8 8" materialDesign:DataGridAssist.ColumnHeaderPadding="8" IsReadOnly="True" Background="LightBlue">
+                <DataGrid Margin="0 8 0 0" ItemsSource="{Binding MeasurementList}" SelectedItem="{Binding SelectedValues}" CanUserSortColumns="True" CanUserAddRows="False" AutoGenerateColumns="False" 
+                                      materialDesign:DataGridAssist.CellPadding="13 8 8 8" materialDesign:DataGridAssist.ColumnHeaderPadding="8" IsReadOnly="True" Background="LightBlue" Grid.ColumnSpan="2">
                     <DataGrid.Columns>
-                        <DataGridTextColumn Binding="{Binding Head}" Header="  Head" Width="*" FontSize="13"
+                        <DataGridTextColumn Binding="{Binding Time ,StringFormat='{}{0:HH:mm:ss}'}" Header="  Time" Width="*" FontSize="13"
+                                            EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
+                        <DataGridTextColumn Binding="{Binding Head}" Header="  Head" Width="1.2*" FontSize="13"
                                             EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
                         <DataGridTextColumn Binding="{Binding Weight}" Header="  Weight(mg)" FontSize="13"
-                                        EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" Width="*" />
+                                        EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" Width="1.2*" />
                         <DataGridTextColumn Binding="{Binding pl}" Header="  pl" Width="*" FontSize="13"
                                             EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
                     </DataGrid.Columns>

+ 26 - 2
InkjetScale/InkjetScale.GUI.LogViews/Views/ScaleLogViewModel.cs

@@ -17,11 +17,16 @@ namespace InkjetScale.GUI.LogViews.Views
         private ObservableCollection<ViewLogArgs> measurementList;
         public ObservableCollection<ViewLogArgs> MeasurementList { get => this.measurementList; set => SetProperty(ref this.measurementList, value); }
 
-        public ICommand ClearCommand { get; set; }
+        private ViewLogArgs selectedValues;
+        public ViewLogArgs SelectedValues { get => this.selectedValues; set => SetProperty(ref this.selectedValues, value); }
 
+        public ICommand RegisterCommand { get; set; }
+        public ICommand ClearCommand { get; set; }
         IEventAggregator eventAggregator = null;
+
         public ScaleLogViewModel(IEventAggregator eventAggregator)
         {
+            this.RegisterCommand = new DelegateCommand(ExecuteRegister);
             this.ClearCommand = new DelegateCommand(ExecuteClear);
             this.eventAggregator = eventAggregator;
 
@@ -29,6 +34,22 @@ namespace InkjetScale.GUI.LogViews.Views
             this.eventAggregator.GetEvent<ViewLogEvent>().Subscribe(ViewLogSubEvent, ThreadOption.UIThread);
         }
 
+        private void ExecuteRegister()
+        {
+            if(SelectedValues != null)
+            {
+                var d = new ViewLogArgs()
+                {
+                    Time = DateTime.Now,
+                    IsRegister = true,
+                    Head = SelectedValues.Head,
+                    Weight = SelectedValues.Weight,
+                    pl = SelectedValues.pl,
+                };
+                this.eventAggregator.GetEvent<ViewLogEvent>().Publish(d);
+            }
+        }
+
         private void ExecuteClear()
         {
             MeasurementList.Clear();
@@ -36,7 +57,10 @@ namespace InkjetScale.GUI.LogViews.Views
 
         private void ViewLogSubEvent(ViewLogArgs args)
         {
-            MeasurementList.Add(args);
+            if (args.IsRegister)
+                return;
+            else
+                 MeasurementList.Add(args);
         }
 
     }

+ 4 - 0
InkjetScale/InkjetScale.GUI.MainViews/InkjetScale.GUI.MainViews.csproj

@@ -116,6 +116,10 @@
       <Project>{74C4EB8F-0A6F-47A0-AFDA-158FB056C0C1}</Project>
       <Name>InkjetScale.BusinessLogic.Calculation</Name>
     </ProjectReference>
+    <ProjectReference Include="..\InkjetScale.BusinessLogic.Scale\InkjetScale.BusinessLogic.Scale.csproj">
+      <Project>{577C09AA-94AB-4F4F-9398-A93586049D1D}</Project>
+      <Name>InkjetScale.BusinessLogic.Scale</Name>
+    </ProjectReference>
     <ProjectReference Include="..\InkjetScale.Common\InkjetScale.Common.csproj">
       <Project>{BC7536F1-00FA-4970-8460-22B63D280108}</Project>
       <Name>InkjetScale.Common</Name>

+ 37 - 45
InkjetScale/InkjetScale.GUI.MainViews/Views/ScaleMainView.xaml

@@ -20,69 +20,64 @@
 
         <Grid.ColumnDefinitions>
             <ColumnDefinition/>
+            <ColumnDefinition Width="1.2*"/>
             <ColumnDefinition/>
         </Grid.ColumnDefinitions>
 
         <Grid Grid.Column="0">
 
-            <Grid.RowDefinitions>
-                <RowDefinition Height="2*"/>
-                <RowDefinition Height="*"/>
-            </Grid.RowDefinitions>
-
             <Grid Grid.Row="0">
-                <ContentControl Content="{Binding ControlView}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5"/>
+                <!--<ContentControl Content="{Binding ControlView}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5"/>-->
+                <ContentControl Content="{Binding RegisterView}" Width="500" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5"/>
             </Grid>
 
-
         </Grid>
 
         <Grid Grid.Column="1">
 
-
             <Grid.ColumnDefinitions>
                 <ColumnDefinition/>
+                <ColumnDefinition Width="3.5*"/>
                 <ColumnDefinition/>
             </Grid.ColumnDefinitions>
-
-            <Grid Grid.Column="0">
+            
+            <Grid Grid.Column="1">
 
                 <Grid.RowDefinitions>
+                    <RowDefinition Height="0.25*"/>
                     <RowDefinition Height="*"/>
                     <RowDefinition Height="0.5*"/>
                     <RowDefinition Height="*"/>
                     <RowDefinition Height="*"/>
                     <RowDefinition Height="*"/>
-                    <RowDefinition Height="0.5*"/>
+                    <RowDefinition Height="0.25*"/>
                 </Grid.RowDefinitions>
 
-                <Grid Grid.Row="0">
-                    <Border BorderBrush="#0075ce" CornerRadius="5" BorderThickness="2" Margin="5"  >
-                        <materialDesign:Card Background="LightBlue" Foreground="{DynamicResource PrimaryHueLightForegroundBrush}" Padding="8">
-                            <Grid>
-
-                                <Grid.RowDefinitions>
-                                    <RowDefinition Height="*"/>
-                                    <RowDefinition Height="6"/>
-                                    <RowDefinition Height="*"/>
-                                </Grid.RowDefinitions>
+                <Grid Grid.Row="1">
+                    <Border CornerRadius="10" Background="LightBlue" BorderBrush="#0075ce" Padding="5" BorderThickness="2" Margin="5"  >
+                        <Grid>
 
-                                <Grid Grid.Row="0">
-                                    <TextBlock Text="Head" FontSize="25" Foreground="Black" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center"/>
-                                </Grid>
+                            <Grid.RowDefinitions>
+                                <RowDefinition Height="*"/>
+                                <RowDefinition Height="6"/>
+                                <RowDefinition Height="*"/>
+                            </Grid.RowDefinitions>
 
-                                <Separator Grid.Row="1"/>
+                            <Grid Grid.Row="0">
+                                <TextBlock Text="Head" FontSize="25" Foreground="Black" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                            </Grid>
 
-                                <Grid Grid.Row="2">
-                                    <ComboBox ItemsSource="{Binding HeadList}" SelectedItem="{Binding SelectedHead}" FontSize="25" Width="auto" HorizontalAlignment="Center"/>
-                                </Grid>
+                            <Separator Grid.Row="1"/>
 
+                            <Grid Grid.Row="2">
+                                <ComboBox ItemsSource="{Binding HeadList}" SelectedItem="{Binding SelectedHead}" FontSize="25" Width="auto" HorizontalAlignment="Center"/>
                             </Grid>
-                        </materialDesign:Card>
+
+                        </Grid>
                     </Border>
                 </Grid>
 
-                <Grid Grid.Row="1">
+                <Grid Grid.Row="2">
 
                     <Border CornerRadius="10" Background="LightBlue" BorderBrush="#0075ce" Padding="5" BorderThickness="2" Margin="5">
 
@@ -107,19 +102,19 @@
 
                 </Grid>
 
-                <Grid Grid.Row="2" >
+                <Grid Grid.Row="3" >
 
                     <Border CornerRadius="10" Background="LightBlue" BorderBrush="#0075ce" Padding="5" BorderThickness="2" Margin="5">
-                        
+
                         <Grid>
-                            
+
                             <Grid.RowDefinitions>
                                 <RowDefinition Height="*"/>
                                 <RowDefinition Height="*"/>
                             </Grid.RowDefinitions>
 
                             <Grid Grid.Row="0">
-                                                                
+
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition/>
                                     <ColumnDefinition/>
@@ -162,14 +157,14 @@
                                 <TextBlock Grid.Column="1" Text="{Binding ReceiveMsg}" Foreground="Black" FontSize="20" Width="auto"
                                    HorizontalAlignment="Center" VerticalAlignment="Center" />
                             </Grid>
-                            
+
                         </Grid>
-                        
+
                     </Border>
-                    
+
                 </Grid>
 
-                <Grid Grid.Row="3" >
+                <Grid Grid.Row="4" >
 
                     <Border CornerRadius="10" Background="LightBlue" BorderBrush="#0075ce" Padding="5" BorderThickness="2" Margin="5">
 
@@ -215,7 +210,7 @@
 
                 </Grid>
 
-                <Grid Grid.Row="4">
+                <Grid Grid.Row="5">
 
                     <Border CornerRadius="10" Background="LightBlue" BorderBrush="#0075ce" Padding="5" BorderThickness="2" Margin="5">
 
@@ -265,13 +260,10 @@
 
 
             </Grid>
+        </Grid>
 
-            <Grid Grid.Column="1" Margin="5">
-
-                <ContentControl Content="{Binding LogView}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
-
-            </Grid>
-
+        <Grid Grid.Column="2" Margin="5">
+            <ContentControl Content="{Binding LogView}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
         </Grid>
 
     </Grid>

+ 60 - 138
InkjetScale/InkjetScale.GUI.MainViews/Views/ScaleMainViewModel.cs

@@ -1,4 +1,5 @@
 using InkjetScale.BusinessLogic.Calculation;
+using InkjetScale.BusinessLogic.Scale;
 using InkjetScale.Common;
 using InkjetScale.Common.Events;
 using InkjetScale.GUI.LogViews.Views;
@@ -25,9 +26,6 @@ namespace InkjetScale.GUI.MainViews.Views
     {
         
         #region Property
-        private eCommand selectedCommand;
-        public eCommand SelectedCommand { get => this.selectedCommand; set => SetProperty(ref this.selectedCommand, value); }
-
         private eHeadList selectedHead;
         public eHeadList SelectedHead { get => this.selectedHead; set => SetProperty(ref this.selectedHead, value); }
         
@@ -54,162 +52,56 @@ namespace InkjetScale.GUI.MainViews.Views
 
         private string dropCount;
         public string DropCount { get => this.dropCount; set => SetProperty(ref this.dropCount, value); }
+        
+        //private ScaleControlView controlView;
+        //public ScaleControlView ControlView { get => this.controlView; set => SetProperty(ref this.controlView, value); }
 
-        private ScaleControlView controlView;
-        public ScaleControlView ControlView { get => this.controlView; set => SetProperty(ref this.controlView, value); }
+        private RegisteredWeightView registerView;
+        public RegisteredWeightView RegisterView { get => this.registerView; set => SetProperty(ref this.registerView, value); }
 
         private ScaleLogView logView;
         public ScaleLogView LogView { get => this.logView; set => SetProperty(ref this.logView, value); }
 
-        private List<eCommand> commandList;
-        public List<eCommand> CommandList { get => this.commandList; set => SetProperty(ref this.commandList, value); }
-        
         private List<eHeadList> headList;
         public List<eHeadList> HeadList { get => this.headList; set => SetProperty(ref this.headList, value); }
-
         #endregion
 
-        SerialPort scale = new SerialPort();
-
         public ICommand RunCommand { get; set; }
-
         IEventAggregator ea = null;
         IContainerProvider provider = null;
+        ScaleManager scaleManager;
 
-        string Command = null;
-        Thread scaleThread = null;
-
-        public ScaleMainViewModel(IEventAggregator eventAggregator, IContainerProvider proVider)
+        public ScaleMainViewModel(IEventAggregator eventAggregator, IContainerProvider proVider, ScaleManager scaleManager)
         {
-            this.CommandList = new List<eCommand>();
-            this.HeadList = new List<eHeadList>();
-
+            this.scaleManager = scaleManager;
             this.ea = eventAggregator;
             this.provider = proVider;
+            this.HeadList = new List<eHeadList>();
 
             this.RunCommand = new DelegateCommand<string>(ExecuteRun);
 
-            scaleThread = new Thread(GetScaleInfo);
-            this.ea.GetEvent<SystemExitEvent>().Subscribe(SystemExitSubEvent, ThreadOption.UIThread);
-        }
-
-        private void SystemExitSubEvent(bool isExit)
-        {
-            if (isExit)
-            {
-                isThreadUse = false;
-                scale.Close();
-                scaleThread.Join();
-            }
-        }
-
-        bool isThreadUse = true;
-        private void GetScaleInfo()
-        {
-            while(scale.IsOpen)
-            {
-                Thread.Sleep(500);
-                if (!isThreadUse)
-                    continue;
-                else
-                {
-                    Command = "S";
-                    scale.Write(Command + Environment.NewLine);
-                }
-
-            }
-        }
-
-        #region Execute
-
-        private void ExecuteRun(string command)
-        {
-            if (!scale.IsOpen)
-                return;
-
-            if (scaleThread.IsAlive)
-                isThreadUse = false;
-
-            if (command != null)
-            {                
-                Command = command;
-                scale.Write(Command + Environment.NewLine); // command 보낼 때 \r\n 또는 Environment.NesLine 붙여서 보내야함
-            }
-            else
-                return;
-
-        }
-        #endregion
-
-        bool isInit = false;
-        internal void Init()
-        {
-            if(!isInit)
-            {
-                DropCount = "2000"; 
-                this.ControlView = this.provider.Resolve<ScaleControlView>();
-                this.LogView = this.provider.Resolve<ScaleLogView>();
-
-                for (eHeadList head = eHeadList.HeadPack1Head1; head <= eHeadList.HeadPack3Head4; head++)
-                {
-                    this.HeadList.Add(head);
-                }
-
-                for (eCommand com = eCommand.S; com <= eCommand.C; com++)
-                {
-                    this.CommandList.Add(com);
-                }
-
-                OpenSerialPort();
-
-                this.SelectedHead = this.HeadList[(int)eHeadList.HeadPack1Head1 -1];
-
-                scaleThread.Start();
-
-            }
-
-        }
-
-        private void OpenSerialPort()
-        {
-            scale.PortName = "COM2";
-            scale.BaudRate = 9600;
-            scale.DataBits = 8;
-            scale.StopBits = StopBits.One;
-            scale.Parity = Parity.None;
-
-            if (!scale.IsOpen)
-            {
-                scale.Open();
-                scale.Encoding = Encoding.Default;
-                scale.DataReceived += new SerialDataReceivedEventHandler(SerialDataReceived);
-            }
+            this.ea.GetEvent<ReceiveMessageEvent>().Subscribe(ScaleMessageSubEvent);
         }
 
-        private void SerialDataReceived(object sender, SerialDataReceivedEventArgs e)
+        private void ScaleMessageSubEvent(ReceiveMessageEventArgs obj)
         {
-            Thread.Sleep(50);
-
-            byte[] ReceiveByte = new byte[28];
-            int num = this.scale.Read(ReceiveByte, 0, 28);
-
             try
             {
                 char c;
                 bool isNum;
                 int val;
-                
-                switch (Command) 
+
+                switch (obj.Command)
                 {
-                    case "S": //-> S S      3.14 mg \r\n 
+                    case eCommand.S: //-> S S      3.14 mg \r\n 
                         {
 
                             ReceiveMsg = String.Empty;
                             WeightValue = String.Empty;
 
-                            for (int index = 0; index < num; index++)
+                            for (int index = 0; index < obj.ReceiveCount; index++)
                             {
-                                c = Convert.ToChar((object)ReceiveByte[index]); // Char 변환
+                                c = Convert.ToChar((object)obj.ReceiveByte[index]); // Char 변환
                                 ReceiveMsg += c;
 
                                 isNum = int.TryParse(c.ToString(), out val); //숫자인지 문자인지 확인 할 변수
@@ -228,24 +120,24 @@ namespace InkjetScale.GUI.MainViews.Views
                                 IsStable = true;
                             else
                                 IsStable = false;
-                            
+
                             var mgValue = double.Parse(WeightValue);
                             var nozzle = 1024;
                             var drops = int.Parse(DropCount);
                             PlValue = $"{ScaleMath.GetPl(mgValue, nozzle, drops)}";
 
-                            if (!isThreadUse)
+                            if (!obj.IsThreadUse)
                                 ViewLogPubEvent(SelectedHead, mgValue, double.Parse(PlValue));
 
                             break;
                         }
 
-                    case "Z": //-> Z A \r\n
+                    case eCommand.Z: //-> Z A \r\n
                         {
                             ReceiveMsg = String.Empty;
-                            for (int index = 0; index < num; index++)
+                            for (int index = 0; index < obj.ReceiveCount; index++)
                             {
-                                c = Convert.ToChar((object)ReceiveByte[index]); // Char 변환
+                                c = Convert.ToChar((object)obj.ReceiveByte[index]); // Char 변환
 
                                 if (c == 'Z' || c == 'A')
                                     ReceiveMsg += c;
@@ -253,7 +145,7 @@ namespace InkjetScale.GUI.MainViews.Views
                                     continue;
                             }
 
-                            if (ReceiveMsg == "ZA") 
+                            if (ReceiveMsg == "ZA")
                             {
                                 ReceiveMsg = "Zero!";
                             }
@@ -261,14 +153,14 @@ namespace InkjetScale.GUI.MainViews.Views
                             break;
                         }
 
-                    case "T":
+                    case eCommand.T:
                         {
                             TareReceiveMsg = String.Empty;
                             TareWeight = String.Empty;
 
-                            for (int index = 0; index < num; index++)
+                            for (int index = 0; index < obj.ReceiveCount; index++)
                             {
-                                c = Convert.ToChar((object)ReceiveByte[index]); // Char 변환
+                                c = Convert.ToChar((object)obj.ReceiveByte[index]); // Char 변환
                                 TareReceiveMsg += c;
 
                                 isNum = int.TryParse(c.ToString(), out val); //숫자인지 문자인지 확인 할 변수
@@ -290,6 +182,12 @@ namespace InkjetScale.GUI.MainViews.Views
                             break;
                         }
 
+                    case eCommand.C:
+                        {
+                            ReceiveMsg = "Clear";
+                            break;
+                        }
+
                     default:
                         {
                             ReceiveMsg = "Wrong Command!";
@@ -298,19 +196,43 @@ namespace InkjetScale.GUI.MainViews.Views
 
                 }
 
-                if (!isThreadUse)
-                    isThreadUse = true;
-
             }
 
             catch
             {
             }
         }
+        
+        #region Execute
+        private void ExecuteRun(string command)
+        {
+            this.scaleManager.SendCommand(command);
+        }
+        #endregion
+
+        bool isInit = false;
+        internal void Init()
+        {
+            if(!isInit)
+            {
+                DropCount = "2000";
+                //this.ControlView = this.provider.Resolve<ScaleControlView>();
+                this.RegisterView = this.provider.Resolve<RegisteredWeightView>();
+                this.LogView = this.provider.Resolve<ScaleLogView>();
+
+                for (eHeadList head = eHeadList.HeadPack1Head1; head <= eHeadList.HeadPack3Head4; head++)
+                {
+                    this.HeadList.Add(head);
+                }
+
+                this.SelectedHead = this.HeadList[(int)eHeadList.HeadPack1Head1 -1];
+                this.scaleManager.Open();
+            }
+        }
 
         private void ViewLogPubEvent(eHeadList head, double weight, double pl)
         {
-            var c = new ViewLogArgs() { Head = head , Weight = weight, pl = pl};
+            var c = new ViewLogArgs() {IsRegister = false, Time = DateTime.Now, Head = head , Weight = weight, pl = pl};
             ea.GetEvent<ViewLogEvent>().Publish(c);
         }
     }

+ 9 - 0
InkjetScale/InkjetScale.sln

@@ -25,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InkjetScale.BusinessLogic.A
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InkjetScale.GUI.LogViews", "InkjetScale.GUI.LogViews\InkjetScale.GUI.LogViews.csproj", "{799D6601-8F88-4C27-8952-7760BAE9DA0C}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InkjetScale.BusinessLogic.Scale", "InkjetScale.BusinessLogic.Scale\InkjetScale.BusinessLogic.Scale.csproj", "{577C09AA-94AB-4F4F-9398-A93586049D1D}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -74,6 +76,12 @@ Global
 		{799D6601-8F88-4C27-8952-7760BAE9DA0C}.Release|Any CPU.Build.0 = Release|Any CPU
 		{799D6601-8F88-4C27-8952-7760BAE9DA0C}.Remote_LAB|Any CPU.ActiveCfg = Remote_LAB|Any CPU
 		{799D6601-8F88-4C27-8952-7760BAE9DA0C}.Remote_LAB|Any CPU.Build.0 = Remote_LAB|Any CPU
+		{577C09AA-94AB-4F4F-9398-A93586049D1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{577C09AA-94AB-4F4F-9398-A93586049D1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{577C09AA-94AB-4F4F-9398-A93586049D1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{577C09AA-94AB-4F4F-9398-A93586049D1D}.Release|Any CPU.Build.0 = Release|Any CPU
+		{577C09AA-94AB-4F4F-9398-A93586049D1D}.Remote_LAB|Any CPU.ActiveCfg = Release|Any CPU
+		{577C09AA-94AB-4F4F-9398-A93586049D1D}.Remote_LAB|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -86,6 +94,7 @@ Global
 		{BC7536F1-00FA-4970-8460-22B63D280108} = {6EDF61B6-2F29-413F-B76E-D360900B056D}
 		{3DDA8868-7FC0-4014-AA47-9375E608BD0C} = {96A2A34C-DFF8-484E-A6BC-349EEC2B8C76}
 		{799D6601-8F88-4C27-8952-7760BAE9DA0C} = {27AC19C6-C633-4862-A69E-42681B82C011}
+		{577C09AA-94AB-4F4F-9398-A93586049D1D} = {96A2A34C-DFF8-484E-A6BC-349EEC2B8C76}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {4CA81647-D0FF-4C4A-AAA8-BF923044E336}

+ 10 - 1
InkjetScale/InkjetScale/App.xaml.cs

@@ -1,4 +1,5 @@
-using InkjetScale.GUI.LogViews;
+using InkjetScale.BusinessLogic.Scale;
+using InkjetScale.GUI.LogViews;
 using InkjetScale.GUI.MainViews;
 using InkjetScale.GUI.ScaleControlViews;
 using Prism.Ioc;
@@ -26,6 +27,8 @@ namespace InkjetScale
 
         private void PrismApplication_Exit(object sender, ExitEventArgs e)
         {
+            var scaleManager = this.Container.Resolve<ScaleManager>();
+            scaleManager.Dispose();
         }
 
 
@@ -39,6 +42,12 @@ namespace InkjetScale
         {
             containerRegistry.RegisterInstance(this.Container);
             containerRegistry.RegisterInstance(containerRegistry);
+
+            if (!containerRegistry.IsRegistered<ScaleManager>())
+                containerRegistry.RegisterSingleton<ScaleManager>();
+
+            var scaleManager = this.Container.Resolve<ScaleManager>();
+            scaleManager.InitSerial();
         }
 
         protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)

+ 4 - 0
InkjetScale/InkjetScale/InkjetScale.csproj

@@ -152,6 +152,10 @@
       <Project>{3DDA8868-7FC0-4014-AA47-9375E608BD0C}</Project>
       <Name>InkjetScale.BusinessLogic.Admin</Name>
     </ProjectReference>
+    <ProjectReference Include="..\InkjetScale.BusinessLogic.Scale\InkjetScale.BusinessLogic.Scale.csproj">
+      <Project>{577C09AA-94AB-4F4F-9398-A93586049D1D}</Project>
+      <Name>InkjetScale.BusinessLogic.Scale</Name>
+    </ProjectReference>
     <ProjectReference Include="..\InkjetScale.Common\InkjetScale.Common.csproj">
       <Project>{bc7536f1-00fa-4970-8460-22b63d280108}</Project>
       <Name>InkjetScale.Common</Name>

+ 0 - 5
InkjetScale/InkjetScale/ShellViewModel.cs

@@ -123,14 +123,9 @@ namespace InkjetScale
         private void ExecuteExit()
         {
             Systemtimer.Stop();
-            SystemExitPubEvent();
             App.Current.Shutdown();
         }
 
-        private void SystemExitPubEvent()
-        {
-            this.eventAggregator.GetEvent<SystemExitEvent>().Publish(true);
-        }
 
         private void ExecuteNavigate(string view)
         {