Fixes in ReadFromSerialPort ---- UpdateUI

main
muhammad.faique 2025-02-10 16:02:13 +05:00
parent ddfd4b4591
commit 98cddf6586
24 changed files with 441 additions and 149 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

2
MainForm.Designer.cs generated
View File

@ -275,7 +275,7 @@ namespace AVS
this.btn_reset_port.TabIndex = 57; this.btn_reset_port.TabIndex = 57;
this.btn_reset_port.Text = "RESET PORT"; this.btn_reset_port.Text = "RESET PORT";
this.btn_reset_port.UseVisualStyleBackColor = false; this.btn_reset_port.UseVisualStyleBackColor = false;
this.btn_reset_port.Visible = false; this.btn_reset_port.Visible = true;
this.btn_reset_port.Click += new System.EventHandler(this.btn_reset_port_Click); this.btn_reset_port.Click += new System.EventHandler(this.btn_reset_port_Click);
// //
// openFileDialog1 // openFileDialog1

View File

@ -51,6 +51,9 @@ namespace AVS
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)] [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetupDiCallClassInstaller(uint InstallFunction, IntPtr deviceInfoSet, ref SP_DEVINFO_DATA deviceInfoData); public static extern bool SetupDiCallClassInstaller(uint InstallFunction, IntPtr deviceInfoSet, ref SP_DEVINFO_DATA deviceInfoData);
[DllImport("setupapi.dll")]
static extern bool SetupDiDestroyDeviceInfoList(IntPtr deviceInfoSet);
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public class SP_DEVINFO_DATA public class SP_DEVINFO_DATA
{ {
@ -1739,6 +1742,35 @@ namespace AVS
} }
} }
} }
else
{
pb_red.Visible = false; // Hide red indicator
pb_blue.Visible = true; // Show blue indicator for data received
// Match weight pattern in message (e.g., "123.45 kg")
Match match = Regex.Match(message, @"(\d+(\.\d+)?) kg");
if (match.Success && double.TryParse(match.Groups[1].Value, out double weight))
{
// Only update weight display if it has changed
if (weight != PreviousWeight)
{
PreviousWeight = weight; // Update the previous weight
txt_weight.Text = weight.ToString("0.000"); // Display the current weight
}
// Update hold weight if above threshold
if (weight > 0.020)
{
lbl_hold_weight.Text = weight.ToString("0.000"); // Display the hold weight
}
message = "Machine connected";
lbl_msg.ForeColor = Color.Green;
lbl_msg.Text = message;
}
}
} }
else else
{ {
@ -1763,6 +1795,7 @@ namespace AVS
} }
} }
})); }));
} }
private void HandleException(Exception ex) private void HandleException(Exception ex)
@ -1923,27 +1956,40 @@ namespace AVS
} }
// Disable a device by Instance ID // Disable a device by Instance ID
public static void DisableDevice(string deviceInstanceId) public static void DisableDevice(string deviceInstanceId)
{ {
IntPtr deviceInfoSet = SetupDiGetClassDevs(IntPtr.Zero, deviceInstanceId, IntPtr.Zero, DIGCF_PRESENT); IntPtr deviceInfoSet = SetupDiGetClassDevs(IntPtr.Zero, deviceInstanceId, IntPtr.Zero, DIGCF_PRESENT);
if (deviceInfoSet == IntPtr.Zero) if (deviceInfoSet == IntPtr.Zero)
{ {
Console.WriteLine("Error getting device info set."); throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to get device info set");
return;
} }
SP_DEVINFO_DATA deviceInfoData = new SP_DEVINFO_DATA(); try
deviceInfoData.cbSize = (uint)Marshal.SizeOf(typeof(SP_DEVINFO_DATA));
uint index = 0;
while (SetupDiEnumDeviceInfo(deviceInfoSet, index, ref deviceInfoData))
{ {
Console.WriteLine($"Found device: {deviceInfoData.DevInst}"); SP_DEVINFO_DATA deviceInfoData = new SP_DEVINFO_DATA();
SetupDiCallClassInstaller(DIF_DISABLE, deviceInfoSet, ref deviceInfoData); deviceInfoData.cbSize = (uint)Marshal.SizeOf(typeof(SP_DEVINFO_DATA));
Console.WriteLine("Device disabled.");
break; // Stop after disabling the first matching device for (uint index = 0; SetupDiEnumDeviceInfo(deviceInfoSet, index, ref deviceInfoData); index++)
{
Console.WriteLine($"Found device: {deviceInfoData.DevInst}");
if (!SetupDiCallClassInstaller(DIF_DISABLE, deviceInfoSet, ref deviceInfoData))
{
Console.WriteLine("Device disabled.");
break; // Stop after disabling the first matching device
}
else
{
Console.WriteLine("Failed to disable device.");
}
}
}
finally
{
SetupDiDestroyDeviceInfoList(deviceInfoSet);
} }
Console.WriteLine("No matching device found.");
} }
public static string GetDeviceInstanceIdFromCOMPort(string portName) public static string GetDeviceInstanceIdFromCOMPort(string portName)
{ {

Binary file not shown.

Binary file not shown.

View File

@ -94,7 +94,8 @@
"net47", "net47",
"net471", "net471",
"net472", "net472",
"net48" "net48",
"net481"
], ],
"assetTargetFallback": true, "assetTargetFallback": true,
"warn": true, "warn": true,
@ -106,7 +107,7 @@
"privateAssets": "none" "privateAssets": "none"
} }
}, },
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.416\\RuntimeIdentifierGraph.json" "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.403\\RuntimeIdentifierGraph.json"
} }
} }
} }

