diff --git a/App/.editorconfig b/App/.editorconfig
new file mode 100644
index 0000000..4aaad81
--- /dev/null
+++ b/App/.editorconfig
@@ -0,0 +1,280 @@
+# editorconfig.org
+
+# top-most EditorConfig file
+root = true
+
+# Default settings:
+# A newline ending every file
+# Use 4 spaces as indentation
+[*]
+insert_final_newline = true
+indent_style = space
+indent_size = 4
+dotnet_style_operator_placement_when_wrapping = beginning_of_line
+tab_width = 4
+end_of_line = crlf
+dotnet_style_coalesce_expression = true:suggestion
+dotnet_style_null_propagation = true:suggestion
+dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
+dotnet_style_prefer_auto_properties = true:silent
+dotnet_style_object_initializer = true:suggestion
+dotnet_style_collection_initializer = true:suggestion
+dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
+dotnet_style_prefer_conditional_expression_over_assignment = true:silent
+dotnet_style_prefer_conditional_expression_over_return = true:silent
+dotnet_style_explicit_tuple_names = true:suggestion
+dotnet_style_prefer_inferred_tuple_names = true:suggestion
+dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
+dotnet_style_prefer_compound_assignment = true:suggestion
+dotnet_style_prefer_simplified_interpolation = true:suggestion
+dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
+dotnet_style_namespace_match_folder = true:suggestion
+
+# C# files
+[*.cs]
+# New line preferences
+csharp_new_line_before_open_brace = all
+csharp_new_line_before_else = true
+csharp_new_line_before_catch = true
+csharp_new_line_before_finally = true
+csharp_new_line_before_members_in_object_initializers = true
+csharp_new_line_before_members_in_anonymous_types = true
+csharp_new_line_between_query_expression_clauses = true
+# trim_trailing_whitespace = true
+
+# Indentation preferences
+csharp_indent_block_contents = true
+csharp_indent_braces = false
+csharp_indent_case_contents = true
+csharp_indent_switch_labels = true
+csharp_indent_labels = one_less_than_current
+
+# avoid this. unless absolutely necessary
+dotnet_style_qualification_for_field = false:suggestion
+dotnet_style_qualification_for_property = false:suggestion
+dotnet_style_qualification_for_method = false:suggestion
+dotnet_style_qualification_for_event = false:suggestion
+
+# prefer var
+csharp_style_var_for_built_in_types = true
+csharp_style_var_when_type_is_apparent = true
+csharp_style_var_elsewhere = true:suggestion
+
+# use language keywords instead of BCL types
+dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
+dotnet_style_predefined_type_for_member_access = true:suggestion
+
+# name all constant fields using PascalCase
+dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
+dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
+
+dotnet_naming_symbols.constant_fields.applicable_kinds = field
+dotnet_naming_symbols.constant_fields.required_modifiers = const
+
+dotnet_naming_style.pascal_case_style.capitalization = pascal_case
+
+# private static fields should have s_ prefix
+dotnet_naming_rule.private_static_fields_should_have_prefix.severity = suggestion
+dotnet_naming_rule.private_static_fields_should_have_prefix.symbols = private_static_fields
+dotnet_naming_rule.private_static_fields_should_have_prefix.style = private_static_prefix_style
+
+dotnet_naming_symbols.private_static_fields.applicable_kinds = field
+dotnet_naming_symbols.private_static_fields.required_modifiers = static
+dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private
+
+dotnet_naming_style.private_static_prefix_style.required_prefix = s_
+dotnet_naming_style.private_static_prefix_style.capitalization = camel_case
+
+# internal and private fields should be _camelCase
+dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
+dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
+dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
+
+dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
+dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
+
+dotnet_naming_style.camel_case_underscore_style.required_prefix = _
+dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
+
+# use accessibility modifiers
+dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
+
+# Code style defaults
+dotnet_sort_system_directives_first = true
+csharp_preserve_single_line_blocks = true
+csharp_preserve_single_line_statements = false
+
+# Expression-level preferences
+dotnet_style_object_initializer = true:suggestion
+dotnet_style_collection_initializer = true:suggestion
+dotnet_style_explicit_tuple_names = true:suggestion
+dotnet_style_coalesce_expression = true:suggestion
+dotnet_style_null_propagation = true:suggestion
+
+# Expression-bodied members
+csharp_style_expression_bodied_methods = false:none
+csharp_style_expression_bodied_constructors = false:none
+csharp_style_expression_bodied_operators = false:none
+csharp_style_expression_bodied_properties = true:none
+csharp_style_expression_bodied_indexers = true:none
+csharp_style_expression_bodied_accessors = true:none
+
+# Pattern matching
+csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
+csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
+csharp_style_inlined_variable_declaration = true:suggestion
+
+# Null checking preferences
+csharp_style_throw_expression = true:suggestion
+csharp_style_conditional_delegate_call = true:suggestion
+
+# Space preferences
+csharp_space_after_cast = false
+csharp_space_after_colon_in_inheritance_clause = true
+csharp_space_after_comma = true
+csharp_space_after_dot = false
+csharp_space_after_keywords_in_control_flow_statements = true
+csharp_space_after_semicolon_in_for_statement = true
+csharp_space_around_binary_operators = before_and_after
+csharp_space_around_declaration_statements = false
+csharp_space_before_colon_in_inheritance_clause = true
+csharp_space_before_comma = false
+csharp_space_before_dot = false
+csharp_space_before_open_square_brackets = false
+csharp_space_before_semicolon_in_for_statement = false
+csharp_space_between_empty_square_brackets = false
+csharp_space_between_method_call_empty_parameter_list_parentheses = false
+csharp_space_between_method_call_name_and_opening_parenthesis = false
+csharp_space_between_method_call_parameter_list_parentheses = false
+csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
+csharp_space_between_method_declaration_name_and_open_parenthesis = false
+csharp_space_between_method_declaration_parameter_list_parentheses = false
+csharp_space_between_parentheses = false
+csharp_space_between_square_brackets = false
+space_within_single_line_array_initializer_braces = true
+
+#Net Analyzer
+dotnet_analyzer_diagnostic.category-Performance.severity = none #error - Uncomment when all violations are fixed.
+
+# CS0649: Field 'field' is never assigned to, and will always have its default value 'value'
+dotnet_diagnostic.CS0649.severity = error
+
+# CS1591: Missing XML comment for publicly visible type or member
+dotnet_diagnostic.CS1591.severity = suggestion
+
+# CS0162: Remove unreachable code
+dotnet_diagnostic.CS0162.severity = error
+# CA1018: Mark attributes with AttributeUsageAttribute
+dotnet_diagnostic.CA1018.severity = error
+# CA1304: Specify CultureInfo
+dotnet_diagnostic.CA1304.severity = warning
+# CA1802: Use literals where appropriate
+dotnet_diagnostic.CA1802.severity = warning
+# CA1813: Avoid unsealed attributes
+dotnet_diagnostic.CA1813.severity = error
+# CA1815: Override equals and operator equals on value types
+dotnet_diagnostic.CA1815.severity = warning
+# CA1820: Test for empty strings using string length
+dotnet_diagnostic.CA1820.severity = warning
+# CA1821: Remove empty finalizers
+dotnet_diagnostic.CA1821.severity = error
+# CA1822: Mark members as static
+dotnet_diagnostic.CA1822.severity = suggestion
+dotnet_code_quality.CA1822.api_surface = private, internal
+# CA1823: Avoid unused private fields
+dotnet_diagnostic.CA1823.severity = error
+# CA1825: Avoid zero-length array allocations
+dotnet_diagnostic.CA1825.severity = warning
+# CA1826: Use property instead of Linq Enumerable method
+dotnet_diagnostic.CA1826.severity = suggestion
+# CA1827: Do not use Count/LongCount when Any can be used
+dotnet_diagnostic.CA1827.severity = warning
+# CA1828: Do not use CountAsync/LongCountAsync when AnyAsync can be used
+dotnet_diagnostic.CA1828.severity = warning
+# CA1829: Use Length/Count property instead of Enumerable.Count method
+dotnet_diagnostic.CA1829.severity = warning
+#CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters
+dotnet_diagnostic.CA1847.severity = warning
+# CA1851: Possible multiple enumerations of IEnumerable collection
+dotnet_diagnostic.CA1851.severity = warning
+#CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method
+dotnet_diagnostic.CA1854.severity = warning
+#CA2211:Non-constant fields should not be visible
+dotnet_diagnostic.CA2211.severity = error
+
+# Wrapping preferences
+csharp_wrap_before_ternary_opsigns = false
+
+# Avalonia DevAnalyzer preferences
+dotnet_diagnostic.AVADEV2001.severity = error
+
+# Avalonia PublicAnalyzer preferences
+dotnet_diagnostic.AVP1000.severity = error
+dotnet_diagnostic.AVP1001.severity = error
+dotnet_diagnostic.AVP1002.severity = error
+dotnet_diagnostic.AVP1010.severity = error
+dotnet_diagnostic.AVP1011.severity = error
+dotnet_diagnostic.AVP1012.severity = warning
+dotnet_diagnostic.AVP1013.severity = error
+dotnet_diagnostic.AVP1020.severity = error
+dotnet_diagnostic.AVP1021.severity = error
+dotnet_diagnostic.AVP1022.severity = error
+dotnet_diagnostic.AVP1030.severity = error
+dotnet_diagnostic.AVP1031.severity = error
+dotnet_diagnostic.AVP1032.severity = error
+dotnet_diagnostic.AVP1040.severity = error
+dotnet_diagnostic.AVA2001.severity = error
+csharp_using_directive_placement = outside_namespace:silent
+csharp_prefer_simple_using_statement = true:suggestion
+csharp_prefer_braces = true:silent
+csharp_style_namespace_declarations = block_scoped:silent
+csharp_style_prefer_method_group_conversion = true:silent
+csharp_style_prefer_top_level_statements = true:silent
+csharp_style_prefer_primary_constructors = true:suggestion
+csharp_prefer_system_threading_lock = true:suggestion
+csharp_style_expression_bodied_lambdas = true:silent
+csharp_style_expression_bodied_local_functions = false:silent
+
+# Xaml files
+[*.{xaml,axaml}]
+indent_size = 2
+# DuplicateSetterError
+avalonia_xaml_diagnostic.AVLN2203.severity = error
+# StyleInMergedDictionaries
+avalonia_xaml_diagnostic.AVLN2204.severity = error
+# RequiredTemplatePartMissing
+avalonia_xaml_diagnostic.AVLN2205.severity = error
+# OptionalTemplatePartMissing
+avalonia_xaml_diagnostic.AVLN2206.severity = info
+# TemplatePartWrongType
+avalonia_xaml_diagnostic.AVLN2207.severity = error
+# ItemContainerInsideTemplate
+avalonia_xaml_diagnostic.AVLN2208.severity = error
+# Obsolete
+avalonia_xaml_diagnostic.AVLN5001.severity = error
+
+# Xml project files
+[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
+indent_size = 2
+
+# Xml build files
+[*.builds]
+indent_size = 2
+
+# Xml files
+[*.{xml,stylecop,resx,ruleset}]
+indent_size = 2
+
+# Xml config files
+[*.{props,targets,config,nuspec}]
+indent_size = 2
+
+[*.json]
+indent_size = 2
+
+# Shell scripts
+[*.sh]
+end_of_line = lf
+[*.{cmd,bat}]
+end_of_line = crlf
diff --git a/App/.gitignore b/App/.gitignore
new file mode 100644
index 0000000..4dd3751
--- /dev/null
+++ b/App/.gitignore
@@ -0,0 +1,453 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Mono auto generated files
+mono_crash.*
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+[Ww][Ii][Nn]32/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
+bld/
+[Bb]in/
+[Oo]bj/
+[Ll]og/
+[Ll]ogs/
+
+# Visual Studio 2015/2017 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUnit
+*.VisualState.xml
+TestResult.xml
+nunit-*.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+# Tye
+.tye/
+
+# ASP.NET Scaffolding
+ScaffoldingReadMe.txt
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
+*_i.c
+*_p.c
+*_h.h
+*.ilk
+*.meta
+*.obj
+*.iobj
+*.pch
+*.pdb
+*.ipdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*_wpftmp.csproj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# Visual Studio Trace Files
+*.e2e
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Coverlet is a free, cross platform Code Coverage Tool
+coverage*.json
+coverage*.xml
+coverage*.info
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# NuGet Symbol Packages
+*.snupkg
+# The packages folder can be ignored because of Package Restore
+**/[Pp]ackages/*
+# except build/, which is used as an MSBuild target.
+!**/[Pp]ackages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!?*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+orleans.codegen.cs
+
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
+
+# SQL Server files
+*.mdf
+*.ldf
+*.ndf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+*.rptproj.rsuser
+*- [Bb]ackup.rdl
+*- [Bb]ackup ([0-9]).rdl
+*- [Bb]ackup ([0-9][0-9]).rdl
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+node_modules/
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
+
+# Ionide (cross platform F# VS Code tools) working folder
+.ionide/
+
+# Fody - auto-generated XML schema
+FodyWeavers.xsd
+
+##
+## Visual studio for Mac
+##
+
+
+# globs
+Makefile.in
+*.userprefs
+*.usertasks
+config.make
+config.status
+aclocal.m4
+install-sh
+autom4te.cache/
+*.tar.gz
+tarballs/
+test-results/
+
+# Mac bundle stuff
+*.dmg
+
+# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
+# General
+.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+
+# Thumbnails
+._*
+
+# Files that might appear in the root of a volume
+.DocumentRevisions-V100
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+.VolumeIcon.icns
+.com.apple.timemachine.donotpresent
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdisk
+
+# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
+# Windows thumbnail cache files
+Thumbs.db
+ehthumbs.db
+ehthumbs_vista.db
+
+# Dump file
+*.stackdump
+
+# Folder config file
+[Dd]esktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Windows Installer files
+*.cab
+*.msi
+*.msix
+*.msm
+*.msp
+
+# Windows shortcuts
+*.lnk
+
+# JetBrains Rider
+.idea/
+*.sln.iml
+
+##
+## Visual Studio Code
+##
+.vscode/*
+!.vscode/settings.json
+!.vscode/tasks.json
+!.vscode/launch.json
+!.vscode/extensions.json
diff --git a/App/Directory.Build.props b/App/Directory.Build.props
new file mode 100644
index 0000000..4d9a552
--- /dev/null
+++ b/App/Directory.Build.props
@@ -0,0 +1,7 @@
+
+
+ enable
+ 11.2.6
+ 1.0.0
+
+
diff --git a/App/Harp.LoadCells.App.sln b/App/Harp.LoadCells.App.sln
new file mode 100644
index 0000000..411e5e0
--- /dev/null
+++ b/App/Harp.LoadCells.App.sln
@@ -0,0 +1,41 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.12.35707.178
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{EB0D5F63-BC4F-49DC-B7B3-02E48F1B0C64}") = "Harp.LoadCells.App", "Harp.LoadCells.App\Harp.LoadCells.App.csproj", "{0E27295C-F856-47ED-B978-D4C4202A0F22}"
+EndProject
+Project("{EB0D5F63-BC4F-49DC-B7B3-02E48F1B0C64}") = "Harp.LoadCells.Design", "Harp.LoadCells.Design\Harp.LoadCells.Design.csproj", "{744754F8-E47C-44F9-A451-2DD93C0AF6E7}"
+EndProject
+Project("{EB0D5F63-BC4F-49DC-B7B3-02E48F1B0C64}") = "Harp.LoadCells", "..\Interface\Harp.LoadCells\Harp.LoadCells.csproj", "{DB9716D6-0BD7-41A1-BA65-51D820BBB89B}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A4CB54F2-2C25-437E-B829-23DC9B47619A}"
+ ProjectSection(SolutionItems) = preProject
+ .editorconfig = .editorconfig
+ Harp.LoadCells.nsi = Harp.LoadCells.nsi
+ README.md = README.md
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {0E27295C-F856-47ED-B978-D4C4202A0F22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0E27295C-F856-47ED-B978-D4C4202A0F22}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0E27295C-F856-47ED-B978-D4C4202A0F22}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0E27295C-F856-47ED-B978-D4C4202A0F22}.Release|Any CPU.Build.0 = Release|Any CPU
+ {744754F8-E47C-44F9-A451-2DD93C0AF6E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {744754F8-E47C-44F9-A451-2DD93C0AF6E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {744754F8-E47C-44F9-A451-2DD93C0AF6E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {744754F8-E47C-44F9-A451-2DD93C0AF6E7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DB9716D6-0BD7-41A1-BA65-51D820BBB89B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DB9716D6-0BD7-41A1-BA65-51D820BBB89B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DB9716D6-0BD7-41A1-BA65-51D820BBB89B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DB9716D6-0BD7-41A1-BA65-51D820BBB89B}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/App/Harp.LoadCells.App/Harp.LoadCells.App.csproj b/App/Harp.LoadCells.App/Harp.LoadCells.App.csproj
new file mode 100644
index 0000000..47614a4
--- /dev/null
+++ b/App/Harp.LoadCells.App/Harp.LoadCells.App.csproj
@@ -0,0 +1,52 @@
+
+
+ WinExe
+
+ net8.0
+ enable
+ true
+ app.manifest
+ ..\bin\$(Configuration)
+ $(AppVersion)
+ ..\Harp.LoadCells.Design\Assets\cf-logo.ico
+ Harp.LoadCells.App
+
+
+
+ Harp.LoadCells.App
+ Harp.LoadCells.App
+ org.fchampalimaud
+ $(Version)
+ $(Version)
+ AAPL
+ .
+ Harp.LoadCells.App
+ cf-logo.icns
+ NSApplication
+ true
+ Champalimaud Foundation
+ ..\Harp.LoadCells.Design\Assets\cf-logo.ico
+ ..\README.md
+ git
+ ..\bin\$(Configuration)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/App/Harp.LoadCells.App/Program.cs b/App/Harp.LoadCells.App/Program.cs
new file mode 100644
index 0000000..8066c14
--- /dev/null
+++ b/App/Harp.LoadCells.App/Program.cs
@@ -0,0 +1,24 @@
+using System;
+
+using Avalonia;
+using Avalonia.ReactiveUI;
+
+namespace Harp.LoadCells.App;
+
+class Program
+{
+ // Initialization code. Don't use any Avalonia, third-party APIs or any
+ // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
+ // yet and stuff might break.
+ [STAThread]
+ public static void Main(string[] args) => BuildAvaloniaApp()
+ .StartWithClassicDesktopLifetime(args);
+
+ // Avalonia configuration, don't remove; also used by visual designer.
+ public static AppBuilder BuildAvaloniaApp()
+ => AppBuilder.Configure()
+ .UsePlatformDetect()
+ .WithInterFont()
+ .LogToTrace()
+ .UseReactiveUI();
+}
diff --git a/App/Harp.LoadCells.App/Properties/launchSettings.json b/App/Harp.LoadCells.App/Properties/launchSettings.json
new file mode 100644
index 0000000..33f0dab
--- /dev/null
+++ b/App/Harp.LoadCells.App/Properties/launchSettings.json
@@ -0,0 +1,11 @@
+{
+ "profiles": {
+ "Harp.LoadCells.App": {
+ "commandName": "Project"
+ },
+ "WSL": {
+ "commandName": "WSL",
+ "distributionName": ""
+ }
+ }
+}
\ No newline at end of file
diff --git a/App/Harp.LoadCells.App/app.manifest b/App/Harp.LoadCells.App/app.manifest
new file mode 100644
index 0000000..e0ce8d0
--- /dev/null
+++ b/App/Harp.LoadCells.App/app.manifest
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/App/Harp.LoadCells.Design/App.axaml b/App/Harp.LoadCells.Design/App.axaml
new file mode 100644
index 0000000..d143415
--- /dev/null
+++ b/App/Harp.LoadCells.Design/App.axaml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/App/Harp.LoadCells.Design/App.axaml.cs b/App/Harp.LoadCells.Design/App.axaml.cs
new file mode 100644
index 0000000..b3a391e
--- /dev/null
+++ b/App/Harp.LoadCells.Design/App.axaml.cs
@@ -0,0 +1,44 @@
+using System;
+using Avalonia;
+using Avalonia.Controls.ApplicationLifetimes;
+using Avalonia.Markup.Xaml;
+
+using Harp.LoadCells.Design.ViewModels;
+using Harp.LoadCells.Design.Views;
+
+namespace Harp.LoadCells.Design;
+
+public partial class App : Application
+{
+ public override void Initialize()
+ {
+ AvaloniaXamlLoader.Load(this);
+ }
+
+ public override void OnFrameworkInitializationCompleted()
+ {
+ if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+ {
+ desktop.MainWindow = new MainWindow
+ {
+ DataContext = new LoadCellsViewModel()
+ };
+ }
+ else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
+ {
+ singleViewPlatform.MainView = new LoadCellsView
+ {
+ DataContext = new LoadCellsViewModel()
+ };
+ }
+
+ base.OnFrameworkInitializationCompleted();
+ }
+
+ private void NativeMenuItem_OnClick(object sender, EventArgs e)
+ {
+ var about = new About() { DataContext = new AboutViewModel() };
+ about.ShowDialog((Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)
+ .MainWindow);
+ }
+}
diff --git a/App/Harp.LoadCells.Design/Assets/cf-logo-small.bmp b/App/Harp.LoadCells.Design/Assets/cf-logo-small.bmp
new file mode 100644
index 0000000..3d70185
Binary files /dev/null and b/App/Harp.LoadCells.Design/Assets/cf-logo-small.bmp differ
diff --git a/App/Harp.LoadCells.Design/Assets/cf-logo-white-lettering.png b/App/Harp.LoadCells.Design/Assets/cf-logo-white-lettering.png
new file mode 100644
index 0000000..ca64284
Binary files /dev/null and b/App/Harp.LoadCells.Design/Assets/cf-logo-white-lettering.png differ
diff --git a/App/Harp.LoadCells.Design/Assets/cf-logo-white-lettering.svg b/App/Harp.LoadCells.Design/Assets/cf-logo-white-lettering.svg
new file mode 100644
index 0000000..dc288cd
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Assets/cf-logo-white-lettering.svg
@@ -0,0 +1,224 @@
+
+
+
+
diff --git a/App/Harp.LoadCells.Design/Assets/cf-logo.icns b/App/Harp.LoadCells.Design/Assets/cf-logo.icns
new file mode 100644
index 0000000..d50056d
Binary files /dev/null and b/App/Harp.LoadCells.Design/Assets/cf-logo.icns differ
diff --git a/App/Harp.LoadCells.Design/Assets/cf-logo.ico b/App/Harp.LoadCells.Design/Assets/cf-logo.ico
new file mode 100644
index 0000000..7f15636
Binary files /dev/null and b/App/Harp.LoadCells.Design/Assets/cf-logo.ico differ
diff --git a/App/Harp.LoadCells.Design/Assets/cf-logo.png b/App/Harp.LoadCells.Design/Assets/cf-logo.png
new file mode 100644
index 0000000..007e30e
Binary files /dev/null and b/App/Harp.LoadCells.Design/Assets/cf-logo.png differ
diff --git a/App/Harp.LoadCells.Design/Assets/cf-logo.svg b/App/Harp.LoadCells.Design/Assets/cf-logo.svg
new file mode 100644
index 0000000..08e8841
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Assets/cf-logo.svg
@@ -0,0 +1,235 @@
+
+
+
+
diff --git a/App/Harp.LoadCells.Design/Assets/cf_hardware_software_logo.png b/App/Harp.LoadCells.Design/Assets/cf_hardware_software_logo.png
new file mode 100644
index 0000000..f8afc50
Binary files /dev/null and b/App/Harp.LoadCells.Design/Assets/cf_hardware_software_logo.png differ
diff --git a/App/Harp.LoadCells.Design/Assets/cf_hardware_software_logo.svg b/App/Harp.LoadCells.Design/Assets/cf_hardware_software_logo.svg
new file mode 100644
index 0000000..1896536
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Assets/cf_hardware_software_logo.svg
@@ -0,0 +1,94 @@
+
+
diff --git a/App/Harp.LoadCells.Design/Assets/cf_hardware_software_logo_white_lettering.png b/App/Harp.LoadCells.Design/Assets/cf_hardware_software_logo_white_lettering.png
new file mode 100644
index 0000000..e201b4b
Binary files /dev/null and b/App/Harp.LoadCells.Design/Assets/cf_hardware_software_logo_white_lettering.png differ
diff --git a/App/Harp.LoadCells.Design/Assets/cf_hardware_software_logo_white_lettering.svg b/App/Harp.LoadCells.Design/Assets/cf_hardware_software_logo_white_lettering.svg
new file mode 100644
index 0000000..c11b09a
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Assets/cf_hardware_software_logo_white_lettering.svg
@@ -0,0 +1,81 @@
+
+
+
+
diff --git a/App/Harp.LoadCells.Design/Controls/ExtendedColorPicker.cs b/App/Harp.LoadCells.Design/Controls/ExtendedColorPicker.cs
new file mode 100644
index 0000000..2f02938
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Controls/ExtendedColorPicker.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Reflection;
+using Avalonia.Controls;
+using Avalonia.Controls.Primitives;
+using Avalonia.Interactivity;
+
+namespace Harp.LoadCells.Design.Controls;
+
+// NOTE: This is currently needed because there's an issue in the ColorPicker control where
+// the SelectedIndex is not respected on load.
+public class ExtendedColorPicker : ColorPicker
+{
+ protected override Type StyleKeyOverride => typeof(ColorPicker);
+
+ private int _selectedTabIndex;
+
+ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
+ {
+ // There might be a property set in xaml that get's overridden here
+ _selectedTabIndex = SelectedIndex;
+ base.OnApplyTemplate(e);
+ }
+
+ protected override void OnLoaded(RoutedEventArgs e)
+ {
+ base.OnLoaded(e);
+
+ var type = typeof(ColorView);
+ if (type.GetField("_tabControl", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(this) is not TabControl tabControl)
+ return;
+ tabControl.SelectedIndex = _selectedTabIndex;
+ }
+}
diff --git a/App/Harp.LoadCells.Design/Controls/VisualStatus.axaml b/App/Harp.LoadCells.Design/Controls/VisualStatus.axaml
new file mode 100644
index 0000000..a737035
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Controls/VisualStatus.axaml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
diff --git a/App/Harp.LoadCells.Design/Controls/VisualStatus.axaml.cs b/App/Harp.LoadCells.Design/Controls/VisualStatus.axaml.cs
new file mode 100644
index 0000000..1035b49
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Controls/VisualStatus.axaml.cs
@@ -0,0 +1,21 @@
+using Avalonia;
+using Avalonia.Controls;
+
+namespace Harp.LoadCells.Design.Controls;
+
+public partial class VisualStatus : ContentControl
+{
+ public static readonly StyledProperty StatusProperty =
+ AvaloniaProperty.Register(nameof(Status), null);
+
+ public bool? Status
+ {
+ get => GetValue(StatusProperty);
+ set => SetValue(StatusProperty, value);
+ }
+
+ public VisualStatus()
+ {
+ InitializeComponent();
+ }
+}
diff --git a/App/Harp.LoadCells.Design/Controls/WriteMessagesControl.axaml b/App/Harp.LoadCells.Design/Controls/WriteMessagesControl.axaml
new file mode 100644
index 0000000..fd34d73
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Controls/WriteMessagesControl.axaml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/App/Harp.LoadCells.Design/Controls/WriteMessagesControl.axaml.cs b/App/Harp.LoadCells.Design/Controls/WriteMessagesControl.axaml.cs
new file mode 100644
index 0000000..1c26ddc
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Controls/WriteMessagesControl.axaml.cs
@@ -0,0 +1,11 @@
+using Avalonia.Controls;
+
+namespace Harp.LoadCells.Design.Controls;
+
+public partial class WriteMessagesControl : UserControl
+{
+ public WriteMessagesControl()
+ {
+ InitializeComponent();
+ }
+}
diff --git a/App/Harp.LoadCells.Design/Converters/EnableFlagConverter.cs b/App/Harp.LoadCells.Design/Converters/EnableFlagConverter.cs
new file mode 100644
index 0000000..ed7e278
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Converters/EnableFlagConverter.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Globalization;
+using Avalonia.Data.Converters;
+using Bonsai.Harp;
+
+namespace Harp.LoadCells.Design.Converters;
+
+///
+/// Converts between EnableFlag enum values and boolean values for two-way binding
+///
+public class EnableFlagConverter : IValueConverter
+{
+ public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
+ {
+ // Convert from enum to bool (for IsChecked)
+ if (value == null)
+ return false;
+
+ return value.ToString().Contains("Enable");
+ }
+
+ public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
+ {
+ // Convert from bool (IsChecked) to enum
+ if (value is not bool isChecked || parameter == null)
+ return null;
+
+ // Create the appropriate enum value based on the checkbox state
+ return isChecked ? EnableFlag.Enable : EnableFlag.Disable;
+ }
+}
diff --git a/App/Harp.LoadCells.Design/Converters/EnumDisplayConverter.cs b/App/Harp.LoadCells.Design/Converters/EnumDisplayConverter.cs
new file mode 100644
index 0000000..ca7b449
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Converters/EnumDisplayConverter.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using Avalonia.Data.Converters;
+
+namespace Harp.LoadCells.Design.Converters;
+
+public class EnumDisplayConverter : IValueConverter
+{
+ public Dictionary Mappings { get; set; } = new Dictionary();
+
+ public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
+ {
+ if (value == null)
+ return null;
+ var key = value.ToString();
+ return Mappings!.GetValueOrDefault(key, key);
+ }
+
+ public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
+ {
+ return null;
+ }
+}
diff --git a/App/Harp.LoadCells.Design/Converters/PayloadFieldConverter.cs b/App/Harp.LoadCells.Design/Converters/PayloadFieldConverter.cs
new file mode 100644
index 0000000..572913e
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Converters/PayloadFieldConverter.cs
@@ -0,0 +1,155 @@
+using System;
+using System.Globalization;
+using System.Reflection;
+using Avalonia.Data.Converters;
+
+namespace Harp.LoadCells.Design.Converters;
+
+public class PayloadFieldConverter : IValueConverter
+{
+ public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
+ {
+ if (value == null || parameter == null)
+ return null;
+
+ var fieldName = parameter.ToString();
+ var valueType = value.GetType();
+
+ // Handle struct types directly with field/property access
+ if (valueType.IsValueType && !valueType.IsPrimitive)
+ {
+ // Try direct field access first
+ var fieldInfo = valueType.GetField(fieldName);
+ if (fieldInfo != null)
+ {
+ return fieldInfo.GetValue(value);
+ }
+
+ // Try property access second
+ var propInfo = valueType.GetProperty(fieldName);
+ if (propInfo != null)
+ {
+ return propInfo.GetValue(value);
+ }
+ }
+
+ // For primitive types, use bit masking
+ // This handles any register with a maskType like DigitalOutputSyncPayload
+ // that is actually a simple number but needs masking
+ try
+ {
+ int mask = GetMaskForField(valueType, fieldName);
+ if (mask != 0)
+ {
+ int rawValue = System.Convert.ToInt32(value);
+ int shift = GetShiftForMask(mask);
+ int maskedValue = (rawValue & mask) >> shift;
+
+ // If targetType is an enum, convert to that enum type
+ if (targetType.IsEnum)
+ {
+ return Enum.ToObject(targetType, maskedValue);
+ }
+ return maskedValue;
+ }
+ }
+ catch
+ {
+ // Silently continue if mask extraction fails
+ }
+
+ return value;
+ }
+
+ public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
+ {
+ if (value == null || parameter == null)
+ return null;
+
+ var fieldName = parameter.ToString();
+
+ // Handle struct types - boxed copy approach
+ if (targetType.IsValueType && !targetType.IsPrimitive)
+ {
+ // Create a copy of the current target value if it exists
+ object currentValue = Activator.CreateInstance(targetType);
+
+ // Set the field/property on the copy
+ var fieldInfo = targetType.GetField(fieldName);
+ if (fieldInfo != null && currentValue != null)
+ {
+ object boxedCopy = currentValue;
+ fieldInfo.SetValue(boxedCopy, value);
+ return boxedCopy;
+ }
+
+ var propInfo = targetType.GetProperty(fieldName);
+ if (propInfo != null && propInfo.CanWrite && currentValue != null)
+ {
+ object boxedCopy = currentValue;
+ propInfo.SetValue(boxedCopy, value);
+ return boxedCopy;
+ }
+ }
+
+ // For primitive/enum types with bitmasks
+ try
+ {
+ int mask = GetMaskForField(targetType, fieldName);
+ if (mask != 0)
+ {
+ // Get the current value if available
+ int currentValue = 0;
+
+ // Extract the value from the selected enum
+ int newValue = System.Convert.ToInt32(value);
+ int shift = GetShiftForMask(mask);
+
+ // Apply the new value at the correct bit position
+ int result = (currentValue & ~mask) | ((newValue << shift) & mask);
+ return System.Convert.ChangeType(result, targetType);
+ }
+ }
+ catch
+ {
+ // Silently continue if mask extraction fails
+ }
+
+ // Default conversion
+ return value;
+ }
+
+ private int GetMaskForField(Type type, string fieldName)
+ {
+ // Try to find mask by reflection from payload specification
+ // This assumes there's a static class or field with mask information
+ try
+ {
+ Type payloadSpecType = Type.GetType($"{type.Namespace}.{type.Name}PayloadSpec");
+ if (payloadSpecType != null)
+ {
+ var maskField = payloadSpecType.GetField($"{fieldName}Mask", BindingFlags.Public | BindingFlags.Static);
+ if (maskField != null)
+ {
+ return (int)maskField.GetValue(null);
+ }
+ }
+ }
+ catch
+ {
+ // Ignore and use default
+ }
+ return 0;
+ }
+
+ private int GetShiftForMask(int mask)
+ {
+ int shift = 0;
+ while ((mask & 1) == 0 && shift < 32)
+ {
+ mask >>= 1;
+ shift++;
+ }
+ return shift;
+ }
+}
diff --git a/App/Harp.LoadCells.Design/Converters/RgbChannelConverter.cs b/App/Harp.LoadCells.Design/Converters/RgbChannelConverter.cs
new file mode 100644
index 0000000..922c14f
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Converters/RgbChannelConverter.cs
@@ -0,0 +1,111 @@
+using System;
+using System.Globalization;
+using System.Reflection;
+using Avalonia;
+using Avalonia.Data;
+using Avalonia.Data.Converters;
+using Avalonia.Media;
+
+namespace Harp.LoadCells.Design.Converters;
+
+public class RgbChannelConverter : IValueConverter
+{
+ // The RGB channel to extract (0 or 1)
+ public int Channel { get; set; }
+
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value == null)
+ return AvaloniaProperty.UnsetValue;
+
+ try
+ {
+ var type = value.GetType();
+
+ // Extract fields for the specified channel (0 or 1)
+ string redName = $"Red{Channel}";
+ string greenName = $"Green{Channel}";
+ string blueName = $"Blue{Channel}";
+
+ // Try to get the color components using reflection
+ var redMember = (MemberInfo?)type.GetProperty(redName) ?? type.GetField(redName);
+ var greenMember = (MemberInfo?)type.GetProperty(greenName) ?? type.GetField(greenName);
+ var blueMember = (MemberInfo?)type.GetProperty(blueName) ?? type.GetField(blueName);
+
+ if (redMember != null && greenMember != null && blueMember != null)
+ {
+ byte r = ExtractByteValue(redMember, value);
+ byte g = ExtractByteValue(greenMember, value);
+ byte b = ExtractByteValue(blueMember, value);
+
+ return Color.FromRgb(r, g, b);
+ }
+ }
+ catch
+ {
+ // Fall back to default color on error
+ return Colors.Gray;
+ }
+
+ return AvaloniaProperty.UnsetValue;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is not Color color)
+ return BindingOperations.DoNothing;
+
+ try
+ {
+ // Create a new instance or get the existing one
+ var instance = parameter as object ?? Activator.CreateInstance(targetType);
+ if (instance == null) // Ensure instance is not null
+ {
+ return BindingOperations.DoNothing;
+ }
+ var type = targetType;
+
+ // Determine field names for this channel
+ string redName = $"Red{Channel}";
+ string greenName = $"Green{Channel}";
+ string blueName = $"Blue{Channel}";
+
+ // Update the appropriate fields
+ var redMember = (MemberInfo?)type.GetProperty(redName) ?? type.GetField(redName);
+ var greenMember = (MemberInfo?)type.GetProperty(greenName) ?? type.GetField(greenName);
+ var blueMember = (MemberInfo?)type.GetProperty(blueName) ?? type.GetField(blueName);
+
+ if (redMember != null)
+ SetValue(redMember, instance, color.R);
+
+ if (greenMember != null)
+ SetValue(greenMember, instance, color.G);
+
+ if (blueMember != null)
+ SetValue(blueMember, instance, color.B);
+
+ return instance;
+ }
+ catch
+ {
+ return BindingOperations.DoNothing;
+ }
+ }
+
+ private byte ExtractByteValue(MemberInfo member, object source)
+ {
+ if (member is PropertyInfo prop)
+ return System.Convert.ToByte(prop.GetValue(source));
+ else if (member is FieldInfo field)
+ return System.Convert.ToByte(field.GetValue(source));
+ return 0;
+ }
+
+ private void SetValue(MemberInfo member, object target, byte value)
+ {
+ if (member is PropertyInfo prop)
+ prop.SetValue(target, value);
+ else if (member is FieldInfo field)
+ field.SetValue(target, value);
+ }
+}
\ No newline at end of file
diff --git a/App/Harp.LoadCells.Design/Converters/RgbColorConverter.cs b/App/Harp.LoadCells.Design/Converters/RgbColorConverter.cs
new file mode 100644
index 0000000..a9f105c
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Converters/RgbColorConverter.cs
@@ -0,0 +1,99 @@
+using System;
+using System.Globalization;
+using System.Reflection;
+using Avalonia;
+using Avalonia.Data;
+using Avalonia.Data.Converters;
+using Avalonia.Media;
+
+namespace Harp.LoadCells.Design.Converters;
+
+public class RgbColorConverter : IValueConverter
+{
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ // Handle RgbPayload structs or similar RGB-containing types
+ if (value != null)
+ {
+ var type = value.GetType();
+
+ // Handle RgbPayload type (struct/enum with Red, Green, Blue fields)
+ if (type.Name == "RgbPayload" || type.Name.Contains("Rgb"))
+ {
+ string redName = "Red";
+ string greenName = "Green";
+ string blueName = "Blue";
+
+ // Try to get the color components using reflection
+ var redMember = (MemberInfo?)type.GetProperty(redName) ?? type.GetField(redName);
+ var greenMember = (MemberInfo?)type.GetProperty(greenName) ?? type.GetField(greenName);
+ var blueMember = (MemberInfo?)type.GetProperty(blueName) ?? type.GetField(blueName);
+
+ if (redMember != null && greenMember != null && blueMember != null)
+ {
+ byte r = GetByteValue(redMember, value);
+ byte g = GetByteValue(greenMember, value);
+ byte b = GetByteValue(blueMember, value);
+
+ return Color.FromRgb(r, g, b);
+ }
+ }
+ }
+
+ return AvaloniaProperty.UnsetValue;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is Color color && targetType != null)
+ {
+ // Create a new instance of the target type (should be RgbPayload or similar)
+ var result = Activator.CreateInstance(targetType);
+ if (result == null) // Ensure result is not null
+ {
+ return BindingOperations.DoNothing;
+ }
+
+ var type = targetType;
+
+ string redName = "Red";
+ string greenName = "Green";
+ string blueName = "Blue";
+
+ // Update the appropriate fields
+ var redMember = (MemberInfo?)type.GetProperty(redName) ?? type.GetField(redName);
+ var greenMember = (MemberInfo?)type.GetProperty(greenName) ?? type.GetField(greenName);
+ var blueMember = (MemberInfo?)type.GetProperty(blueName) ?? type.GetField(blueName);
+
+ if (redMember != null)
+ SetValue(redMember, result, color.R);
+
+ if (greenMember != null)
+ SetValue(greenMember, result, color.G);
+
+ if (blueMember != null)
+ SetValue(blueMember, result, color.B);
+
+ return result;
+ }
+
+ return BindingOperations.DoNothing;
+ }
+
+ private byte GetByteValue(MemberInfo member, object source)
+ {
+ if (member is PropertyInfo prop)
+ return System.Convert.ToByte(prop.GetValue(source));
+ else if (member is FieldInfo field)
+ return System.Convert.ToByte(field.GetValue(source));
+ return 0;
+ }
+
+ private void SetValue(MemberInfo member, object target, byte value)
+ {
+ if (member is PropertyInfo prop)
+ prop.SetValue(target, value);
+ else if (member is FieldInfo field)
+ field.SetValue(target, value);
+ }
+}
diff --git a/App/Harp.LoadCells.Design/Converters/VisualStatusColorConverter.cs b/App/Harp.LoadCells.Design/Converters/VisualStatusColorConverter.cs
new file mode 100644
index 0000000..c022607
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Converters/VisualStatusColorConverter.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Globalization;
+using Avalonia.Data.Converters;
+using Avalonia.Media;
+
+namespace Harp.LoadCells.Design.Converters;
+
+public class VisualStatusColorConverter : IValueConverter
+{
+ public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
+ {
+ var status = value as bool?;
+ return status switch
+ {
+ true => new SolidColorBrush(Colors.Green),
+ false => new SolidColorBrush(Colors.Red),
+ _ => new SolidColorBrush(Colors.Gray)
+ };
+ }
+
+ public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) =>
+ throw new NotImplementedException();
+}
diff --git a/App/Harp.LoadCells.Design/FodyWeavers.xml b/App/Harp.LoadCells.Design/FodyWeavers.xml
new file mode 100644
index 0000000..63fc148
--- /dev/null
+++ b/App/Harp.LoadCells.Design/FodyWeavers.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/App/Harp.LoadCells.Design/Harp.LoadCells.Design.csproj b/App/Harp.LoadCells.Design/Harp.LoadCells.Design.csproj
new file mode 100644
index 0000000..00383c4
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Harp.LoadCells.Design.csproj
@@ -0,0 +1,31 @@
+
+
+ net8.0
+ enable
+ latest
+ true
+ ..\bin\$(Configuration)
+ $(AppVersion)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/App/Harp.LoadCells.Design/Styles/DefaultStyles.axaml b/App/Harp.LoadCells.Design/Styles/DefaultStyles.axaml
new file mode 100644
index 0000000..65d2028
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Styles/DefaultStyles.axaml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/App/Harp.LoadCells.Design/ViewModels/AboutViewModel.cs b/App/Harp.LoadCells.Design/ViewModels/AboutViewModel.cs
new file mode 100644
index 0000000..a4da518
--- /dev/null
+++ b/App/Harp.LoadCells.Design/ViewModels/AboutViewModel.cs
@@ -0,0 +1,5 @@
+namespace Harp.LoadCells.Design.ViewModels;
+
+internal class AboutViewModel : ViewModelBase
+{
+}
diff --git a/App/Harp.LoadCells.Design/ViewModels/MyDeviceViewModel.cs b/App/Harp.LoadCells.Design/ViewModels/MyDeviceViewModel.cs
new file mode 100644
index 0000000..d9e0ea1
--- /dev/null
+++ b/App/Harp.LoadCells.Design/ViewModels/MyDeviceViewModel.cs
@@ -0,0 +1,1874 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.IO.Ports;
+using System.Linq;
+using System.Reactive;
+using System.Reactive.Concurrency;
+using System.Reactive.Disposables;
+using System.Reactive.Linq;
+using System.Threading.Tasks;
+using Avalonia;
+using Avalonia.Controls.ApplicationLifetimes;
+using Bonsai.Harp;
+using Harp.LoadCells.Design.Views;
+using LiveChartsCore;
+using LiveChartsCore.Defaults;
+using LiveChartsCore.SkiaSharpView;
+using LiveChartsCore.SkiaSharpView.Painting;
+using MsBox.Avalonia;
+using MsBox.Avalonia.Enums;
+using ReactiveUI;
+using ReactiveUI.Fody.Helpers;
+using SkiaSharp;
+namespace Harp.LoadCells.Design.ViewModels;
+
+
+public class LoadCellsViewModel : ViewModelBase
+{
+ public string AppVersion { get; set; }
+ public ReactiveCommand LoadDeviceInformation { get; }
+
+ #region Connection Information
+
+ [Reactive] public ObservableCollection Ports { get; set; }
+ [Reactive] public string SelectedPort { get; set; }
+ [Reactive] public bool Connected { get; set; }
+ [Reactive] public string ConnectButtonText { get; set; } = "Connect";
+ public ReactiveCommand ConnectAndGetBaseInfoCommand { get; }
+
+ #endregion
+
+ #region Operations
+
+ public ReactiveCommand SaveConfigurationCommand { get; }
+ public ReactiveCommand ResetConfigurationCommand { get; }
+
+ #endregion
+
+ #region Device basic information
+
+ [Reactive] public int DeviceID { get; set; }
+ [Reactive] public string DeviceName { get; set; }
+ [Reactive] public HarpVersion HardwareVersion { get; set; }
+ [Reactive] public HarpVersion FirmwareVersion { get; set; }
+ [Reactive] public int SerialNumber { get; set; }
+
+ #endregion
+
+ #region Registers
+
+ [Reactive] public EnableFlag AcquisitionState { get; set; }
+ [Reactive] public LoadCellDataPayload LoadCellData { get; set; }
+ [Reactive] public DigitalInputs DigitalInputState { get; set; }
+ [Reactive] public SyncOutputs SyncOutputState { get; set; }
+ [Reactive] public TriggerConfig DI0Trigger { get; set; }
+ [Reactive] public SyncConfig DO0Sync { get; set; }
+ [Reactive] public byte DO0PulseWidth { get; set; }
+ [Reactive] public DigitalOutputs DigitalOutputSet { get; set; }
+ [Reactive] public DigitalOutputs DigitalOutputClear { get; set; }
+ [Reactive] public DigitalOutputs DigitalOutputToggle { get; set; }
+ [Reactive] public DigitalOutputs DigitalOutputState { get; set; }
+ [Reactive] public short OffsetLoadCell0 { get; set; }
+ [Reactive] public short OffsetLoadCell1 { get; set; }
+ [Reactive] public short OffsetLoadCell2 { get; set; }
+ [Reactive] public short OffsetLoadCell3 { get; set; }
+ [Reactive] public short OffsetLoadCell4 { get; set; }
+ [Reactive] public short OffsetLoadCell5 { get; set; }
+ [Reactive] public short OffsetLoadCell6 { get; set; }
+ [Reactive] public short OffsetLoadCell7 { get; set; }
+ [Reactive] public LoadCellChannel DO1TargetLoadCell { get; set; }
+ [Reactive] public LoadCellChannel DO2TargetLoadCell { get; set; }
+ [Reactive] public LoadCellChannel DO3TargetLoadCell { get; set; }
+ [Reactive] public LoadCellChannel DO4TargetLoadCell { get; set; }
+ [Reactive] public LoadCellChannel DO5TargetLoadCell { get; set; }
+ [Reactive] public LoadCellChannel DO6TargetLoadCell { get; set; }
+ [Reactive] public LoadCellChannel DO7TargetLoadCell { get; set; }
+ [Reactive] public LoadCellChannel DO8TargetLoadCell { get; set; }
+ [Reactive] public short DO1Threshold { get; set; }
+ [Reactive] public short DO2Threshold { get; set; }
+ [Reactive] public short DO3Threshold { get; set; }
+ [Reactive] public short DO4Threshold { get; set; }
+ [Reactive] public short DO5Threshold { get; set; }
+ [Reactive] public short DO6Threshold { get; set; }
+ [Reactive] public short DO7Threshold { get; set; }
+ [Reactive] public short DO8Threshold { get; set; }
+ [Reactive] public ushort DO1TimeAboveThreshold { get; set; }
+ [Reactive] public ushort DO2TimeAboveThreshold { get; set; }
+ [Reactive] public ushort DO3TimeAboveThreshold { get; set; }
+ [Reactive] public ushort DO4TimeAboveThreshold { get; set; }
+ [Reactive] public ushort DO5TimeAboveThreshold { get; set; }
+ [Reactive] public ushort DO6TimeAboveThreshold { get; set; }
+ [Reactive] public ushort DO7TimeAboveThreshold { get; set; }
+ [Reactive] public ushort DO8TimeAboveThreshold { get; set; }
+ [Reactive] public ushort DO1TimeBelowThreshold { get; set; }
+ [Reactive] public ushort DO2TimeBelowThreshold { get; set; }
+ [Reactive] public ushort DO3TimeBelowThreshold { get; set; }
+ [Reactive] public ushort DO4TimeBelowThreshold { get; set; }
+ [Reactive] public ushort DO5TimeBelowThreshold { get; set; }
+ [Reactive] public ushort DO6TimeBelowThreshold { get; set; }
+ [Reactive] public ushort DO7TimeBelowThreshold { get; set; }
+ [Reactive] public ushort DO8TimeBelowThreshold { get; set; }
+ [Reactive] public LoadCellEvents EnableEvents { get; set; }
+
+ #endregion
+
+ #region Array Collections
+
+
+ #endregion
+
+ #region Events Flags
+
+ public bool IsLoadCellDataEnabled
+ {
+ get
+ {
+ return EnableEvents.HasFlag(LoadCellEvents.LoadCellData);
+ }
+ set
+ {
+ if (value)
+ {
+ EnableEvents |= LoadCellEvents.LoadCellData;
+ }
+ else
+ {
+ EnableEvents &= ~LoadCellEvents.LoadCellData;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsLoadCellDataEnabled));
+ this.RaisePropertyChanged(nameof(EnableEvents));
+ }
+ }
+
+ public bool IsDigitalInputEnabled
+ {
+ get
+ {
+ return EnableEvents.HasFlag(LoadCellEvents.DigitalInput);
+ }
+ set
+ {
+ if (value)
+ {
+ EnableEvents |= LoadCellEvents.DigitalInput;
+ }
+ else
+ {
+ EnableEvents &= ~LoadCellEvents.DigitalInput;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDigitalInputEnabled));
+ this.RaisePropertyChanged(nameof(EnableEvents));
+ }
+ }
+
+ public bool IsSyncOutputEnabled
+ {
+ get
+ {
+ return EnableEvents.HasFlag(LoadCellEvents.SyncOutput);
+ }
+ set
+ {
+ if (value)
+ {
+ EnableEvents |= LoadCellEvents.SyncOutput;
+ }
+ else
+ {
+ EnableEvents &= ~LoadCellEvents.SyncOutput;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsSyncOutputEnabled));
+ this.RaisePropertyChanged(nameof(EnableEvents));
+ }
+ }
+
+ public bool IsThresholdsEnabled
+ {
+ get
+ {
+ return EnableEvents.HasFlag(LoadCellEvents.Thresholds);
+ }
+ set
+ {
+ if (value)
+ {
+ EnableEvents |= LoadCellEvents.Thresholds;
+ }
+ else
+ {
+ EnableEvents &= ~LoadCellEvents.Thresholds;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsThresholdsEnabled));
+ this.RaisePropertyChanged(nameof(EnableEvents));
+ }
+ }
+
+ #endregion
+
+ #region DigitalInputs_DigitalInputState Flags
+
+ public bool IsDI0Enabled_DigitalInputState
+ {
+ get
+ {
+ return DigitalInputState.HasFlag(DigitalInputs.DI0);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalInputState |= DigitalInputs.DI0;
+ }
+ else
+ {
+ DigitalInputState &= ~DigitalInputs.DI0;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDI0Enabled_DigitalInputState));
+ this.RaisePropertyChanged(nameof(DigitalInputState));
+ }
+ }
+
+ #endregion
+
+ #region SyncOutputs_SyncOutputState Flags
+
+ public bool IsDO0Enabled_SyncOutputState
+ {
+ get
+ {
+ return SyncOutputState.HasFlag(SyncOutputs.DO0);
+ }
+ set
+ {
+ if (value)
+ {
+ SyncOutputState |= SyncOutputs.DO0;
+ }
+ else
+ {
+ SyncOutputState &= ~SyncOutputs.DO0;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO0Enabled_SyncOutputState));
+ this.RaisePropertyChanged(nameof(SyncOutputState));
+ }
+ }
+
+ #endregion
+
+ #region DigitalOutputs_DigitalOutputSet Flags
+
+ public bool IsDO1Enabled_DigitalOutputSet
+ {
+ get
+ {
+ return DigitalOutputSet.HasFlag(DigitalOutputs.DO1);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputSet |= DigitalOutputs.DO1;
+ }
+ else
+ {
+ DigitalOutputSet &= ~DigitalOutputs.DO1;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO1Enabled_DigitalOutputSet));
+ this.RaisePropertyChanged(nameof(DigitalOutputSet));
+ }
+ }
+
+ public bool IsDO2Enabled_DigitalOutputSet
+ {
+ get
+ {
+ return DigitalOutputSet.HasFlag(DigitalOutputs.DO2);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputSet |= DigitalOutputs.DO2;
+ }
+ else
+ {
+ DigitalOutputSet &= ~DigitalOutputs.DO2;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO2Enabled_DigitalOutputSet));
+ this.RaisePropertyChanged(nameof(DigitalOutputSet));
+ }
+ }
+
+ public bool IsDO3Enabled_DigitalOutputSet
+ {
+ get
+ {
+ return DigitalOutputSet.HasFlag(DigitalOutputs.DO3);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputSet |= DigitalOutputs.DO3;
+ }
+ else
+ {
+ DigitalOutputSet &= ~DigitalOutputs.DO3;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO3Enabled_DigitalOutputSet));
+ this.RaisePropertyChanged(nameof(DigitalOutputSet));
+ }
+ }
+
+ public bool IsDO4Enabled_DigitalOutputSet
+ {
+ get
+ {
+ return DigitalOutputSet.HasFlag(DigitalOutputs.DO4);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputSet |= DigitalOutputs.DO4;
+ }
+ else
+ {
+ DigitalOutputSet &= ~DigitalOutputs.DO4;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO4Enabled_DigitalOutputSet));
+ this.RaisePropertyChanged(nameof(DigitalOutputSet));
+ }
+ }
+
+ public bool IsDO5Enabled_DigitalOutputSet
+ {
+ get
+ {
+ return DigitalOutputSet.HasFlag(DigitalOutputs.DO5);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputSet |= DigitalOutputs.DO5;
+ }
+ else
+ {
+ DigitalOutputSet &= ~DigitalOutputs.DO5;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO5Enabled_DigitalOutputSet));
+ this.RaisePropertyChanged(nameof(DigitalOutputSet));
+ }
+ }
+
+ public bool IsDO6Enabled_DigitalOutputSet
+ {
+ get
+ {
+ return DigitalOutputSet.HasFlag(DigitalOutputs.DO6);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputSet |= DigitalOutputs.DO6;
+ }
+ else
+ {
+ DigitalOutputSet &= ~DigitalOutputs.DO6;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO6Enabled_DigitalOutputSet));
+ this.RaisePropertyChanged(nameof(DigitalOutputSet));
+ }
+ }
+
+ public bool IsDO7Enabled_DigitalOutputSet
+ {
+ get
+ {
+ return DigitalOutputSet.HasFlag(DigitalOutputs.DO7);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputSet |= DigitalOutputs.DO7;
+ }
+ else
+ {
+ DigitalOutputSet &= ~DigitalOutputs.DO7;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO7Enabled_DigitalOutputSet));
+ this.RaisePropertyChanged(nameof(DigitalOutputSet));
+ }
+ }
+
+ public bool IsDO8Enabled_DigitalOutputSet
+ {
+ get
+ {
+ return DigitalOutputSet.HasFlag(DigitalOutputs.DO8);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputSet |= DigitalOutputs.DO8;
+ }
+ else
+ {
+ DigitalOutputSet &= ~DigitalOutputs.DO8;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO8Enabled_DigitalOutputSet));
+ this.RaisePropertyChanged(nameof(DigitalOutputSet));
+ }
+ }
+
+ #endregion
+
+ #region DigitalOutputs_DigitalOutputClear Flags
+
+ public bool IsDO1Enabled_DigitalOutputClear
+ {
+ get
+ {
+ return DigitalOutputClear.HasFlag(DigitalOutputs.DO1);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputClear |= DigitalOutputs.DO1;
+ }
+ else
+ {
+ DigitalOutputClear &= ~DigitalOutputs.DO1;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO1Enabled_DigitalOutputClear));
+ this.RaisePropertyChanged(nameof(DigitalOutputClear));
+ }
+ }
+
+ public bool IsDO2Enabled_DigitalOutputClear
+ {
+ get
+ {
+ return DigitalOutputClear.HasFlag(DigitalOutputs.DO2);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputClear |= DigitalOutputs.DO2;
+ }
+ else
+ {
+ DigitalOutputClear &= ~DigitalOutputs.DO2;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO2Enabled_DigitalOutputClear));
+ this.RaisePropertyChanged(nameof(DigitalOutputClear));
+ }
+ }
+
+ public bool IsDO3Enabled_DigitalOutputClear
+ {
+ get
+ {
+ return DigitalOutputClear.HasFlag(DigitalOutputs.DO3);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputClear |= DigitalOutputs.DO3;
+ }
+ else
+ {
+ DigitalOutputClear &= ~DigitalOutputs.DO3;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO3Enabled_DigitalOutputClear));
+ this.RaisePropertyChanged(nameof(DigitalOutputClear));
+ }
+ }
+
+ public bool IsDO4Enabled_DigitalOutputClear
+ {
+ get
+ {
+ return DigitalOutputClear.HasFlag(DigitalOutputs.DO4);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputClear |= DigitalOutputs.DO4;
+ }
+ else
+ {
+ DigitalOutputClear &= ~DigitalOutputs.DO4;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO4Enabled_DigitalOutputClear));
+ this.RaisePropertyChanged(nameof(DigitalOutputClear));
+ }
+ }
+
+ public bool IsDO5Enabled_DigitalOutputClear
+ {
+ get
+ {
+ return DigitalOutputClear.HasFlag(DigitalOutputs.DO5);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputClear |= DigitalOutputs.DO5;
+ }
+ else
+ {
+ DigitalOutputClear &= ~DigitalOutputs.DO5;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO5Enabled_DigitalOutputClear));
+ this.RaisePropertyChanged(nameof(DigitalOutputClear));
+ }
+ }
+
+ public bool IsDO6Enabled_DigitalOutputClear
+ {
+ get
+ {
+ return DigitalOutputClear.HasFlag(DigitalOutputs.DO6);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputClear |= DigitalOutputs.DO6;
+ }
+ else
+ {
+ DigitalOutputClear &= ~DigitalOutputs.DO6;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO6Enabled_DigitalOutputClear));
+ this.RaisePropertyChanged(nameof(DigitalOutputClear));
+ }
+ }
+
+ public bool IsDO7Enabled_DigitalOutputClear
+ {
+ get
+ {
+ return DigitalOutputClear.HasFlag(DigitalOutputs.DO7);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputClear |= DigitalOutputs.DO7;
+ }
+ else
+ {
+ DigitalOutputClear &= ~DigitalOutputs.DO7;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO7Enabled_DigitalOutputClear));
+ this.RaisePropertyChanged(nameof(DigitalOutputClear));
+ }
+ }
+
+ public bool IsDO8Enabled_DigitalOutputClear
+ {
+ get
+ {
+ return DigitalOutputClear.HasFlag(DigitalOutputs.DO8);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputClear |= DigitalOutputs.DO8;
+ }
+ else
+ {
+ DigitalOutputClear &= ~DigitalOutputs.DO8;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO8Enabled_DigitalOutputClear));
+ this.RaisePropertyChanged(nameof(DigitalOutputClear));
+ }
+ }
+
+ #endregion
+
+ #region DigitalOutputs_DigitalOutputToggle Flags
+
+ public bool IsDO1Enabled_DigitalOutputToggle
+ {
+ get
+ {
+ return DigitalOutputToggle.HasFlag(DigitalOutputs.DO1);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputToggle |= DigitalOutputs.DO1;
+ }
+ else
+ {
+ DigitalOutputToggle &= ~DigitalOutputs.DO1;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO1Enabled_DigitalOutputToggle));
+ this.RaisePropertyChanged(nameof(DigitalOutputToggle));
+ }
+ }
+
+ public bool IsDO2Enabled_DigitalOutputToggle
+ {
+ get
+ {
+ return DigitalOutputToggle.HasFlag(DigitalOutputs.DO2);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputToggle |= DigitalOutputs.DO2;
+ }
+ else
+ {
+ DigitalOutputToggle &= ~DigitalOutputs.DO2;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO2Enabled_DigitalOutputToggle));
+ this.RaisePropertyChanged(nameof(DigitalOutputToggle));
+ }
+ }
+
+ public bool IsDO3Enabled_DigitalOutputToggle
+ {
+ get
+ {
+ return DigitalOutputToggle.HasFlag(DigitalOutputs.DO3);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputToggle |= DigitalOutputs.DO3;
+ }
+ else
+ {
+ DigitalOutputToggle &= ~DigitalOutputs.DO3;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO3Enabled_DigitalOutputToggle));
+ this.RaisePropertyChanged(nameof(DigitalOutputToggle));
+ }
+ }
+
+ public bool IsDO4Enabled_DigitalOutputToggle
+ {
+ get
+ {
+ return DigitalOutputToggle.HasFlag(DigitalOutputs.DO4);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputToggle |= DigitalOutputs.DO4;
+ }
+ else
+ {
+ DigitalOutputToggle &= ~DigitalOutputs.DO4;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO4Enabled_DigitalOutputToggle));
+ this.RaisePropertyChanged(nameof(DigitalOutputToggle));
+ }
+ }
+
+ public bool IsDO5Enabled_DigitalOutputToggle
+ {
+ get
+ {
+ return DigitalOutputToggle.HasFlag(DigitalOutputs.DO5);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputToggle |= DigitalOutputs.DO5;
+ }
+ else
+ {
+ DigitalOutputToggle &= ~DigitalOutputs.DO5;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO5Enabled_DigitalOutputToggle));
+ this.RaisePropertyChanged(nameof(DigitalOutputToggle));
+ }
+ }
+
+ public bool IsDO6Enabled_DigitalOutputToggle
+ {
+ get
+ {
+ return DigitalOutputToggle.HasFlag(DigitalOutputs.DO6);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputToggle |= DigitalOutputs.DO6;
+ }
+ else
+ {
+ DigitalOutputToggle &= ~DigitalOutputs.DO6;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO6Enabled_DigitalOutputToggle));
+ this.RaisePropertyChanged(nameof(DigitalOutputToggle));
+ }
+ }
+
+ public bool IsDO7Enabled_DigitalOutputToggle
+ {
+ get
+ {
+ return DigitalOutputToggle.HasFlag(DigitalOutputs.DO7);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputToggle |= DigitalOutputs.DO7;
+ }
+ else
+ {
+ DigitalOutputToggle &= ~DigitalOutputs.DO7;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO7Enabled_DigitalOutputToggle));
+ this.RaisePropertyChanged(nameof(DigitalOutputToggle));
+ }
+ }
+
+ public bool IsDO8Enabled_DigitalOutputToggle
+ {
+ get
+ {
+ return DigitalOutputToggle.HasFlag(DigitalOutputs.DO8);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputToggle |= DigitalOutputs.DO8;
+ }
+ else
+ {
+ DigitalOutputToggle &= ~DigitalOutputs.DO8;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO8Enabled_DigitalOutputToggle));
+ this.RaisePropertyChanged(nameof(DigitalOutputToggle));
+ }
+ }
+
+ #endregion
+
+ #region DigitalOutputs_DigitalOutputState Flags
+
+ public bool IsDO1Enabled_DigitalOutputState
+ {
+ get
+ {
+ return DigitalOutputState.HasFlag(DigitalOutputs.DO1);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputState |= DigitalOutputs.DO1;
+ }
+ else
+ {
+ DigitalOutputState &= ~DigitalOutputs.DO1;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO1Enabled_DigitalOutputState));
+ this.RaisePropertyChanged(nameof(DigitalOutputState));
+ }
+ }
+
+ public bool IsDO2Enabled_DigitalOutputState
+ {
+ get
+ {
+ return DigitalOutputState.HasFlag(DigitalOutputs.DO2);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputState |= DigitalOutputs.DO2;
+ }
+ else
+ {
+ DigitalOutputState &= ~DigitalOutputs.DO2;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO2Enabled_DigitalOutputState));
+ this.RaisePropertyChanged(nameof(DigitalOutputState));
+ }
+ }
+
+ public bool IsDO3Enabled_DigitalOutputState
+ {
+ get
+ {
+ return DigitalOutputState.HasFlag(DigitalOutputs.DO3);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputState |= DigitalOutputs.DO3;
+ }
+ else
+ {
+ DigitalOutputState &= ~DigitalOutputs.DO3;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO3Enabled_DigitalOutputState));
+ this.RaisePropertyChanged(nameof(DigitalOutputState));
+ }
+ }
+
+ public bool IsDO4Enabled_DigitalOutputState
+ {
+ get
+ {
+ return DigitalOutputState.HasFlag(DigitalOutputs.DO4);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputState |= DigitalOutputs.DO4;
+ }
+ else
+ {
+ DigitalOutputState &= ~DigitalOutputs.DO4;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO4Enabled_DigitalOutputState));
+ this.RaisePropertyChanged(nameof(DigitalOutputState));
+ }
+ }
+
+ public bool IsDO5Enabled_DigitalOutputState
+ {
+ get
+ {
+ return DigitalOutputState.HasFlag(DigitalOutputs.DO5);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputState |= DigitalOutputs.DO5;
+ }
+ else
+ {
+ DigitalOutputState &= ~DigitalOutputs.DO5;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO5Enabled_DigitalOutputState));
+ this.RaisePropertyChanged(nameof(DigitalOutputState));
+ }
+ }
+
+ public bool IsDO6Enabled_DigitalOutputState
+ {
+ get
+ {
+ return DigitalOutputState.HasFlag(DigitalOutputs.DO6);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputState |= DigitalOutputs.DO6;
+ }
+ else
+ {
+ DigitalOutputState &= ~DigitalOutputs.DO6;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO6Enabled_DigitalOutputState));
+ this.RaisePropertyChanged(nameof(DigitalOutputState));
+ }
+ }
+
+ public bool IsDO7Enabled_DigitalOutputState
+ {
+ get
+ {
+ return DigitalOutputState.HasFlag(DigitalOutputs.DO7);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputState |= DigitalOutputs.DO7;
+ }
+ else
+ {
+ DigitalOutputState &= ~DigitalOutputs.DO7;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO7Enabled_DigitalOutputState));
+ this.RaisePropertyChanged(nameof(DigitalOutputState));
+ }
+ }
+
+ public bool IsDO8Enabled_DigitalOutputState
+ {
+ get
+ {
+ return DigitalOutputState.HasFlag(DigitalOutputs.DO8);
+ }
+ set
+ {
+ if (value)
+ {
+ DigitalOutputState |= DigitalOutputs.DO8;
+ }
+ else
+ {
+ DigitalOutputState &= ~DigitalOutputs.DO8;
+ }
+
+ // Notify the UI about the change
+ this.RaisePropertyChanged(nameof(IsDO8Enabled_DigitalOutputState));
+ this.RaisePropertyChanged(nameof(DigitalOutputState));
+ }
+ }
+
+ #endregion
+
+ #region Application State
+
+ [ObservableAsProperty] public bool IsLoadingPorts { get; }
+ [ObservableAsProperty] public bool IsConnecting { get; }
+ [ObservableAsProperty] public bool IsResetting { get; }
+ [ObservableAsProperty] public bool IsSaving { get; }
+
+ [Reactive] public bool ShowWriteMessages { get; set; }
+ [Reactive] public ObservableCollection HarpEvents { get; set; } = new ObservableCollection();
+ [Reactive] public ObservableCollection SentMessages { get; set; } = new ObservableCollection();
+
+ public ReactiveCommand ShowAboutCommand { get; private set; }
+ public ReactiveCommand ClearMessagesCommand { get; private set; }
+ public ReactiveCommand ShowMessagesCommand { get; private set; }
+
+
+ #endregion
+
+ #region Chart state
+
+ // Public chart properties
+ [Reactive] public bool Show0 { get; set; } = true;
+ [Reactive] public bool Show1 { get; set; } = true;
+ [Reactive] public bool Show2 { get; set; } = true;
+ [Reactive] public bool Show3 { get; set; } = true;
+ [Reactive] public bool Show4 { get; set; } = true;
+ [Reactive] public bool Show5 { get; set; } = true;
+ [Reactive] public bool Show6 { get; set; } = true;
+ [Reactive] public bool Show7 { get; set; } = true;
+
+ public ObservableCollection Series { get; set; }
+ public Axis[] XAxes { get; set; }
+ public object SyncChart { get; } = new object();
+ public DateTimeAxis _customAxis;
+
+ // Private chart data fields
+ private readonly List _values0 = new List(250);
+ private readonly List _values1 = new List(250);
+ private readonly List _values2 = new List(250);
+ private readonly List _values3 = new List(250);
+ private readonly List _values4 = new List(250);
+ private readonly List _values5 = new List(250);
+ private readonly List _values6 = new List(250);
+ private readonly List _values7 = new List(250);
+
+ #endregion
+
+
+ private Harp.LoadCells.AsyncDevice? _device;
+ private IObservable _deviceEventsObservable;
+ private IDisposable? _deviceEventsSubscription;
+
+ public LoadCellsViewModel()
+ {
+ var assembly = typeof(LoadCellsViewModel).Assembly;
+ var informationVersion = assembly.GetName().Version;
+ if (informationVersion != null)
+ AppVersion = $"v{informationVersion.Major}.{informationVersion.Minor}.{informationVersion.Build}";
+
+ Ports = new ObservableCollection();
+
+ ClearMessagesCommand = ReactiveCommand.Create(() => { SentMessages.Clear(); });
+ ShowMessagesCommand = ReactiveCommand.Create(() => { ShowWriteMessages = !ShowWriteMessages; });
+
+
+ LoadDeviceInformation = ReactiveCommand.CreateFromObservable(LoadUsbInformation);
+ LoadDeviceInformation.IsExecuting.ToPropertyEx(this, x => x.IsLoadingPorts);
+ LoadDeviceInformation.ThrownExceptions.Subscribe(ex =>
+ Console.WriteLine($"Error loading device information with exception: {ex.Message}"));
+ //Log.Error(ex, "Error loading device information with exception: {Exception}", ex));
+
+ // can connect if there is a selection and also if the new selection is different than the old one
+ var canConnect = this.WhenAnyValue(x => x.SelectedPort)
+ .Select(selectedPort => !string.IsNullOrEmpty(selectedPort));
+
+ ShowAboutCommand = ReactiveCommand.CreateFromTask(async () =>
+ await new About() { DataContext = new AboutViewModel() }.ShowDialog(
+ (Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow));
+
+ ConnectAndGetBaseInfoCommand = ReactiveCommand.CreateFromTask(ConnectAndGetBaseInfo, canConnect);
+ ConnectAndGetBaseInfoCommand.IsExecuting.ToPropertyEx(this, x => x.IsConnecting);
+ ConnectAndGetBaseInfoCommand.ThrownExceptions.Subscribe(ex =>
+ //Log.Error(ex, "Error connecting to device with error: {Exception}", ex));
+ Console.WriteLine($"Error connecting to device with error: {ex}"));
+
+ var canChangeConfig = this.WhenAnyValue(x => x.Connected).Select(connected => connected);
+ // Handle Save and Reset
+ SaveConfigurationCommand =
+ ReactiveCommand.CreateFromObservable(SaveConfiguration, canChangeConfig);
+ SaveConfigurationCommand.IsExecuting.ToPropertyEx(this, x => x.IsSaving);
+ SaveConfigurationCommand.ThrownExceptions.Subscribe(ex =>
+ //Log.Error(ex, "Error saving configuration with error: {Exception}", ex));
+ Console.WriteLine($"Error saving configuration with error: {ex}"));
+
+ ResetConfigurationCommand = ReactiveCommand.CreateFromObservable(ResetConfiguration, canChangeConfig);
+ ResetConfigurationCommand.IsExecuting.ToPropertyEx(this, x => x.IsResetting);
+ ResetConfigurationCommand.ThrownExceptions.Subscribe(ex =>
+ //Log.Error(ex, "Error resetting device configuration with error: {Exception}", ex));
+ Console.WriteLine($"Error resetting device configuration with error: {ex}"));
+
+ this.WhenAnyValue(x => x.Connected)
+ .Subscribe(x => { ConnectButtonText = x ? "Disconnect" : "Connect"; });
+
+ this.WhenAnyValue(x => x.EnableEvents)
+ .Subscribe(x =>
+ {
+ IsLoadCellDataEnabled = x.HasFlag(LoadCellEvents.LoadCellData);
+ IsDigitalInputEnabled = x.HasFlag(LoadCellEvents.DigitalInput);
+ IsSyncOutputEnabled = x.HasFlag(LoadCellEvents.SyncOutput);
+ IsThresholdsEnabled = x.HasFlag(LoadCellEvents.Thresholds);
+ });
+
+
+ // handle the events from the device
+ // When Connected changes subscribe/unsubscribe the device events.
+ this.WhenAnyValue(x => x.Connected)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(isConnected =>
+ {
+ if (isConnected && _deviceEventsObservable != null)
+ {
+ // Subscribe on the UI thread so that the HarpEvents collection can be updated safely.
+ SubscribeToEvents();
+ }
+ else
+ {
+ // Dispose subscription and clear messages.
+ _deviceEventsSubscription?.Dispose();
+ _deviceEventsSubscription = null;
+ }
+ });
+
+ this.WhenAnyValue(x => x.DigitalInputState)
+ .Subscribe(x =>
+ {
+ IsDI0Enabled_DigitalInputState = x.HasFlag(DigitalInputs.DI0);
+ });
+
+ this.WhenAnyValue(x => x.SyncOutputState)
+ .Subscribe(x =>
+ {
+ IsDO0Enabled_SyncOutputState = x.HasFlag(SyncOutputs.DO0);
+ });
+
+ this.WhenAnyValue(x => x.DigitalOutputSet)
+ .Subscribe(x =>
+ {
+ IsDO1Enabled_DigitalOutputSet = x.HasFlag(DigitalOutputs.DO1);
+ IsDO2Enabled_DigitalOutputSet = x.HasFlag(DigitalOutputs.DO2);
+ IsDO3Enabled_DigitalOutputSet = x.HasFlag(DigitalOutputs.DO3);
+ IsDO4Enabled_DigitalOutputSet = x.HasFlag(DigitalOutputs.DO4);
+ IsDO5Enabled_DigitalOutputSet = x.HasFlag(DigitalOutputs.DO5);
+ IsDO6Enabled_DigitalOutputSet = x.HasFlag(DigitalOutputs.DO6);
+ IsDO7Enabled_DigitalOutputSet = x.HasFlag(DigitalOutputs.DO7);
+ IsDO8Enabled_DigitalOutputSet = x.HasFlag(DigitalOutputs.DO8);
+ });
+
+ this.WhenAnyValue(x => x.DigitalOutputClear)
+ .Subscribe(x =>
+ {
+ IsDO1Enabled_DigitalOutputClear = x.HasFlag(DigitalOutputs.DO1);
+ IsDO2Enabled_DigitalOutputClear = x.HasFlag(DigitalOutputs.DO2);
+ IsDO3Enabled_DigitalOutputClear = x.HasFlag(DigitalOutputs.DO3);
+ IsDO4Enabled_DigitalOutputClear = x.HasFlag(DigitalOutputs.DO4);
+ IsDO5Enabled_DigitalOutputClear = x.HasFlag(DigitalOutputs.DO5);
+ IsDO6Enabled_DigitalOutputClear = x.HasFlag(DigitalOutputs.DO6);
+ IsDO7Enabled_DigitalOutputClear = x.HasFlag(DigitalOutputs.DO7);
+ IsDO8Enabled_DigitalOutputClear = x.HasFlag(DigitalOutputs.DO8);
+ });
+
+ this.WhenAnyValue(x => x.DigitalOutputToggle)
+ .Subscribe(x =>
+ {
+ IsDO1Enabled_DigitalOutputToggle = x.HasFlag(DigitalOutputs.DO1);
+ IsDO2Enabled_DigitalOutputToggle = x.HasFlag(DigitalOutputs.DO2);
+ IsDO3Enabled_DigitalOutputToggle = x.HasFlag(DigitalOutputs.DO3);
+ IsDO4Enabled_DigitalOutputToggle = x.HasFlag(DigitalOutputs.DO4);
+ IsDO5Enabled_DigitalOutputToggle = x.HasFlag(DigitalOutputs.DO5);
+ IsDO6Enabled_DigitalOutputToggle = x.HasFlag(DigitalOutputs.DO6);
+ IsDO7Enabled_DigitalOutputToggle = x.HasFlag(DigitalOutputs.DO7);
+ IsDO8Enabled_DigitalOutputToggle = x.HasFlag(DigitalOutputs.DO8);
+ });
+
+ this.WhenAnyValue(x => x.DigitalOutputState)
+ .Subscribe(x =>
+ {
+ IsDO1Enabled_DigitalOutputState = x.HasFlag(DigitalOutputs.DO1);
+ IsDO2Enabled_DigitalOutputState = x.HasFlag(DigitalOutputs.DO2);
+ IsDO3Enabled_DigitalOutputState = x.HasFlag(DigitalOutputs.DO3);
+ IsDO4Enabled_DigitalOutputState = x.HasFlag(DigitalOutputs.DO4);
+ IsDO5Enabled_DigitalOutputState = x.HasFlag(DigitalOutputs.DO5);
+ IsDO6Enabled_DigitalOutputState = x.HasFlag(DigitalOutputs.DO6);
+ IsDO7Enabled_DigitalOutputState = x.HasFlag(DigitalOutputs.DO7);
+ IsDO8Enabled_DigitalOutputState = x.HasFlag(DigitalOutputs.DO8);
+ });
+
+ // force initial population of currently connected ports
+ LoadUsbInformation();
+
+ CreateSeries();
+ Console.WriteLine("Connected to device");
+
+ this.WhenAnyValue(x => x.Show0).Subscribe(x => Series[0].IsVisible = x);
+ this.WhenAnyValue(x => x.Show1).Subscribe(x => Series[1].IsVisible = x);
+ this.WhenAnyValue(x => x.Show2).Subscribe(x => Series[2].IsVisible = x);
+ this.WhenAnyValue(x => x.Show3).Subscribe(x => Series[3].IsVisible = x);
+ this.WhenAnyValue(x => x.Show4).Subscribe(x => Series[4].IsVisible = x);
+ this.WhenAnyValue(x => x.Show5).Subscribe(x => Series[5].IsVisible = x);
+ this.WhenAnyValue(x => x.Show6).Subscribe(x => Series[6].IsVisible = x);
+ this.WhenAnyValue(x => x.Show7).Subscribe(x => Series[7].IsVisible = x);
+
+
+ }
+
+ private IObservable LoadUsbInformation()
+ {
+ return Observable.Start(() =>
+ {
+ var devices = SerialPort.GetPortNames();
+
+ if (OperatingSystem.IsMacOS())
+ // except with Bluetooth in the name
+ Ports = new ObservableCollection(devices.Where(d => d.Contains("cu.")).Except(devices.Where(d => d.Contains("Bluetooth"))));
+ else
+ Ports = new ObservableCollection(devices);
+
+ Console.WriteLine("Loaded USB information");
+ //Log.Information("Loaded USB information");
+ });
+ }
+
+ private async Task ConnectAndGetBaseInfo()
+ {
+ if (string.IsNullOrEmpty(SelectedPort))
+ throw new Exception("invalid parameter");
+
+ if (Connected)
+ {
+ _device?.Dispose();
+ _device = null;
+ Connected = false;
+ SentMessages.Clear();
+ return;
+ }
+
+ try
+ {
+ _device = await Harp.LoadCells.Device.CreateAsync(SelectedPort);
+ }
+ catch (OperationCanceledException ex)
+ {
+ Console.WriteLine($"Error connecting to device with error: {ex}");
+ //Log.Error(ex, "Error connecting to device with error: {Exception}", ex);
+ var messageBoxStandardWindow = MessageBoxManager
+ .GetMessageBoxStandard("Unexpected device found",
+ "Timeout when trying to connect to a device. Most likely not an Harp device.",
+ icon: Icon.Error);
+ await messageBoxStandardWindow.ShowAsync();
+ _device?.Dispose();
+ _device = null;
+ return;
+
+ }
+ catch (HarpException ex)
+ {
+ Console.WriteLine($"Error connecting to device with error: {ex}");
+ //Log.Error(ex, "Error connecting to device with error: {Exception}", ex);
+
+ var messageBoxStandardWindow = MessageBoxManager
+ .GetMessageBoxStandard("Unexpected device found",
+ ex.Message,
+ icon: Icon.Error);
+ await messageBoxStandardWindow.ShowAsync();
+
+ _device?.Dispose();
+ _device = null;
+ return;
+ }
+ catch (UnauthorizedAccessException ex)
+ {
+ Console.WriteLine($"COM port still in use and most likely not the expected Harp device");
+ var messageBoxStandardWindow = MessageBoxManager
+ .GetMessageBoxStandard("Unexpected device found",
+ $"COM port still in use and most likely not the expected Harp device.{Environment.NewLine}Specific error: {ex.Message}",
+ icon: Icon.Error);
+ await messageBoxStandardWindow.ShowAsync();
+
+ _device?.Dispose();
+ _device = null;
+ return;
+ }
+
+ // Clear the sent messages list
+ SentMessages.Clear();
+
+ //Log.Information("Attempting connection to port \'{SelectedPort}\'", SelectedPort);
+ Console.WriteLine($"Attempting connection to port \'{SelectedPort}\'");
+
+ DeviceID = await _device.ReadWhoAmIAsync();
+ DeviceName = await _device.ReadDeviceNameAsync();
+ HardwareVersion = await _device.ReadHardwareVersionAsync();
+ FirmwareVersion = await _device.ReadFirmwareVersionAsync();
+ try
+ {
+ // some devices may not have a serial number
+ SerialNumber = await _device.ReadSerialNumberAsync();
+ }
+ catch (HarpException)
+ {
+ // Device does not have a serial number, simply continue by ignoring the exception
+ }
+
+ AcquisitionState = await _device.ReadAcquisitionStateAsync();
+ LoadCellData = await _device.ReadLoadCellDataAsync();
+ DigitalInputState = await _device.ReadDigitalInputStateAsync();
+ SyncOutputState = await _device.ReadSyncOutputStateAsync();
+ DI0Trigger = await _device.ReadDI0TriggerAsync();
+ DO0Sync = await _device.ReadDO0SyncAsync();
+ DO0PulseWidth = await _device.ReadDO0PulseWidthAsync();
+ DigitalOutputSet = await _device.ReadDigitalOutputSetAsync();
+ DigitalOutputClear = await _device.ReadDigitalOutputClearAsync();
+ DigitalOutputToggle = await _device.ReadDigitalOutputToggleAsync();
+ DigitalOutputState = await _device.ReadDigitalOutputStateAsync();
+ OffsetLoadCell0 = await _device.ReadOffsetLoadCell0Async();
+ OffsetLoadCell1 = await _device.ReadOffsetLoadCell1Async();
+ OffsetLoadCell2 = await _device.ReadOffsetLoadCell2Async();
+ OffsetLoadCell3 = await _device.ReadOffsetLoadCell3Async();
+ OffsetLoadCell4 = await _device.ReadOffsetLoadCell4Async();
+ OffsetLoadCell5 = await _device.ReadOffsetLoadCell5Async();
+ OffsetLoadCell6 = await _device.ReadOffsetLoadCell6Async();
+ OffsetLoadCell7 = await _device.ReadOffsetLoadCell7Async();
+ DO1TargetLoadCell = await _device.ReadDO1TargetLoadCellAsync();
+ DO2TargetLoadCell = await _device.ReadDO2TargetLoadCellAsync();
+ DO3TargetLoadCell = await _device.ReadDO3TargetLoadCellAsync();
+ DO4TargetLoadCell = await _device.ReadDO4TargetLoadCellAsync();
+ DO5TargetLoadCell = await _device.ReadDO5TargetLoadCellAsync();
+ DO6TargetLoadCell = await _device.ReadDO6TargetLoadCellAsync();
+ DO7TargetLoadCell = await _device.ReadDO7TargetLoadCellAsync();
+ DO8TargetLoadCell = await _device.ReadDO8TargetLoadCellAsync();
+ DO1Threshold = await _device.ReadDO1ThresholdAsync();
+ DO2Threshold = await _device.ReadDO2ThresholdAsync();
+ DO3Threshold = await _device.ReadDO3ThresholdAsync();
+ DO4Threshold = await _device.ReadDO4ThresholdAsync();
+ DO5Threshold = await _device.ReadDO5ThresholdAsync();
+ DO6Threshold = await _device.ReadDO6ThresholdAsync();
+ DO7Threshold = await _device.ReadDO7ThresholdAsync();
+ DO8Threshold = await _device.ReadDO8ThresholdAsync();
+ DO1TimeAboveThreshold = await _device.ReadDO1TimeAboveThresholdAsync();
+ DO2TimeAboveThreshold = await _device.ReadDO2TimeAboveThresholdAsync();
+ DO3TimeAboveThreshold = await _device.ReadDO3TimeAboveThresholdAsync();
+ DO4TimeAboveThreshold = await _device.ReadDO4TimeAboveThresholdAsync();
+ DO5TimeAboveThreshold = await _device.ReadDO5TimeAboveThresholdAsync();
+ DO6TimeAboveThreshold = await _device.ReadDO6TimeAboveThresholdAsync();
+ DO7TimeAboveThreshold = await _device.ReadDO7TimeAboveThresholdAsync();
+ DO8TimeAboveThreshold = await _device.ReadDO8TimeAboveThresholdAsync();
+ DO1TimeBelowThreshold = await _device.ReadDO1TimeBelowThresholdAsync();
+ DO2TimeBelowThreshold = await _device.ReadDO2TimeBelowThresholdAsync();
+ DO3TimeBelowThreshold = await _device.ReadDO3TimeBelowThresholdAsync();
+ DO4TimeBelowThreshold = await _device.ReadDO4TimeBelowThresholdAsync();
+ DO5TimeBelowThreshold = await _device.ReadDO5TimeBelowThresholdAsync();
+ DO6TimeBelowThreshold = await _device.ReadDO6TimeBelowThresholdAsync();
+ DO7TimeBelowThreshold = await _device.ReadDO7TimeBelowThresholdAsync();
+ DO8TimeBelowThreshold = await _device.ReadDO8TimeBelowThresholdAsync();
+ EnableEvents = await _device.ReadEnableEventsAsync();
+
+
+ // generate observable for the _deviceSync
+ _deviceEventsObservable = GenerateEventMessages();
+
+ Connected = true;
+
+ //Log.Information("Connected to device");
+
+
+
+ _ = ReadData();
+ }
+
+ public IObservable GenerateEventMessages()
+ {
+ return Observable.Create(async (observer, cancellationToken) =>
+ {
+ // Loop until cancellation is requested or the device is no longer available.
+ while (!cancellationToken.IsCancellationRequested && _device != null)
+ {
+ // Capture local reference and check for null.
+ var device = _device;
+ if (device == null)
+ {
+ observer.OnCompleted();
+ break;
+ }
+
+ try
+ {
+ // Check if LoadCellData event is enabled
+ if (IsLoadCellDataEnabled)
+ {
+ var result = await device.ReadLoadCellDataAsync(cancellationToken);
+ // Update the corresponding property with the result
+ // FIXME: this might not be the most appropriate action, please review for each case
+ LoadCellData = result;
+ observer.OnNext($"LoadCellData: {result}");
+ }
+
+ // Check if DigitalInput event is enabled
+ if (IsDigitalInputEnabled)
+ {
+ var result = await device.ReadDigitalInputStateAsync(cancellationToken);
+ // Update the corresponding property with the result
+ // FIXME: this might not be the most appropriate action, please review for each case
+ DigitalInputState = result;
+ observer.OnNext($"DigitalInput: {result}");
+ }
+
+ // Check if SyncOutput event is enabled
+ if (IsSyncOutputEnabled)
+ {
+ var result = await device.ReadSyncOutputStateAsync(cancellationToken);
+ // Update the corresponding property with the result
+ // FIXME: this might not be the most appropriate action, please review for each case
+ SyncOutputState = result;
+ observer.OnNext($"SyncOutput: {result}");
+ }
+
+ // Check if Thresholds event is enabled
+ if (IsThresholdsEnabled)
+ {
+ // Read all threshold-related registers and notify the observer
+ var doThresholds = new[]
+ {
+ await device.ReadDO1ThresholdAsync(cancellationToken),
+ await device.ReadDO2ThresholdAsync(cancellationToken),
+ await device.ReadDO3ThresholdAsync(cancellationToken),
+ await device.ReadDO4ThresholdAsync(cancellationToken),
+ await device.ReadDO5ThresholdAsync(cancellationToken),
+ await device.ReadDO6ThresholdAsync(cancellationToken),
+ await device.ReadDO7ThresholdAsync(cancellationToken),
+ await device.ReadDO8ThresholdAsync(cancellationToken)
+ };
+ var doTimeAbove = new[]
+ {
+ await device.ReadDO1TimeAboveThresholdAsync(cancellationToken),
+ await device.ReadDO2TimeAboveThresholdAsync(cancellationToken),
+ await device.ReadDO3TimeAboveThresholdAsync(cancellationToken),
+ await device.ReadDO4TimeAboveThresholdAsync(cancellationToken),
+ await device.ReadDO5TimeAboveThresholdAsync(cancellationToken),
+ await device.ReadDO6TimeAboveThresholdAsync(cancellationToken),
+ await device.ReadDO7TimeAboveThresholdAsync(cancellationToken),
+ await device.ReadDO8TimeAboveThresholdAsync(cancellationToken)
+ };
+ var doTimeBelow = new[]
+ {
+ await device.ReadDO1TimeBelowThresholdAsync(cancellationToken),
+ await device.ReadDO2TimeBelowThresholdAsync(cancellationToken),
+ await device.ReadDO3TimeBelowThresholdAsync(cancellationToken),
+ await device.ReadDO4TimeBelowThresholdAsync(cancellationToken),
+ await device.ReadDO5TimeBelowThresholdAsync(cancellationToken),
+ await device.ReadDO6TimeBelowThresholdAsync(cancellationToken),
+ await device.ReadDO7TimeBelowThresholdAsync(cancellationToken),
+ await device.ReadDO8TimeBelowThresholdAsync(cancellationToken)
+ };
+
+ for (int i = 0; i < 8; i++)
+ {
+ observer.OnNext($"DO{i + 1}Threshold: {doThresholds[i]}");
+ observer.OnNext($"DO{i + 1}TimeAboveThreshold: {doTimeAbove[i]}");
+ observer.OnNext($"DO{i + 1}TimeBelowThreshold: {doTimeBelow[i]}");
+ }
+
+ var DigitalOutputStateResult = await device.ReadDigitalOutputStateAsync(cancellationToken);
+ DigitalOutputState = DigitalOutputStateResult;
+ observer.OnNext($"DigitalOutputState: {DigitalOutputStateResult}");
+
+ }
+
+ // Wait a short while before polling again. Adjust delay as necessary.
+ await Task.Delay(TimeSpan.FromMilliseconds(10), cancellationToken);
+ }
+ catch (OperationCanceledException)
+ {
+ break;
+ }
+ catch (Exception ex)
+ {
+ observer.OnError(ex);
+ break;
+ }
+ }
+ observer.OnCompleted();
+ return Disposable.Empty;
+ });
+ }
+
+ private IObservable SaveConfiguration(bool savePermanently)
+ {
+ return Observable.StartAsync(async () =>
+ {
+ if (_device == null)
+ throw new Exception("You need to connect to the device first");
+ await WriteAndLogAsync(
+ value => _device.WriteAcquisitionStateAsync(value),
+ AcquisitionState,
+ "AcquisitionState");
+ await WriteAndLogAsync(
+ value => _device.WriteDI0TriggerAsync(value),
+ DI0Trigger,
+ "DI0Trigger");
+ await WriteAndLogAsync(
+ value => _device.WriteDO0SyncAsync(value),
+ DO0Sync,
+ "DO0Sync");
+ await WriteAndLogAsync(
+ value => _device.WriteDO0PulseWidthAsync(value),
+ DO0PulseWidth,
+ "DO0PulseWidth");
+ await WriteAndLogAsync(
+ value => _device.WriteDigitalOutputSetAsync(value),
+ DigitalOutputSet,
+ "DigitalOutputSet");
+ await WriteAndLogAsync(
+ value => _device.WriteDigitalOutputClearAsync(value),
+ DigitalOutputClear,
+ "DigitalOutputClear");
+ await WriteAndLogAsync(
+ value => _device.WriteDigitalOutputToggleAsync(value),
+ DigitalOutputToggle,
+ "DigitalOutputToggle");
+ await WriteAndLogAsync(
+ value => _device.WriteOffsetLoadCell0Async(value),
+ OffsetLoadCell0,
+ "OffsetLoadCell0");
+ await WriteAndLogAsync(
+ value => _device.WriteOffsetLoadCell1Async(value),
+ OffsetLoadCell1,
+ "OffsetLoadCell1");
+ await WriteAndLogAsync(
+ value => _device.WriteOffsetLoadCell2Async(value),
+ OffsetLoadCell2,
+ "OffsetLoadCell2");
+ await WriteAndLogAsync(
+ value => _device.WriteOffsetLoadCell3Async(value),
+ OffsetLoadCell3,
+ "OffsetLoadCell3");
+ await WriteAndLogAsync(
+ value => _device.WriteOffsetLoadCell4Async(value),
+ OffsetLoadCell4,
+ "OffsetLoadCell4");
+ await WriteAndLogAsync(
+ value => _device.WriteOffsetLoadCell5Async(value),
+ OffsetLoadCell5,
+ "OffsetLoadCell5");
+ await WriteAndLogAsync(
+ value => _device.WriteOffsetLoadCell6Async(value),
+ OffsetLoadCell6,
+ "OffsetLoadCell6");
+ await WriteAndLogAsync(
+ value => _device.WriteOffsetLoadCell7Async(value),
+ OffsetLoadCell7,
+ "OffsetLoadCell7");
+ await WriteAndLogAsync(
+ value => _device.WriteDO1TargetLoadCellAsync(value),
+ DO1TargetLoadCell,
+ "DO1TargetLoadCell");
+ await WriteAndLogAsync(
+ value => _device.WriteDO2TargetLoadCellAsync(value),
+ DO2TargetLoadCell,
+ "DO2TargetLoadCell");
+ await WriteAndLogAsync(
+ value => _device.WriteDO3TargetLoadCellAsync(value),
+ DO3TargetLoadCell,
+ "DO3TargetLoadCell");
+ await WriteAndLogAsync(
+ value => _device.WriteDO4TargetLoadCellAsync(value),
+ DO4TargetLoadCell,
+ "DO4TargetLoadCell");
+ await WriteAndLogAsync(
+ value => _device.WriteDO5TargetLoadCellAsync(value),
+ DO5TargetLoadCell,
+ "DO5TargetLoadCell");
+ await WriteAndLogAsync(
+ value => _device.WriteDO6TargetLoadCellAsync(value),
+ DO6TargetLoadCell,
+ "DO6TargetLoadCell");
+ await WriteAndLogAsync(
+ value => _device.WriteDO7TargetLoadCellAsync(value),
+ DO7TargetLoadCell,
+ "DO7TargetLoadCell");
+ await WriteAndLogAsync(
+ value => _device.WriteDO8TargetLoadCellAsync(value),
+ DO8TargetLoadCell,
+ "DO8TargetLoadCell");
+ await WriteAndLogAsync(
+ value => _device.WriteDO1ThresholdAsync(value),
+ DO1Threshold,
+ "DO1Threshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO2ThresholdAsync(value),
+ DO2Threshold,
+ "DO2Threshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO3ThresholdAsync(value),
+ DO3Threshold,
+ "DO3Threshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO4ThresholdAsync(value),
+ DO4Threshold,
+ "DO4Threshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO5ThresholdAsync(value),
+ DO5Threshold,
+ "DO5Threshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO6ThresholdAsync(value),
+ DO6Threshold,
+ "DO6Threshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO7ThresholdAsync(value),
+ DO7Threshold,
+ "DO7Threshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO8ThresholdAsync(value),
+ DO8Threshold,
+ "DO8Threshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO1TimeAboveThresholdAsync(value),
+ DO1TimeAboveThreshold,
+ "DO1TimeAboveThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO2TimeAboveThresholdAsync(value),
+ DO2TimeAboveThreshold,
+ "DO2TimeAboveThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO3TimeAboveThresholdAsync(value),
+ DO3TimeAboveThreshold,
+ "DO3TimeAboveThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO4TimeAboveThresholdAsync(value),
+ DO4TimeAboveThreshold,
+ "DO4TimeAboveThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO5TimeAboveThresholdAsync(value),
+ DO5TimeAboveThreshold,
+ "DO5TimeAboveThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO6TimeAboveThresholdAsync(value),
+ DO6TimeAboveThreshold,
+ "DO6TimeAboveThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO7TimeAboveThresholdAsync(value),
+ DO7TimeAboveThreshold,
+ "DO7TimeAboveThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO8TimeAboveThresholdAsync(value),
+ DO8TimeAboveThreshold,
+ "DO8TimeAboveThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO1TimeBelowThresholdAsync(value),
+ DO1TimeBelowThreshold,
+ "DO1TimeBelowThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO2TimeBelowThresholdAsync(value),
+ DO2TimeBelowThreshold,
+ "DO2TimeBelowThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO3TimeBelowThresholdAsync(value),
+ DO3TimeBelowThreshold,
+ "DO3TimeBelowThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO4TimeBelowThresholdAsync(value),
+ DO4TimeBelowThreshold,
+ "DO4TimeBelowThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO5TimeBelowThresholdAsync(value),
+ DO5TimeBelowThreshold,
+ "DO5TimeBelowThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO6TimeBelowThresholdAsync(value),
+ DO6TimeBelowThreshold,
+ "DO6TimeBelowThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO7TimeBelowThresholdAsync(value),
+ DO7TimeBelowThreshold,
+ "DO7TimeBelowThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteDO8TimeBelowThresholdAsync(value),
+ DO8TimeBelowThreshold,
+ "DO8TimeBelowThreshold");
+ await WriteAndLogAsync(
+ value => _device.WriteEnableEventsAsync(value),
+ EnableEvents,
+ "EnableEvents");
+
+ // Save the configuration to the device permanently
+ if (savePermanently)
+ {
+ // To prevent multiple calls to the device while it is resetting
+ _deviceEventsSubscription?.Dispose();
+ _deviceEventsSubscription = null;
+
+ await WriteAndLogAsync(
+ value => _device.WriteResetDeviceAsync(value),
+ ResetFlags.Save,
+ "SavePermanently");
+
+ // Wait to ensure the device is ready after the reset
+ await Task.Delay(4000);
+
+ // Re-subscribe to the device events observable
+ SubscribeToEvents();
+ }
+ });
+ }
+
+ private IObservable ResetConfiguration()
+ {
+ return Observable.StartAsync(async () =>
+ {
+ if (_device != null)
+ {
+ await WriteAndLogAsync(
+ value => _device.WriteResetDeviceAsync(value),
+ ResetFlags.RestoreDefault,
+ "ResetDevice");
+ }
+ });
+ }
+
+ private void SubscribeToEvents()
+ {
+ _deviceEventsSubscription = _deviceEventsObservable
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(
+ msg => HarpEvents.Add(msg.ToString()),
+ ex => Debug.WriteLine($"Error in device events: {ex}")
+ );
+ }
+
+ private async Task WriteAndLogAsync(Func writeFunc, T value, string registerName)
+ {
+ if (_device == null)
+ throw new Exception("Device is not connected");
+
+ await writeFunc(value);
+
+ // Log the message to the SentMessages collection on the UI thread
+ RxApp.MainThreadScheduler.Schedule(() =>
+ {
+ SentMessages.Add($"{DateTime.Now:HH:mm:ss.fff} - Write {registerName}: {value}");
+ });
+ }
+
+ // Update the UpdateSeries method:
+ private void CreateSeries()
+ {
+
+ Series = new ObservableCollection();
+
+ _customAxis = new DateTimeAxis(TimeSpan.FromSeconds(1), Formatter)
+ {
+ CustomSeparators = GetSeparators(),
+ AnimationsSpeed = TimeSpan.FromMilliseconds(0),
+ SeparatorsPaint = new SolidColorPaint(SKColors.Black.WithAlpha(100))
+ };
+
+ XAxes = [_customAxis];
+
+ if (Show0)
+ Series.Add(new LineSeries { Values = _values0, Fill = null, GeometryFill = null, GeometryStroke = null, Stroke = new SolidColorPaint(SKColors.Blue, 2) });
+ if (Show1)
+ Series.Add(new LineSeries { Values = _values1, Fill = null, GeometryFill = null, GeometryStroke = null, Stroke = new SolidColorPaint(SKColors.Red, 2) });
+ if (Show2)
+ Series.Add(new LineSeries { Values = _values2, Fill = null, GeometryFill = null, GeometryStroke = null, Stroke = new SolidColorPaint(SKColors.Green, 2) });
+ if (Show3)
+ Series.Add(new LineSeries { Values = _values3, Fill = null, GeometryFill = null, GeometryStroke = null, Stroke = new SolidColorPaint(SKColors.Orange, 2) });
+ if (Show4)
+ Series.Add(new LineSeries { Values = _values4, Fill = null, GeometryFill = null, GeometryStroke = null, Stroke = new SolidColorPaint(SKColors.Purple, 2) });
+ if (Show5)
+ Series.Add(new LineSeries { Values = _values5, Fill = null, GeometryFill = null, GeometryStroke = null, Stroke = new SolidColorPaint(SKColors.Brown, 2) });
+ if (Show6)
+ Series.Add(new LineSeries { Values = _values6, Fill = null, GeometryFill = null, GeometryStroke = null, Stroke = new SolidColorPaint(SKColors.Cyan, 2) });
+ if (Show7)
+ Series.Add(new LineSeries { Values = _values7, Fill = null, GeometryFill = null, GeometryStroke = null, Stroke = new SolidColorPaint(SKColors.Magenta, 2) });
+ }
+
+ // Update ReadData to add data for all 8 channels
+ private async Task ReadData()
+ {
+ while (Connected)
+ {
+ await Task.Delay(30);
+
+ lock (SyncChart)
+ {
+ var now = DateTime.Now;
+ _values0.Add(new DateTimePoint(now, LoadCellData.Channel0));
+ _values1.Add(new DateTimePoint(now, LoadCellData.Channel1));
+ _values2.Add(new DateTimePoint(now, LoadCellData.Channel2));
+ _values3.Add(new DateTimePoint(now, LoadCellData.Channel3));
+ _values4.Add(new DateTimePoint(now, LoadCellData.Channel4));
+ _values5.Add(new DateTimePoint(now, LoadCellData.Channel5));
+ _values6.Add(new DateTimePoint(now, LoadCellData.Channel6));
+ _values7.Add(new DateTimePoint(now, LoadCellData.Channel7));
+
+ if (_values0.Count > 250)
+ _values0.RemoveAt(0);
+ if (_values1.Count > 250)
+ _values1.RemoveAt(0);
+ if (_values2.Count > 250)
+ _values2.RemoveAt(0);
+ if (_values3.Count > 250)
+ _values3.RemoveAt(0);
+ if (_values4.Count > 250)
+ _values4.RemoveAt(0);
+ if (_values5.Count > 250)
+ _values5.RemoveAt(0);
+ if (_values6.Count > 250)
+ _values6.RemoveAt(0);
+ if (_values7.Count > 250)
+ _values7.RemoveAt(0);
+
+ _customAxis.CustomSeparators = GetSeparators();
+ }
+ }
+ }
+
+ // GetSeparators generates a set of custom ticks for the DateTimeAxis
+ private static double[] GetSeparators()
+ {
+ var now = DateTime.Now;
+
+ return
+ [
+ now.AddSeconds(-20).Ticks,
+ now.AddSeconds(-15).Ticks,
+ now.AddSeconds(-10).Ticks,
+ now.AddSeconds(-5).Ticks,
+ now.Ticks
+ ];
+ }
+
+ private static string Formatter(DateTime date)
+ {
+ var secsAgo = (DateTime.Now - date).TotalSeconds;
+
+ return secsAgo < 1
+ ? "0"
+ : $"{secsAgo:N0}s ago";
+ }
+
+}
diff --git a/App/Harp.LoadCells.Design/ViewModels/ViewModelBase.cs b/App/Harp.LoadCells.Design/ViewModels/ViewModelBase.cs
new file mode 100644
index 0000000..1e43fc1
--- /dev/null
+++ b/App/Harp.LoadCells.Design/ViewModels/ViewModelBase.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Reactive.Linq;
+using Avalonia;
+using Avalonia.Media;
+using Avalonia.Platform;
+using Avalonia.Styling;
+using ReactiveUI;
+using ReactiveUI.Fody.Helpers;
+
+namespace Harp.LoadCells.Design.ViewModels;
+
+public class ViewModelBase : ReactiveObject
+{
+ [Reactive] public bool IsDarkMode { get; set; }
+ [Reactive] public IBrush IconColor { get; set; }
+
+ public ViewModelBase()
+ {
+ // Get the current theme on Application.Current!.RequestedTheme
+ var currentTheme = Application.Current!.RequestedThemeVariant;
+ IsDarkMode = currentTheme == ThemeVariant.Dark ||
+ (currentTheme == ThemeVariant.Default && IsSystemInDarkMode());
+
+ // set initial color
+ IconColor = IsDarkMode ? Brushes.White : Brushes.Black;
+
+ // update icon color when IsDarkMode changes
+ this.WhenAnyValue(x => x.IsDarkMode)
+ .Subscribe(isDarkMode =>
+ {
+ IconColor = isDarkMode ? Brushes.White : Brushes.Black;
+ });
+
+ // Subscribe to changes in IsDarkMode
+ this.WhenAnyValue(x => x.IsDarkMode)
+ .Skip(1) // Skip the initial value to avoid unnecessary theme change on initialization
+ .Subscribe(isDarkMode => Application.Current.RequestedThemeVariant = isDarkMode ? ThemeVariant.Dark : ThemeVariant.Light);
+ }
+
+ private bool IsSystemInDarkMode()
+ {
+ // detect using avalonia if system is in dark mode
+ var colors = Application.Current!.PlatformSettings!.GetColorValues();
+ return colors.ThemeVariant == PlatformThemeVariant.Dark;
+ }
+}
diff --git a/App/Harp.LoadCells.Design/Views/About.axaml b/App/Harp.LoadCells.Design/Views/About.axaml
new file mode 100644
index 0000000..4eb5fda
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Views/About.axaml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+ The LoadCells GUI application allows to configure the LoadCells device, developed by the Hardware and Software Platform at the Champalimaud Foundation.
+
+ The LoadCells device is a Harp device and has all the inherent functionality of Harp devices.
+
+ The GUI was developed using [.NET](https://dotnet.microsoft.com/), [AvaloniaUI](https://avaloniaui.net/) with ReactiveUI and makes direct use of the [Bonsai.Harp](https://github.com/bonsai-rx/harp) library.
+
+ As with other Harp devices, the LoadCells can also be used in [Bonsai](https://bonsai-rx.org/).
+
+
+
diff --git a/App/Harp.LoadCells.Design/Views/About.axaml.cs b/App/Harp.LoadCells.Design/Views/About.axaml.cs
new file mode 100644
index 0000000..4f869fc
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Views/About.axaml.cs
@@ -0,0 +1,11 @@
+using Avalonia.Controls;
+
+namespace Harp.LoadCells.Design.Views;
+
+public partial class About : Window
+{
+ public About()
+ {
+ InitializeComponent();
+ }
+}
diff --git a/App/Harp.LoadCells.Design/Views/MainWindow.axaml b/App/Harp.LoadCells.Design/Views/MainWindow.axaml
new file mode 100644
index 0000000..00e3382
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Views/MainWindow.axaml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/App/Harp.LoadCells.Design/Views/MainWindow.axaml.cs b/App/Harp.LoadCells.Design/Views/MainWindow.axaml.cs
new file mode 100644
index 0000000..08b91b5
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Views/MainWindow.axaml.cs
@@ -0,0 +1,11 @@
+using Avalonia.Controls;
+
+namespace Harp.LoadCells.Design.Views;
+
+public partial class MainWindow : Window
+{
+ public MainWindow()
+ {
+ InitializeComponent();
+ }
+}
diff --git a/App/Harp.LoadCells.Design/Views/MyDeviceView.axaml b/App/Harp.LoadCells.Design/Views/MyDeviceView.axaml
new file mode 100644
index 0000000..891b577
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Views/MyDeviceView.axaml
@@ -0,0 +1,649 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Specifies the active events in the device.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Enables the data acquisition.
+
+
+
+
+
+
+
+
+
+
+ Pulse duration (ms) for the digital output pin 0. The pulse will only be emitted when DO0Sync == Pulse.
+
+
+
+
+
+
+
+
+
+ Configuration of the digital output pin 0.
+
+
+
+
+
+
+ Controlled by software
+ Toggles each second during acquisition
+ Generates a pulse
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Configuration of the digital input pin 0.
+
+
+
+
+
+
+ Pure digital input
+ Start acquisition on a rising edge
+ Start acquisition on a falling edge
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Status of the digital input pin 0. An event will be emitted when DI0Trigger == None.
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Status of the digital output pin 0. An periodic event will be emitted when DO0Sync == ToggleEachSecond.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Target Load Cell that will be used to trigger a threshold event on the DO pin.
+
+
+
+
+
+
+ Value used to threshold a Load Cell read, and trigger the DO pin.
+
+
+
+
+
+
+ Time (ms) above threshold value that is required to trigger the DO pin event.
+
+
+
+
+
+
+ Time (ms) below threshold value that is required to trigger the DO pin event.
+
+
+
+
+
+
+ Write the state of all digital output lines. An event will be emitted when the value of any pin was changed by a threshold event.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Notes:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Value of single ADC read from all load cell channels.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/App/Harp.LoadCells.Design/Views/MyDeviceView.axaml.cs b/App/Harp.LoadCells.Design/Views/MyDeviceView.axaml.cs
new file mode 100644
index 0000000..5971fd1
--- /dev/null
+++ b/App/Harp.LoadCells.Design/Views/MyDeviceView.axaml.cs
@@ -0,0 +1,11 @@
+using Avalonia.Controls;
+
+namespace Harp.LoadCells.Design.Views;
+
+public partial class LoadCellsView : UserControl
+{
+ public LoadCellsView()
+ {
+ InitializeComponent();
+ }
+}
diff --git a/App/Harp.LoadCells.nsi b/App/Harp.LoadCells.nsi
new file mode 100644
index 0000000..ab09e88
Binary files /dev/null and b/App/Harp.LoadCells.nsi differ
diff --git a/App/LICENSE b/App/LICENSE
new file mode 100644
index 0000000..47539f7
--- /dev/null
+++ b/App/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2021-2023 Hardware & Software Platform, Champalimaud Foundation
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
\ No newline at end of file
diff --git a/App/README.md b/App/README.md
new file mode 100644
index 0000000..8ca7477
--- /dev/null
+++ b/App/README.md
@@ -0,0 +1,2 @@
+# Harp.LoadCells.App
+