Skip to content

Commit a3c1bb0

Browse files
committed
Change memory address data type from short to ushort
1 parent c3906e9 commit a3c1bb0

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

Components/ParallelPorts.Windows.WPF/HexShortConverter.cs renamed to Components/ParallelPorts.Windows.WPF/HexUShortConverter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
using System.Windows.Data;
66

77
namespace OpenSense.WPF.Components.ParallelPorts {
8-
internal sealed class HexShortConverter : IValueConverter {
8+
internal sealed class HexUShortConverter : IValueConverter {
99
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
10-
return value is short s ? s.ToString("X4") : string.Empty;
10+
return value is ushort s ? s.ToString("X4") : string.Empty;
1111
}
1212

1313
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
1414
var text = value?.ToString();
1515
return string.IsNullOrWhiteSpace(text) ?
16-
(short)0
16+
(ushort)0
1717
:
18-
short.TryParse(text.Trim(), NumberStyles.HexNumber, null, out var result) ?
18+
ushort.TryParse(text.Trim(), NumberStyles.HexNumber, null, out var result) ?
1919
result
2020
:
21-
(short)0;
21+
(ushort)0;
2222
}
2323
}
2424
}

Components/ParallelPorts.Windows.WPF/ParallelPortPinPullerConfigurationControl.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<UserControl.Resources>
1717
<local:HexByteConverter
1818
x:Key="HexByteConverter" />
19-
<local:HexShortConverter
20-
x:Key="HexShortConverter" />
19+
<local:HexUShortConverter
20+
x:Key="HexUShortConverter" />
2121
</UserControl.Resources>
2222
<Grid>
2323
<Grid.ColumnDefinitions>
@@ -48,7 +48,7 @@
4848
<TextBox
4949
Grid.Row="0"
5050
Grid.Column="1"
51-
Text="{Binding MemoryAddress, Converter={StaticResource HexShortConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
51+
Text="{Binding MemoryAddress, Converter={StaticResource HexUShortConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
5252

5353
<TextBlock
5454
Grid.Row="1"

Components/ParallelPorts.Windows/ParallelPortPinPuller.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public sealed class ParallelPortPinPuller : IConsumer<byte>, IProducer<byte>, IN
1515
#endregion
1616

1717
#region Options
18-
private short memoryAddress = 0x378;
18+
private ushort memoryAddress = 0x0378;
1919

2020
/// <remarks>
21-
/// Inpoutx64 uses signed short for memory address. Here we follow its convention.
21+
/// Inpoutx64 uses signed short for memory address. Here we use common convention of unsigned short.
2222
/// </remarks>
23-
public short MemoryAddress {
23+
public ushort MemoryAddress {
2424
get => memoryAddress;
2525
set => SetProperty(ref memoryAddress, value);
2626
}
@@ -88,7 +88,7 @@ private void OnPipelineRun(object? sender, PipelineRunEventArgs e) {
8888
if (!SetOnStart) {
8989
return;
9090
}
91-
Inpoutx64PInvoke.Out32(MemoryAddress, SetOnStartValue);
91+
Inpoutx64PInvoke.Out32((short)MemoryAddress, SetOnStartValue);
9292
var timestamp = UseSourceOriginatingTime ? e.StartOriginatingTime : Out.Pipeline.GetCurrentTime();
9393
Out.Post(SetOnStartValue, timestamp);
9494
}
@@ -97,12 +97,12 @@ private void OnPipelineCompleted(object? sender, PipelineCompletedEventArgs e) {
9797
if (!SetAfterStop) {
9898
return;
9999
}
100-
Inpoutx64PInvoke.Out32(MemoryAddress, SetAfterStopValue);
100+
Inpoutx64PInvoke.Out32((short)MemoryAddress, SetAfterStopValue);
101101
}
102102
#endregion
103103

104104
private void Process(byte value, Envelope envelope) {
105-
Inpoutx64PInvoke.Out32(MemoryAddress, value);
105+
Inpoutx64PInvoke.Out32((short)MemoryAddress, value);
106106
var timestamp = UseSourceOriginatingTime ? envelope.OriginatingTime : Out.Pipeline.GetCurrentTime();
107107
Out.Post(value, timestamp);
108108
}

Components/ParallelPorts.Windows/ParallelPortPinPullerConfiguration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ public class ParallelPortPinPullerConfiguration : ConventionalComponentConfigura
99
private static readonly ParallelPortPinPullerMetadata Metadata = new();
1010

1111
#region Settings
12-
private short memoryAddress = 0x378;
12+
private ushort memoryAddress = 0x0378;
1313

1414
/// <remarks>
15-
/// Inpoutx64 uses signed short for memory address. Here we follow its convention.
15+
/// Inpoutx64 uses signed short for memory address. Here we use common convention of unsigned short.
1616
/// </remarks>
17-
public short MemoryAddress {
17+
public ushort MemoryAddress {
1818
get => memoryAddress;
1919
set => SetProperty(ref memoryAddress, value);
2020
}

0 commit comments

Comments
 (0)