View File

@ -7,16 +7,13 @@
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot> <NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\muhammad.faique\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages;C:\Program Files (x86)\Microsoft\Xamarin\NuGet\</NuGetPackageFolders> <NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\muhammad.faique\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages;C:\Program Files (x86)\Microsoft\Xamarin\NuGet\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle> <NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">5.11.6</NuGetToolVersion> <NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.7.0</NuGetToolVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' "> <ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\muhammad.faique\.nuget\packages\" /> <SourceRoot Include="C:\Users\muhammad.faique\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" /> <SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft\Xamarin\NuGet\" /> <SourceRoot Include="C:\Program Files (x86)\Microsoft\Xamarin\NuGet\" />
</ItemGroup> </ItemGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' "> <ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)entityframework\6.4.4\buildTransitive\netcoreapp3.0\EntityFramework.props" Condition="Exists('$(NuGetPackageRoot)entityframework\6.4.4\buildTransitive\netcoreapp3.0\EntityFramework.props')" /> <Import Project="$(NuGetPackageRoot)entityframework\6.4.4\buildTransitive\netcoreapp3.0\EntityFramework.props" Condition="Exists('$(NuGetPackageRoot)entityframework\6.4.4\buildTransitive\netcoreapp3.0\EntityFramework.props')" />
</ImportGroup> </ImportGroup>

View File

@ -1,8 +1,5 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?> <?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' "> <ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)system.text.encodings.web\7.0.0\buildTransitive\netcoreapp2.0\System.Text.Encodings.Web.targets" Condition="Exists('$(NuGetPackageRoot)system.text.encodings.web\7.0.0\buildTransitive\netcoreapp2.0\System.Text.Encodings.Web.targets')" /> <Import Project="$(NuGetPackageRoot)system.text.encodings.web\7.0.0\buildTransitive\netcoreapp2.0\System.Text.Encodings.Web.targets" Condition="Exists('$(NuGetPackageRoot)system.text.encodings.web\7.0.0\buildTransitive\netcoreapp2.0\System.Text.Encodings.Web.targets')" />
<Import Project="$(NuGetPackageRoot)system.text.json\7.0.1\buildTransitive\netcoreapp2.0\System.Text.Json.targets" Condition="Exists('$(NuGetPackageRoot)system.text.json\7.0.1\buildTransitive\netcoreapp2.0\System.Text.Json.targets')" /> <Import Project="$(NuGetPackageRoot)system.text.json\7.0.1\buildTransitive\netcoreapp2.0\System.Text.Json.targets" Condition="Exists('$(NuGetPackageRoot)system.text.json\7.0.1\buildTransitive\netcoreapp2.0\System.Text.Json.targets')" />

View File

@ -1,3 +1,9 @@
is_global = true is_global = true
build_property.ApplicationManifest =
build_property.StartupObject =
build_property.ApplicationDefaultFont =
build_property.ApplicationHighDpiMode =
build_property.ApplicationUseCompatibleTextRendering =
build_property.ApplicationVisualStyles =
build_property.RootNamespace = AVS build_property.RootNamespace = AVS
build_property.ProjectDir = D:\Projects\AVS\ build_property.ProjectDir = D:\Projects\AVS\

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"version": 2, "version": 2,
"dgSpecHash": "ruBmURm9Q/B7dlNWTusRQQ/R+5RZgbQgksj//5+Zk8qcXJ14BCeK0BmvogYuoAuZoYXCQn3liiFiW6YFILdXUg==", "dgSpecHash": "QNbNTGu+h1/KOiKWOwagV0AD91N3ZDiiXBDwzgQZ492TlU57m4gvbddfIzuVmuKTrrxSf/B1N8DKBvqOKZCKaA==",
"success": true, "success": true,
"projectFilePath": "D:\\Projects\\AVS\\AVS.csproj", "projectFilePath": "D:\\Projects\\AVS\\AVS.csproj",
"expectedPackageFiles": [ "expectedPackageFiles": [
@ -146,7 +146,7 @@
"code": "NU1701", "code": "NU1701",
"level": "Warning", "level": "Warning",
"warningLevel": 1, "warningLevel": 1,
"message": "Package 'MaterialSkin 0.2.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.", "message": "Package 'MaterialSkin 0.2.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.",
"libraryId": "MaterialSkin", "libraryId": "MaterialSkin",
"targetGraphs": [ "targetGraphs": [
".NETCoreApp,Version=v3.1" ".NETCoreApp,Version=v3.1"