add debug print command

This commit is contained in:
kwan.nguyen 2024-10-25 14:23:29 +07:00
parent 2b925a8ffa
commit 1e425a3e7e
5 changed files with 60 additions and 13 deletions

View File

@ -247,6 +247,7 @@
<DependentUpon>UserListPage.xaml</DependentUpon> <DependentUpon>UserListPage.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModels\CutDialogViewModel.cs" />
<Compile Include="ViewModels\LogViewModel.cs" /> <Compile Include="ViewModels\LogViewModel.cs" />
<Compile Include="ViewModels\UpsertMetadataViewModel.cs" /> <Compile Include="ViewModels\UpsertMetadataViewModel.cs" />
<Compile Include="ViewModels\CategoriesViewModel.cs" /> <Compile Include="ViewModels\CategoriesViewModel.cs" />

View File

@ -9,7 +9,7 @@
<Identity <Identity
Name="ac171214-3336-4e02-845d-9bdc107cce71" Name="ac171214-3336-4e02-845d-9bdc107cce71"
Publisher="CN=pcut, O=PCUT, L=HN, S=HN, C=VN" Publisher="CN=pcut, O=PCUT, L=HN, S=HN, C=VN"
Version="1.3.3.0" /> Version="1.3.4.0" />
<mp:PhoneIdentity PhoneProductId="ac171214-3336-4e02-845d-9bdc107cce71" PhonePublisherId="00000000-0000-0000-0000-000000000000"/> <mp:PhoneIdentity PhoneProductId="ac171214-3336-4e02-845d-9bdc107cce71" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

View File

@ -8,6 +8,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" mc:Ignorable="d"
Opened="ContentDialog_Opened"> Opened="ContentDialog_Opened">
<ContentDialog.DataContext>
<localVM:CutDialogViewModel/>
</ContentDialog.DataContext>
<ContentDialog.Resources> <ContentDialog.Resources>
<localVM:ComponentStyle x:Key="previewStyle"/> <localVM:ComponentStyle x:Key="previewStyle"/>
</ContentDialog.Resources> </ContentDialog.Resources>
@ -16,7 +19,8 @@
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="0.1*"/> <RowDefinition Height="0.1*"/>
<RowDefinition Height="0.1*"/> <RowDefinition Height="0.1*"/>
<RowDefinition x:Name="PreviewRowDefinition" Height="0.7*"/> <RowDefinition x:Name="PreviewRowDefinition" Height="0.6*"/>
<RowDefinition Height="0.1*" MinHeight="100"/>
<RowDefinition Height="0.1*"/> <RowDefinition Height="0.1*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@ -61,7 +65,18 @@
Margin="5 0 0 0"/> Margin="5 0 0 0"/>
<TextBlock Text="(mm)" Foreground="{ThemeResource SystemAccentColor}" VerticalAlignment="Center" Margin="5 0 0 0" /> <TextBlock Text="(mm)" Foreground="{ThemeResource SystemAccentColor}" VerticalAlignment="Center" Margin="5 0 0 0" />
</StackPanel> </StackPanel>
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Center"> <StackPanel Grid.Row="3" Height="92" MaxHeight="92" Margin="0 4 0 4">
<TextBlock Text="Print Command:" Height="16" Margin="0 0 0 4"/>
<TextBox
Text="{Binding PrintCommand}"
Height="72"
MaxHeight="72"
IsReadOnly="True"
TextWrapping="Wrap"
ScrollViewer.VerticalScrollMode="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"/>
</StackPanel>
<StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Center">
<Button x:Name="CancelButton" Style="{StaticResource CloseDialogButton}" Width="150" Click="CancelButton_Click">Cancel</Button> <Button x:Name="CancelButton" Style="{StaticResource CloseDialogButton}" Width="150" Click="CancelButton_Click">Cancel</Button>
<Button x:Name="StartButton" Style="{StaticResource PrimaryDialogButton}" Width="150" Margin="10 0 0 0" Click="StartButton_Click">Start</Button> <Button x:Name="StartButton" Style="{StaticResource PrimaryDialogButton}" Width="150" Margin="10 0 0 0" Click="StartButton_Click">Start</Button>
</StackPanel> </StackPanel>

