mirror of
https://github.com/UzixLS/sdrsharp-catcontroller.git
synced 2026-05-08 20:06:51 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11d6358712 | ||
|
|
40ba5cd3f8 | ||
|
|
e5aa75b7e6 | ||
|
|
21496719dd | ||
|
|
c995b5a3e8 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
obj/
|
obj/
|
||||||
|
Release/
|
||||||
|
ReferencedDLLs/
|
||||||
|
|||||||
@ -1,27 +1,25 @@
|
|||||||
using System.Reflection;
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
[assembly: AssemblyTitle("SerialController")]
|
[assembly: AssemblyTitle ("SerialController")]
|
||||||
[assembly: AssemblyDescription("Serial port controller for SDR#")]
|
[assembly: AssemblyDescription ("Serial port controller for SDR#")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration ("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany ("")]
|
||||||
[assembly: AssemblyProduct("SerialController")]
|
[assembly: AssemblyProduct ("SerialController")]
|
||||||
[assembly: AssemblyCopyright("Copyright © Pawel Walczak 2014")]
|
[assembly: AssemblyCopyright ("")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark ("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture ("")]
|
||||||
|
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
// to COM components. If you need to access a type in this assembly from
|
// to COM components. If you need to access a type in this assembly from
|
||||||
// COM, set the ComVisible attribute to true on that type.
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible (false)]
|
||||||
|
|
||||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
[assembly: Guid("a69bd5ae-f03a-4dcf-856d-4303bf64e2a3")]
|
[assembly: Guid ("a69bd5ae-f03a-4dcf-856d-4303bf64e2a3")]
|
||||||
|
|
||||||
// Version information for an assembly consists of the following four values:
|
// Version information for an assembly consists of the following four values:
|
||||||
//
|
//
|
||||||
// Major Version
|
// Major Version
|
||||||
@ -32,5 +30,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion ("1.0.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion ("1.0.0.0")]
|
||||||
|
|||||||
18
ProtocolInterface.cs
Normal file
18
ProtocolInterface.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Created by SharpDevelop.
|
||||||
|
* User: uzix
|
||||||
|
* Date: 04.01.2017
|
||||||
|
* Time: 16:02
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace SDRSharp.SerialController
|
||||||
|
{
|
||||||
|
public interface ProtocolInterface
|
||||||
|
{
|
||||||
|
string EndMarker { get; }
|
||||||
|
int MaxLen { get; }
|
||||||
|
string PktTransmitter(string ChangedProperty);
|
||||||
|
string PktReceiver(string ReveivedData);
|
||||||
|
}
|
||||||
|
}
|
||||||
123
Protocol_TS50.cs
Normal file
123
Protocol_TS50.cs
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* Created by SharpDevelop.
|
||||||
|
* User: uzix
|
||||||
|
* Date: 02.05.2016
|
||||||
|
* Time: 17:00
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using SDRSharp.Radio;
|
||||||
|
|
||||||
|
|
||||||
|
namespace SDRSharp.SerialController
|
||||||
|
{
|
||||||
|
public class Protocol_TS50 : ProtocolInterface
|
||||||
|
{
|
||||||
|
static readonly Dictionary<DetectorType, uint> mode2int = new Dictionary<DetectorType, uint> {
|
||||||
|
{DetectorType.NFM, 4},
|
||||||
|
{DetectorType.WFM, 4},
|
||||||
|
{DetectorType.AM, 5},
|
||||||
|
{DetectorType.DSB, 5},
|
||||||
|
{DetectorType.LSB, 1},
|
||||||
|
{DetectorType.USB, 2},
|
||||||
|
{DetectorType.CW, 3},
|
||||||
|
{DetectorType.RAW, 8}
|
||||||
|
};
|
||||||
|
static readonly Dictionary<uint, DetectorType> int2mode = new Dictionary<uint, DetectorType> {
|
||||||
|
{1, DetectorType.LSB},
|
||||||
|
{2, DetectorType.USB},
|
||||||
|
{3, DetectorType.CW},
|
||||||
|
{4, DetectorType.NFM},
|
||||||
|
{5, DetectorType.AM},
|
||||||
|
{8, DetectorType.RAW}
|
||||||
|
};
|
||||||
|
|
||||||
|
public string EndMarker { get { return ";"; } }
|
||||||
|
public int MaxLen { get { return 255; } }
|
||||||
|
|
||||||
|
SerialRadioInterface _radio;
|
||||||
|
bool _DetectorSetFailure;
|
||||||
|
|
||||||
|
|
||||||
|
public Protocol_TS50(SerialRadioInterface radio)
|
||||||
|
{
|
||||||
|
_radio = radio;
|
||||||
|
_DetectorSetFailure = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string PktTransmitter(string ChangedProperty)
|
||||||
|
{
|
||||||
|
string response = "";
|
||||||
|
switch (ChangedProperty)
|
||||||
|
{
|
||||||
|
case "Frequency":
|
||||||
|
response = "FA" + String.Format("{0:00000000000}", _radio.RadioFrequency) + ";";
|
||||||
|
break;
|
||||||
|
case "DetectorType":
|
||||||
|
response = "MD" + mode2int[_radio.RadioMode] + ";";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string PktReceiver(string ReceivedData)
|
||||||
|
{
|
||||||
|
string response = "";
|
||||||
|
if (ReceivedData.StartsWith("IF", StringComparison.Ordinal)) {
|
||||||
|
response += "IF";
|
||||||
|
response += String.Format("{0:00000000000}", _radio.RadioFrequency);
|
||||||
|
response += "0000000000000000";
|
||||||
|
if ( _DetectorSetFailure)
|
||||||
|
response += 0;
|
||||||
|
else
|
||||||
|
response += mode2int[_radio.RadioMode];
|
||||||
|
response += "0000000";
|
||||||
|
response += EndMarker;
|
||||||
|
}
|
||||||
|
else if (ReceivedData == "FA") {
|
||||||
|
response += "FA";
|
||||||
|
response += String.Format("{0:00000000000}", _radio.RadioFrequency);
|
||||||
|
response += EndMarker;
|
||||||
|
}
|
||||||
|
else if (ReceivedData.StartsWith("FA", StringComparison.Ordinal)) {
|
||||||
|
long freq;
|
||||||
|
if (long.TryParse(ReceivedData.Substring(2), out freq)) {
|
||||||
|
_radio.RadioFrequency = freq;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ReceivedData == "MD") {
|
||||||
|
response += "MD";
|
||||||
|
if (_DetectorSetFailure)
|
||||||
|
response += 0;
|
||||||
|
else
|
||||||
|
response += mode2int[_radio.RadioMode];
|
||||||
|
response += EndMarker;
|
||||||
|
}
|
||||||
|
else if (ReceivedData.StartsWith("MD", StringComparison.Ordinal)) {
|
||||||
|
uint mode;
|
||||||
|
if (uint.TryParse(ReceivedData.Substring(2), out mode)) {
|
||||||
|
try {
|
||||||
|
_radio.RadioMode = int2mode[mode];
|
||||||
|
_DetectorSetFailure = false;
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
_DetectorSetFailure = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ReceivedData == "ID") {
|
||||||
|
response += "ID";
|
||||||
|
response += "021"; //XXX: TS-590S value, idk what's should be there for TS-50
|
||||||
|
response += EndMarker;
|
||||||
|
}
|
||||||
|
else if (ReceivedData == "RX") {
|
||||||
|
response += "RX";
|
||||||
|
response += EndMarker;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
17
README.md
Normal file
17
README.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# sdrsharp-catcontroller
|
||||||
|
|
||||||
|
This plugin allow SDR# to be controlled via serial (COM) interface with set of TS-50 receiver commands.
|
||||||
|
E.g. it can be coupled with com0com virtual serial port and Fldigi for better convenience.
|
||||||
|
|
||||||
|
Supported commands:
|
||||||
|
* IF - get frequency and mode
|
||||||
|
* FA - set frequency
|
||||||
|
* MD - set mode (AM,FM,USB,LSB,CW)
|
||||||
|
|
||||||
|
Serial port parameters:
|
||||||
|
* Speed: 9600
|
||||||
|
* Data bits: 8
|
||||||
|
* Stop bits: 1
|
||||||
|
* Parity: none
|
||||||
|
|
||||||
|
This plugin based on code by pewusoft (http://users.vline.pl/~pewusoft/)
|
||||||
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
@ -10,7 +10,7 @@
|
|||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>SDRSharp.SerialController</RootNamespace>
|
<RootNamespace>SDRSharp.SerialController</RootNamespace>
|
||||||
<AssemblyName>SDRSharp.SerialController</AssemblyName>
|
<AssemblyName>SDRSharp.SerialController</AssemblyName>
|
||||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
<NoWin32Manifest>False</NoWin32Manifest>
|
<NoWin32Manifest>False</NoWin32Manifest>
|
||||||
@ -63,7 +63,7 @@
|
|||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||||
<OutputPath>..\Release\</OutputPath>
|
<OutputPath>Release\</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<Optimize>True</Optimize>
|
<Optimize>True</Optimize>
|
||||||
<DebugType>PdbOnly</DebugType>
|
<DebugType>PdbOnly</DebugType>
|
||||||
@ -82,6 +82,15 @@
|
|||||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.CSharp">
|
||||||
|
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="SDRSharp.Common">
|
||||||
|
<HintPath>ReferencedDLLs\SDRSharp.Common.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="SDRSharp.Radio">
|
||||||
|
<HintPath>ReferencedDLLs\SDRSharp.Radio.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
@ -92,19 +101,13 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="SerialPort.cs" />
|
<Compile Include="ProtocolInterface.cs" />
|
||||||
<Reference Include="SDRSharp.Common, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86">
|
<Compile Include="Protocol_TS50.cs" />
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<Compile Include="SerialPortCtrl.cs" />
|
||||||
<HintPath>../Common/SDRSharp.Common.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<!--<Reference Include="SDRSharp.PanView, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86">
|
<!--<Reference Include="SDRSharp.PanView, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>../Common/SDRSharp.PanView.dll</HintPath>
|
<HintPath>../Common/SDRSharp.PanView.dll</HintPath>
|
||||||
</Reference>-->
|
</Reference>-->
|
||||||
<Reference Include="SDRSharp.Radio, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>../Common/SDRSharp.Radio.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Compile Include="SerialControllerPanel.cs">
|
<Compile Include="SerialControllerPanel.cs">
|
||||||
<SubType>UserControl</SubType>
|
<SubType>UserControl</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
@ -113,6 +116,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="SerialControllerPlugin.cs" />
|
<Compile Include="SerialControllerPlugin.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="SerialRadioInterface.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="SerialControllerPanel.resx">
|
<EmbeddedResource Include="SerialControllerPanel.resx">
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ProjectView>ProjectFiles</ProjectView>
|
<ProjectView>ProjectFiles</ProjectView>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 2008
|
# Visual Studio 2012
|
||||||
# SharpDevelop 5.1
|
# SharpDevelop 5.1
|
||||||
|
VisualStudioVersion = 12.0.20827.3
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDRSharp.SerialController", "SDRSharp.SerialController.csproj", "{41C6CC2E-5F1D-4BFC-9676-381AD488FCD6}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDRSharp.SerialController", "SDRSharp.SerialController.csproj", "{41C6CC2E-5F1D-4BFC-9676-381AD488FCD6}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
|
|||||||
32
SerialControllerPanel.Designer.cs
generated
32
SerialControllerPanel.Designer.cs
generated
@ -32,9 +32,7 @@
|
|||||||
this.cbEnable = new System.Windows.Forms.CheckBox();
|
this.cbEnable = new System.Windows.Forms.CheckBox();
|
||||||
this.comboPorts = new System.Windows.Forms.ComboBox();
|
this.comboPorts = new System.Windows.Forms.ComboBox();
|
||||||
this.btnRefreshPorts = new System.Windows.Forms.Button();
|
this.btnRefreshPorts = new System.Windows.Forms.Button();
|
||||||
this.cbLogToFile = new System.Windows.Forms.CheckBox();
|
|
||||||
this.lbLog = new System.Windows.Forms.ListBox();
|
this.lbLog = new System.Windows.Forms.ListBox();
|
||||||
this.label1 = new System.Windows.Forms.Label();
|
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// cbEnable
|
// cbEnable
|
||||||
@ -61,47 +59,27 @@
|
|||||||
this.btnRefreshPorts.Image = ((System.Drawing.Image)(resources.GetObject("btnRefreshPorts.Image")));
|
this.btnRefreshPorts.Image = ((System.Drawing.Image)(resources.GetObject("btnRefreshPorts.Image")));
|
||||||
this.btnRefreshPorts.Location = new System.Drawing.Point(188, 2);
|
this.btnRefreshPorts.Location = new System.Drawing.Point(188, 2);
|
||||||
this.btnRefreshPorts.Name = "btnRefreshPorts";
|
this.btnRefreshPorts.Name = "btnRefreshPorts";
|
||||||
this.btnRefreshPorts.Size = new System.Drawing.Size(30, 23);
|
this.btnRefreshPorts.Size = new System.Drawing.Size(24, 24);
|
||||||
this.btnRefreshPorts.TabIndex = 3;
|
this.btnRefreshPorts.TabIndex = 3;
|
||||||
this.btnRefreshPorts.UseVisualStyleBackColor = true;
|
this.btnRefreshPorts.UseVisualStyleBackColor = true;
|
||||||
this.btnRefreshPorts.Click += new System.EventHandler(this.BtnRefreshPortsClick);
|
this.btnRefreshPorts.Click += new System.EventHandler(this.BtnRefreshPortsClick);
|
||||||
//
|
//
|
||||||
// cbLogToFile
|
|
||||||
//
|
|
||||||
this.cbLogToFile.Location = new System.Drawing.Point(3, 30);
|
|
||||||
this.cbLogToFile.Name = "cbLogToFile";
|
|
||||||
this.cbLogToFile.Size = new System.Drawing.Size(104, 24);
|
|
||||||
this.cbLogToFile.TabIndex = 4;
|
|
||||||
this.cbLogToFile.Text = "Log to file";
|
|
||||||
this.cbLogToFile.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// lbLog
|
// lbLog
|
||||||
//
|
//
|
||||||
this.lbLog.FormattingEnabled = true;
|
this.lbLog.FormattingEnabled = true;
|
||||||
this.lbLog.Location = new System.Drawing.Point(3, 60);
|
this.lbLog.Location = new System.Drawing.Point(3, 30);
|
||||||
this.lbLog.Name = "lbLog";
|
this.lbLog.Name = "lbLog";
|
||||||
this.lbLog.Size = new System.Drawing.Size(215, 69);
|
this.lbLog.Size = new System.Drawing.Size(215, 69);
|
||||||
this.lbLog.TabIndex = 5;
|
this.lbLog.TabIndex = 4;
|
||||||
//
|
|
||||||
// label1
|
|
||||||
//
|
|
||||||
this.label1.Location = new System.Drawing.Point(3, 132);
|
|
||||||
this.label1.Name = "label1";
|
|
||||||
this.label1.Size = new System.Drawing.Size(215, 46);
|
|
||||||
this.label1.TabIndex = 6;
|
|
||||||
this.label1.Text = "This plugin receives AR ONE commands from UniTrunker and sets frequency according" +
|
|
||||||
"ly. Made by pewusoft, 2015";
|
|
||||||
//
|
//
|
||||||
// SerialControllerPanel
|
// SerialControllerPanel
|
||||||
//
|
//
|
||||||
this.Controls.Add(this.label1);
|
|
||||||
this.Controls.Add(this.lbLog);
|
this.Controls.Add(this.lbLog);
|
||||||
this.Controls.Add(this.cbLogToFile);
|
|
||||||
this.Controls.Add(this.btnRefreshPorts);
|
this.Controls.Add(this.btnRefreshPorts);
|
||||||
this.Controls.Add(this.comboPorts);
|
this.Controls.Add(this.comboPorts);
|
||||||
this.Controls.Add(this.cbEnable);
|
this.Controls.Add(this.cbEnable);
|
||||||
this.Name = "SerialControllerPanel";
|
this.Name = "SerialControllerPanel";
|
||||||
this.Size = new System.Drawing.Size(222, 201);
|
this.Size = new System.Drawing.Size(222, 131);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -111,9 +89,7 @@
|
|||||||
private System.Windows.Forms.CheckBox cbEnable;
|
private System.Windows.Forms.CheckBox cbEnable;
|
||||||
private System.Windows.Forms.ComboBox comboPorts;
|
private System.Windows.Forms.ComboBox comboPorts;
|
||||||
private System.Windows.Forms.Button btnRefreshPorts;
|
private System.Windows.Forms.Button btnRefreshPorts;
|
||||||
private System.Windows.Forms.CheckBox cbLogToFile;
|
|
||||||
private System.Windows.Forms.ListBox lbLog;
|
private System.Windows.Forms.ListBox lbLog;
|
||||||
private System.Windows.Forms.Label label1;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ using System.Windows.Forms;
|
|||||||
|
|
||||||
using SDRSharp.Radio;
|
using SDRSharp.Radio;
|
||||||
|
|
||||||
|
|
||||||
namespace SDRSharp.SerialController
|
namespace SDRSharp.SerialController
|
||||||
{
|
{
|
||||||
public partial class SerialControllerPanel : UserControl
|
public partial class SerialControllerPanel : UserControl
|
||||||
@ -25,7 +26,7 @@ namespace SDRSharp.SerialController
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addToLogList(String log) {
|
public void addToLogList(String log) {
|
||||||
lbLog.Items.Add(log);
|
lbLog.Items.Add(DateTime.Now.ToString("[HH:mm:ss] ") + log);
|
||||||
// scroll to bottom
|
// scroll to bottom
|
||||||
lbLog.SelectedIndex = lbLog.Items.Count - 1;
|
lbLog.SelectedIndex = lbLog.Items.Count - 1;
|
||||||
lbLog.SelectedIndex = -1;
|
lbLog.SelectedIndex = -1;
|
||||||
@ -33,23 +34,23 @@ namespace SDRSharp.SerialController
|
|||||||
|
|
||||||
public void readSettings() {
|
public void readSettings() {
|
||||||
comboPorts.Text = Utils.GetStringSetting("serialControlComPort", "");
|
comboPorts.Text = Utils.GetStringSetting("serialControlComPort", "");
|
||||||
cbLogToFile.Checked = Utils.GetBooleanSetting("serialControlLogToFile");
|
|
||||||
cbEnable.Checked = Utils.GetBooleanSetting("serialControlEnable");
|
cbEnable.Checked = Utils.GetBooleanSetting("serialControlEnable");
|
||||||
CbEnableClick(null,null);
|
CbEnableClick(null,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveSettings() {
|
public void saveSettings() {
|
||||||
Utils.SaveSetting("serialControlComPort", comboPorts.Text);
|
Utils.SaveSetting("serialControlComPort", comboPorts.Text);
|
||||||
Utils.SaveSetting("serialControlLogToFile", cbLogToFile.Checked);
|
|
||||||
Utils.SaveSetting("serialControlEnable", cbEnable.Checked);
|
Utils.SaveSetting("serialControlEnable", cbEnable.Checked);
|
||||||
}
|
}
|
||||||
void CbEnableClick(object sender, EventArgs e)
|
void CbEnableClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
cbEnable.Checked = cbEnable.Checked ? _serialPort.openPort(comboPorts.Text) : _serialPort.closePort();
|
if (! _serialPort.IsOpen)
|
||||||
|
_serialPort.openPort(comboPorts.Text);
|
||||||
|
else
|
||||||
|
_serialPort.closePort();
|
||||||
|
cbEnable.Checked = _serialPort.IsOpen;
|
||||||
comboPorts.Enabled = !cbEnable.Checked;
|
comboPorts.Enabled = !cbEnable.Checked;
|
||||||
btnRefreshPorts.Enabled = !cbEnable.Checked;
|
btnRefreshPorts.Enabled = !cbEnable.Checked;
|
||||||
cbLogToFile.Enabled = !cbEnable.Checked;
|
|
||||||
_serialPort.EnableLogging = cbLogToFile.Checked;
|
|
||||||
}
|
}
|
||||||
void CbEnableKeyDown(object sender, EventArgs e)
|
void CbEnableKeyDown(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -112,10 +112,10 @@
|
|||||||
<value>2.0</value>
|
<value>2.0</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<resheader name="reader">
|
<resheader name="reader">
|
||||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||||
<data name="btnRefreshPorts.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="btnRefreshPorts.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
|||||||
@ -1,17 +1,25 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using SDRSharp.Common;
|
using SDRSharp.Common;
|
||||||
|
using SDRSharp.Radio;
|
||||||
|
|
||||||
|
|
||||||
namespace SDRSharp.SerialController
|
namespace SDRSharp.SerialController
|
||||||
{
|
{
|
||||||
public class SerialControllerPlugin: ISharpPlugin
|
public class SerialControllerPlugin: ISharpPlugin,SerialRadioInterface
|
||||||
{
|
{
|
||||||
private const string _displayName = "SerialController";
|
private const string _displayName = "SerialController";
|
||||||
|
|
||||||
|
private ISharpControl _control;
|
||||||
private SerialControllerPanel _controlPanel;
|
private SerialControllerPanel _controlPanel;
|
||||||
private SerialPortCtrl _serialPort;
|
private SerialPortCtrl _serialPort;
|
||||||
private ISharpControl _control;
|
private ProtocolInterface _Protocol;
|
||||||
|
|
||||||
|
long _LastRadioFrequency;
|
||||||
|
DetectorType _LastRadioMode;
|
||||||
|
|
||||||
|
|
||||||
public string DisplayName
|
public string DisplayName
|
||||||
{
|
{
|
||||||
@ -31,23 +39,66 @@ namespace SDRSharp.SerialController
|
|||||||
public void Initialize(ISharpControl control)
|
public void Initialize(ISharpControl control)
|
||||||
{
|
{
|
||||||
_control = control;
|
_control = control;
|
||||||
_serialPort = new SerialPortCtrl();
|
_control.PropertyChanged += PropertyChangedHandler;
|
||||||
_serialPort.OnFrequencyChange += UpdateFrequency;
|
_LastRadioFrequency = _control.Frequency;
|
||||||
|
_LastRadioMode = _control.DetectorType;
|
||||||
|
_Protocol = new Protocol_TS50(this);
|
||||||
|
_serialPort = new SerialPortCtrl(_Protocol);
|
||||||
_controlPanel = new SerialControllerPanel(_serialPort);
|
_controlPanel = new SerialControllerPanel(_serialPort);
|
||||||
_controlPanel.readSettings();
|
_controlPanel.readSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateFrequency(object sender, long freq) {
|
|
||||||
_control.Frequency = freq;
|
|
||||||
_controlPanel.addToLogList(freq.ToString("N0")+" Hz");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
{
|
{
|
||||||
_serialPort.closePort();
|
_serialPort.closePort();
|
||||||
_controlPanel.saveSettings();
|
_controlPanel.saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PropertyChangedHandler(object sender, PropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
switch (e.PropertyName)
|
||||||
|
{
|
||||||
|
case "Frequency":
|
||||||
|
if (_LastRadioFrequency == _control.Frequency)
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
case "DetectorType":
|
||||||
|
if( _LastRadioMode == _control.DetectorType)
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (_serialPort.IsOpen)
|
||||||
|
{
|
||||||
|
string response = _Protocol.PktTransmitter(e.PropertyName);
|
||||||
|
if (! string.IsNullOrEmpty(response))
|
||||||
|
_serialPort.DataTransmit(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long RadioFrequency
|
||||||
|
{
|
||||||
|
get {
|
||||||
|
return _control.Frequency;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
_LastRadioFrequency = value;
|
||||||
|
_controlPanel.addToLogList(value.ToString("N0")+" Hz");
|
||||||
|
_control.Frequency = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DetectorType RadioMode
|
||||||
|
{
|
||||||
|
get {
|
||||||
|
return _control.DetectorType;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
_LastRadioMode = value;
|
||||||
|
_controlPanel.addToLogList(value.ToString());
|
||||||
|
_control.DetectorType = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
138
SerialPort.cs
138
SerialPort.cs
@ -1,138 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Pawel Walczak (pewusoft)
|
|
||||||
* Date: 2015-01-12 20:50
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
using System;
|
|
||||||
using System.IO.Ports;
|
|
||||||
using System.IO;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace SDRSharp.SerialController
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Description of SerialPort.
|
|
||||||
/// </summary>
|
|
||||||
public class SerialPortCtrl
|
|
||||||
{
|
|
||||||
bool _enableLogging = true;
|
|
||||||
public bool EnableLogging {
|
|
||||||
set { this._enableLogging = value; }
|
|
||||||
get { return this._enableLogging; }
|
|
||||||
}
|
|
||||||
|
|
||||||
StreamWriter logger;
|
|
||||||
SerialPort _port;
|
|
||||||
|
|
||||||
public delegate void FrequencyChangeHandler(object sender, long freq);
|
|
||||||
public event FrequencyChangeHandler OnFrequencyChange;
|
|
||||||
|
|
||||||
public static string[] GetAllPorts()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return SerialPort.GetPortNames();
|
|
||||||
} catch {
|
|
||||||
MessageBox.Show("Exception while getting available serial ports", "SerialController", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return new string[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool openPort(string portName) {
|
|
||||||
try {
|
|
||||||
if (_port != null && _port.IsOpen) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (portName == null || (portName.Trim().Equals("")))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
_port = new SerialPort(portName, 9600, Parity.None, 8, StopBits.One);
|
|
||||||
_port.DataReceived += Port_DataReceived;
|
|
||||||
|
|
||||||
|
|
||||||
if (_port != null) {
|
|
||||||
_port.Open();
|
|
||||||
if (_enableLogging) {
|
|
||||||
prepareLogger();
|
|
||||||
log("Port " + _port.PortName + " opened");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} catch (Exception) {
|
|
||||||
MessageBox.Show("Couldn't open port "+portName, "SerialController", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool closePort() {
|
|
||||||
if (_port != null) {
|
|
||||||
if (_port.IsOpen) {
|
|
||||||
try {
|
|
||||||
_port.Close();
|
|
||||||
if (_enableLogging) {
|
|
||||||
log("Port " + _port.PortName + " closed");
|
|
||||||
closeLogger();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (IOException) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
|
|
||||||
{
|
|
||||||
if (OnFrequencyChange == null) return;
|
|
||||||
|
|
||||||
string data = _port.ReadLine();
|
|
||||||
// log commands to file
|
|
||||||
log("Received on COM port: "+data);
|
|
||||||
// AR-ONE RF command parse, as simple as can be, but faster than regex
|
|
||||||
if (data.StartsWith("RF", StringComparison.Ordinal)) {
|
|
||||||
long freq;
|
|
||||||
if (long.TryParse(data.Substring("RF".Length), out freq)) {
|
|
||||||
OnFrequencyChange(this, freq);
|
|
||||||
log("Changing frequency to: "+freq.ToString("N0"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void log(String str) {
|
|
||||||
if (logger!=null) {
|
|
||||||
logger.WriteLine("[" + DateTime.Now + "]: " + str.Trim());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void prepareLogger() {
|
|
||||||
try {
|
|
||||||
if (logger != null) {
|
|
||||||
logger.Close();
|
|
||||||
}
|
|
||||||
logger = new StreamWriter(new FileStream("serial.log",
|
|
||||||
FileMode.Append,
|
|
||||||
FileAccess.Write,
|
|
||||||
FileShare.ReadWrite,
|
|
||||||
1024,
|
|
||||||
FileOptions.WriteThrough));
|
|
||||||
logger.AutoFlush = true;
|
|
||||||
} catch (Exception) {
|
|
||||||
logger = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void closeLogger() {
|
|
||||||
try {
|
|
||||||
if (logger != null) {
|
|
||||||
logger.Close();
|
|
||||||
}
|
|
||||||
logger = null;
|
|
||||||
} catch (Exception) {
|
|
||||||
logger = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
110
SerialPortCtrl.cs
Normal file
110
SerialPortCtrl.cs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* Author: Pawel Walczak (pewusoft)
|
||||||
|
* Date: 2015-01-12 20:50
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.IO.Ports;
|
||||||
|
using System.IO;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
|
||||||
|
namespace SDRSharp.SerialController
|
||||||
|
{
|
||||||
|
public class SerialPortCtrl
|
||||||
|
{
|
||||||
|
public bool IsOpen {
|
||||||
|
get { return _port != null && _port.IsOpen; }
|
||||||
|
}
|
||||||
|
|
||||||
|
SerialPort _port;
|
||||||
|
ProtocolInterface _protocol;
|
||||||
|
string _received;
|
||||||
|
|
||||||
|
public SerialPortCtrl(ProtocolInterface protocol)
|
||||||
|
{
|
||||||
|
_protocol = protocol;
|
||||||
|
_received = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string[] GetAllPorts()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return SerialPort.GetPortNames();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
MessageBox.Show("Couldn't read port list:\n"+e.ToString(), "SerialController", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return new string[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool openPort(string portName)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (_port != null && _port.IsOpen)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (portName == null || (portName.Trim().Equals("")))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_port = new SerialPort(portName, 9600, Parity.None, 8, StopBits.One);
|
||||||
|
_port.DataReceived += new SerialDataReceivedEventHandler( DataReceivedHandler );
|
||||||
|
|
||||||
|
if (_port != null) {
|
||||||
|
_port.Open();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
MessageBox.Show("Couldn't open port "+portName+":\n"+e.ToString(), "SerialController",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool closePort()
|
||||||
|
{
|
||||||
|
if (_port != null) {
|
||||||
|
if (_port.IsOpen) {
|
||||||
|
try {
|
||||||
|
_port.Close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (IOException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
|
||||||
|
{
|
||||||
|
while (_port.BytesToRead > 0) {
|
||||||
|
if (_received.Length > _protocol.MaxLen)
|
||||||
|
_received = "";
|
||||||
|
|
||||||
|
string input = ((char)_port.ReadChar()).ToString();
|
||||||
|
if (input == _protocol.EndMarker) {
|
||||||
|
string response = _protocol.PktReceiver(_received);
|
||||||
|
if (! string.IsNullOrEmpty(response)) {
|
||||||
|
DataTransmit(response);
|
||||||
|
}
|
||||||
|
_received = "";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_received += input;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DataTransmit(string data)
|
||||||
|
{
|
||||||
|
_port.Write(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
SerialRadioInterface.cs
Normal file
19
SerialRadioInterface.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Created by SharpDevelop.
|
||||||
|
* User: uzix
|
||||||
|
* Date: 04.01.2017
|
||||||
|
* Time: 16:46
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
|
||||||
|
using SDRSharp.Radio;
|
||||||
|
|
||||||
|
|
||||||
|
namespace SDRSharp.SerialController
|
||||||
|
{
|
||||||
|
public interface SerialRadioInterface
|
||||||
|
{
|
||||||
|
long RadioFrequency { get; set; }
|
||||||
|
DetectorType RadioMode { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user