Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/famicom-dumper-client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2021-05-28 04:58:46 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2021-05-28 04:58:46 +0300
commitfff3ab511e9c96d1c6d82c60c26e8ed4b2f79958 (patch)
treec8419690bbf2c5927ccedafca2dafea5c7e5d62d /FamicomDumperConnection
parentd1a136861243918efd4db46867735ee6b02c2deb (diff)
Migrated FamicomDumperConnection to .NET Standard 2.0
Diffstat (limited to 'FamicomDumperConnection')
-rw-r--r--FamicomDumperConnection/FamicomDumperConnection.cs141
-rw-r--r--FamicomDumperConnection/FamicomDumperConnection.csproj65
-rw-r--r--FamicomDumperConnection/packages.config4
3 files changed, 88 insertions, 122 deletions
diff --git a/FamicomDumperConnection/FamicomDumperConnection.cs b/FamicomDumperConnection/FamicomDumperConnection.cs
index d41170b..96a8e6d 100644
--- a/FamicomDumperConnection/FamicomDumperConnection.cs
+++ b/FamicomDumperConnection/FamicomDumperConnection.cs
@@ -209,15 +209,17 @@ namespace com.clusterrr.Famicom.DumperConnection
{
portName = null;
// Need to autodetect port
- if (!IsRunningOnMono()) // Is it running on Windows?
+
+ // Is it running on Windows?
+ try
{
- // First of all lets check bus reported device description
+ // First of all lets check bus reported device descriptions
var allComPorts = Win32DeviceMgmt.GetAllCOMPorts();
foreach (var port in allComPorts)
{
if (!DeviceNames.Contains(port.bus_description))
continue;
- // Seems like it's dumper port but it can me already busy
+ // Seems like it's dumper port but it can be already busy
try
{
sPort = OpenPort(port.name, (int)Timeout);
@@ -231,87 +233,99 @@ namespace com.clusterrr.Famicom.DumperConnection
continue;
}
}
+ }
+ catch { }
- if (portName == null)
+ if (portName == null)
+ {
+ // Port still not detected, using Windows FTDI driver to determine serial number
+ try
{
- try
- {
- // Port still not detected, ising Windows FTDI driver to determine serial number
- FTDI myFtdiDevice = new FTDI();
- uint ftdiDeviceCount = 0;
- FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;
- // FTDI serial number autodetect
- ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
- // Check status
- if (ftStatus != FTDI.FT_STATUS.FT_OK)
- throw new IOException("Failed to get number of devices (error " + ftStatus.ToString() + ")");
+ FTDI myFtdiDevice = new FTDI();
+ uint ftdiDeviceCount = 0;
+ FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;
+ // FTDI serial number autodetect
+ ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount);
+ // Check status
+ if (ftStatus != FTDI.FT_STATUS.FT_OK)
+ throw new IOException("Failed to get number of devices (error " + ftStatus.ToString() + ")");
- // If no devices available, return
- if (ftdiDeviceCount == 0)
- throw new IOException("Failed to get number of devices (error " + ftStatus.ToString() + ")");
+ // If no devices available, return
+ if (ftdiDeviceCount == 0)
+ throw new IOException("Failed to get number of devices (error " + ftStatus.ToString() + ")");
- // Allocate storage for device info list
- FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
+ // Allocate storage for device info list
+ FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
- // Populate our device list
- ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);
+ // Populate our device list
+ ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList);
- portName = null;
- if (ftStatus == FTDI.FT_STATUS.FT_OK)
- {
- var dumpers = ftdiDeviceList.Where(d => DeviceNames.Contains(d.Description));
- portName = dumpers.First().SerialNumber;
- Console.WriteLine($"Autodetected USB device serial number: {portName}");
- }
- if (ftStatus != FTDI.FT_STATUS.FT_OK)
- throw new IOException("Failed to get FTDI devices (error " + ftStatus.ToString() + ")");
- }
- catch
+ portName = null;
+ if (ftStatus == FTDI.FT_STATUS.FT_OK)
{
- throw new IOException($"{DeviceNames[0]} not found");
+ var dumpers = ftdiDeviceList.Where(d => DeviceNames.Contains(d.Description));
+ portName = dumpers.First().SerialNumber;
+ Console.WriteLine($"Autodetected USB device serial number: {portName}");
}
+ if (ftStatus != FTDI.FT_STATUS.FT_OK)
+ throw new IOException("Failed to get FTDI devices (error " + ftStatus.ToString() + ")");
+ }
+ catch
+ {
}
}
- else
+
+ if (portName == null)
{
- // Linux?
+ // Port still not detected, let's try Linux methods
var devices = GetLinuxUsbDevices();
var dumpers = devices.Where(d =>
{
var productFile = Path.Combine(d, "product");
return File.Exists(productFile) && DeviceNames.Contains(File.ReadAllText(productFile).Trim());
});
- if (!dumpers.Any())
- throw new IOException($"{DeviceNames[0]} not found");
- portName = LinuxDeviceToPort(dumpers.First());
- if (string.IsNullOrEmpty(portName))
- throw new IOException($"Can't detect device path");
- Console.WriteLine($"Autodetected USB device path: {portName}");
+ if (dumpers.Any())
+ {
+ portName = LinuxDeviceToPort(dumpers.First());
+ if (string.IsNullOrEmpty(portName))
+ throw new IOException($"Can't detect device path");
+ Console.WriteLine($"Autodetected USB device path: {portName}");
+ }
}
+
+ if (portName == null)
+ throw new IOException($"{DeviceNames.First()} not found, try to specify port name manually");
}
- if (portName.ToUpper().StartsWith("COM") || IsRunningOnMono())
+ if (sPort != null)
{
- // Using VCP
- if (IsRunningOnMono() && !File.Exists(portName))
- {
- // Need to convert serial number to port address
- var ttyPath = LinuxDeviceSerialToPort(portName);
- if (string.IsNullOrEmpty(ttyPath))
- throw new IOException($"Device with serial number {portName} not found");
- portName = ttyPath;
- Console.WriteLine($"Autodetected USB device path: {portName}");
- }
- // Port specified
- if (sPort == null)
+ // success, already opened
+ serialPort = sPort;
+ return;
+ }
+
+ if (portName.ToUpper().StartsWith("COM") || File.Exists(portName))
+ {
+ // Serial port name/path to open
+ serialPort = OpenPort(portName, (int)Timeout);
+ return;
+ }
+
+ try
+ {
+ // Is it VCP serial number?
+ var ttyPath = LinuxDeviceSerialToPort(portName);
+ if (!string.IsNullOrEmpty(ttyPath))
{
- // If not already opened
- sPort = OpenPort(portName, (int)Timeout);
+ serialPort = OpenPort(ttyPath, (int)Timeout);
+ return;
}
- serialPort = sPort;
}
- else
+ catch { }
+
+ try
{
+ // Is is FTDI serial number?
// Using Windows FTDI driver
FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK;
// Create new instance of the FTDI device class
@@ -340,9 +354,12 @@ namespace com.clusterrr.Famicom.DumperConnection
if (ftStatus != FTDI.FT_STATUS.FT_OK)
throw new IOException($"Failed to set latency (error {ftStatus})");
d2xxPort = myFtdiDevice;
+ return;
}
- }
+ catch { }
+ throw new IOException($"Can't open {serialPort}");
+ }
public void Close()
{
if (serialPort != null)
@@ -1059,7 +1076,7 @@ namespace com.clusterrr.Famicom.DumperConnection
/// <param name="blockNumbers">Block numbers to write (zero-based)</param>
/// <param name="block">Block data</param>
public void WriteFdsBlocks(byte blockNumber, byte[] block)
- => WriteFdsBlocks(new byte[] { blockNumber }, block );
+ => WriteFdsBlocks(new byte[] { blockNumber }, block);
/// <summary>
/// Write single block to Famicom Disk System card
@@ -1067,7 +1084,7 @@ namespace com.clusterrr.Famicom.DumperConnection
/// <param name="blockNumbers">Block numbers to write (zero-based)</param>
/// <param name="block">Block data</param>
public void WriteFdsBlocks(byte blockNumber, IFdsBlock block)
- => WriteFdsBlocks(new byte[] { blockNumber }, block.ToBytes() );
+ => WriteFdsBlocks(new byte[] { blockNumber }, block.ToBytes());
/// <summary>
/// Read raw mirroring values (CIRAM A10 pin states for different states of PPU A10 and A11)
diff --git a/FamicomDumperConnection/FamicomDumperConnection.csproj b/FamicomDumperConnection/FamicomDumperConnection.csproj
index 91af4fb..1a0a526 100644
--- a/FamicomDumperConnection/FamicomDumperConnection.csproj
+++ b/FamicomDumperConnection/FamicomDumperConnection.csproj
@@ -1,64 +1,17 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+<Project Sdk="Microsoft.NET.Sdk">
+
<PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProjectGuid>{E9721416-3405-41A4-A1E4-12F91E02D36A}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
+ <TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>com.clusterrr.Famicom.DumperConnection</RootNamespace>
<AssemblyName>FamicomDumperConnection</AssemblyName>
- <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- <Deterministic>true</Deterministic>
</PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <UseVSHostingProcess>true</UseVSHostingProcess>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>none</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="System" />
- <Reference Include="System.Core" />
- <Reference Include="System.Management" />
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="Microsoft.CSharp" />
- <Reference Include="System.Data" />
- <Reference Include="System.Net.Http" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="FamicomDumperConnection.cs" />
- <Compile Include="FTD2XX_NET.cs" />
- <Compile Include="IFamicomDumperConnection.cs" />
- <Compile Include="Win32DeviceMgmt.cs" />
- </ItemGroup>
- <ItemGroup>
- <Folder Include="Properties\" />
- </ItemGroup>
+
<ItemGroup>
- <None Include="packages.config" />
+ <PackageReference Include="System.IO.Ports" Version="5.0.1" />
</ItemGroup>
+
<ItemGroup>
- <ProjectReference Include="..\NesContainers\NesContainers.csproj">
- <Project>{dbde5f39-ff67-496f-999f-65f86dcec1d5}</Project>
- <Name>NesContainers</Name>
- </ProjectReference>
+ <ProjectReference Include="..\NesContainers\NesContainers.csproj" />
</ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-</Project> \ No newline at end of file
+
+</Project>
diff --git a/FamicomDumperConnection/packages.config b/FamicomDumperConnection/packages.config
deleted file mode 100644
index b13d76e..0000000
--- a/FamicomDumperConnection/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
- <package id="System.Management" version="4.7.0" targetFramework="net48" />
-</packages> \ No newline at end of file