View File

@ -11,6 +11,7 @@ using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using Windows.ApplicationModel.Core;
using Windows.Foundation; using Windows.Foundation;
using Windows.Foundation.Collections; using Windows.Foundation.Collections;
using Windows.UI.Popups; using Windows.UI.Popups;
@ -33,6 +34,7 @@ namespace PCUT.Pages
private readonly string _portName; private readonly string _portName;
private readonly PortSettingViewModel _portSettings; private readonly PortSettingViewModel _portSettings;
private readonly DesignCenterViewModel _designCenterViewModel; private readonly DesignCenterViewModel _designCenterViewModel;
private CutDialogViewModel ViewModels;
public CutFilesDialog( public CutFilesDialog(
string portName, string portName,
@ -44,7 +46,9 @@ namespace PCUT.Pages
_portName = portName; _portName = portName;
_portSettings = portSetting; _portSettings = portSetting;
_designCenterViewModel = designCenterViewModel; _designCenterViewModel = designCenterViewModel;
StartButton.IsEnabled = !(portName is null); //StartButton.IsEnabled = !(portName is null);
ViewModels = DataContext as CutDialogViewModel;
} }
private Task _printTask; private Task _printTask;
@ -79,12 +83,13 @@ namespace PCUT.Pages
} }
_cancellationTokenSource = new CancellationTokenSource(); _cancellationTokenSource = new CancellationTokenSource();
using (var serialPort = new SerialPort(_portName, _portSettings.BaudRate) ViewModels.PrintCommand = string.Empty;
{ //using (var serialPort = new SerialPort(_portName, _portSettings.BaudRate)
DataBits = _portSettings.Databits, //{
Parity = _portSettings.ParityList[_portSettings.SelectedParity], // DataBits = _portSettings.Databits,
StopBits = _portSettings.StopbitsList[_portSettings.SelectedStopbits] // Parity = _portSettings.ParityList[_portSettings.SelectedParity],
}) // StopBits = _portSettings.StopbitsList[_portSettings.SelectedStopbits]
//})
{ {
var errorMessage = string.Empty; var errorMessage = string.Empty;
try try
@ -95,15 +100,19 @@ namespace PCUT.Pages
(_svgData.OriginWidth.Value, _svgData.OriginHeight.Value), (_svgData.OriginWidth.Value, _svgData.OriginHeight.Value),
(_designCenterViewModel.Width, _designCenterViewModel.Height), (_designCenterViewModel.Width, _designCenterViewModel.Height),
_portSettings.Speed); _portSettings.Speed);
serialPort.Open(); //serialPort.Open();
Task waitTask = Task.CompletedTask; Task waitTask = Task.CompletedTask;
foreach (var (path, waitTime) in data) foreach (var (path, waitTime) in data)
{ {
_cancellationTokenSource.Token.ThrowIfCancellationRequested(); _cancellationTokenSource.Token.ThrowIfCancellationRequested();
_ = CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
ViewModels.PrintCommand += path;
});
waitTask.Wait(); waitTask.Wait();
try try
{ {
serialPort.Write(path); //serialPort.Write(path);
} }
catch catch
{ {
@ -141,7 +150,7 @@ namespace PCUT.Pages
{ {
try try
{ {
serialPort.Close(); //serialPort.Close();
Task.Delay(1000).Wait(); Task.Delay(1000).Wait();
} }
catch catch

View File

@ -0,0 +1,22 @@
using PCUT.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PCUT.ViewModels
{
internal class CutDialogViewModel : NotificationBase
{
private string _printCommand;
public string PrintCommand
{
get => _printCommand;
set
{
SetProperty(ref _printCommand, value);
}
}
}
}