Skip to content

Commit

Permalink
add LPT并口通讯
Browse files Browse the repository at this point in the history
  • Loading branch information
何秀奇 committed Jul 3, 2024
1 parent e41786e commit 9c0147c
Show file tree
Hide file tree
Showing 16 changed files with 641 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Commun.NetCore/Commun.NetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<!--<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>-->
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Commun.NetWork/Commun.NetWork.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Commun.NetWork</RootNamespace>
<AssemblyName>Commun.NetWork</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
Expand Down
10 changes: 2 additions & 8 deletions CommunTools.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31313.381
# Visual Studio Version 17
VisualStudioVersion = 17.10.35013.160
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunTools", "CommunTools\CommunTools.csproj", "{B907527A-675C-400B-AD88-129581690C0B}"
EndProject
Expand All @@ -23,8 +23,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.props = Directory.Build.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZCS_FormTest", "ZCS_FormTest\ZCS_FormTest.csproj", "{18E09D61-FD45-4F99-998E-C725DED37706}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -59,10 +57,6 @@ Global
{DB9852F6-DCFE-4209-BDC5-48362F2A259E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB9852F6-DCFE-4209-BDC5-48362F2A259E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB9852F6-DCFE-4209-BDC5-48362F2A259E}.Release|Any CPU.Build.0 = Release|Any CPU
{18E09D61-FD45-4F99-998E-C725DED37706}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18E09D61-FD45-4F99-998E-C725DED37706}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18E09D61-FD45-4F99-998E-C725DED37706}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18E09D61-FD45-4F99-998E-C725DED37706}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
11 changes: 10 additions & 1 deletion CommunTools/CommunTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<RootNamespace>CommunTools</RootNamespace>
<AssemblyName>CommunTools</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
Expand Down Expand Up @@ -78,6 +78,12 @@
<Compile Include="Enums\Encoding.cs" />
<Compile Include="Enums\FuncItemCom.cs" />
<Compile Include="Enums\SerialPortEnum.cs" />
<Compile Include="FrmBaseCom\Frm_ComLPT.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FrmBaseCom\Frm_ComLPT.Designer.cs">
<DependentUpon>Frm_ComLPT.cs</DependentUpon>
</Compile>
<Compile Include="FrmBaseCom\Frm_ComWebSocket.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -129,6 +135,9 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Common\SerialPortEventArgs.cs" />
<EmbeddedResource Include="FrmBaseCom\Frm_ComLPT.resx">
<DependentUpon>Frm_ComLPT.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FrmBaseCom\Frm_ComWebSocket.resx">
<DependentUpon>Frm_ComWebSocket.cs</DependentUpon>
</EmbeddedResource>
Expand Down
9 changes: 8 additions & 1 deletion CommunTools/Enums/FuncItemCom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ public enum Com_BaseFuncItem
/// </summary>
[Description(" UDP通讯")]
[FuncURI("Frm_ComUDP")]
COM_ComUDP = 9
COM_ComUDP = 9,

/// <summary>
/// WebSocket
/// </summary>
[Description(" LPT并口通讯")]
[FuncURI("Frm_ComLPT")]
COM_ComLTP = 10
}

/// <summary>
Expand Down
149 changes: 149 additions & 0 deletions CommunTools/FrmBaseCom/Frm_ComLPT.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions CommunTools/FrmBaseCom/Frm_ComLPT.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Com_CSSkin;
using Commun.NetWork.MQTT;
using CommunTools.Common;
using CommunTools.Common.Twain;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace CommunTools
{
/// <summary>
/// LPT并口通讯
/// </summary>
public partial class Frm_ComLPT : CSSkinMain
{
public Frm_ComLPT()
{
InitializeComponent();
}

public class PortControl // Import dll to project
{
[DllImport("inpout32.dll", EntryPoint = "Out32")]
public static extern void Output(int portAddress, int value); // decimal

[DllImport("inpout32.dll", EntryPoint = "Inp32")]
public static extern int Input(int portAddress);
}

static int portAddress = 0x378; // Typically, 0x378 is the address for LPT1
static int portDecData = 0xFF;

private void btnInp_BtnClick(object sender, EventArgs e)
{
// Read a value from the parallel port
Console.WriteLine("Reading value from the parallel port...");
int value = PortControl.Input(portAddress);
Console.WriteLine($"Value read from port: {value:X}");
}

private void btnOut_BtnClick(object sender, EventArgs e)
{
// Write a value to the parallel port
Console.WriteLine("Writing value to the parallel port...");
PortControl.Output(portAddress, portDecData); // Sending 0xFF (all bits high)
}
}
}
Loading

0 comments on commit 9c0147c

Please sign in to comment.