TS-50 IF and FA commands

This commit is contained in:
UzixLS
2016-05-02 15:24:29 +03:00
parent 2a72da6517
commit c995b5a3e8
10 changed files with 82 additions and 38 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
obj/
Release/
ReferencedDLLs/

8
README.md Normal file
View File

@ -0,0 +1,8 @@
# sdrsharp-catcontroller
This plugin allow SDR# to be controlled via serial (COM) interface with subset of TS-50 receiver commands.
Supported commands:
* IF - get frequency
* FA - set frequency
This plugin based on code by pewusoft (http://users.vline.pl/~pewusoft/)

View File

@ -1,5 +1,5 @@
<?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>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SDRSharp.SerialController</RootNamespace>
<AssemblyName>SDRSharp.SerialController</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NoWin32Manifest>False</NoWin32Manifest>
@ -63,7 +63,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>..\Release\</OutputPath>
<OutputPath>Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>True</Optimize>
<DebugType>PdbOnly</DebugType>
@ -82,6 +82,15 @@
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
</PropertyGroup>
<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.Core" />
<Reference Include="System.Drawing" />
@ -93,18 +102,10 @@
</ItemGroup>
<ItemGroup>
<Compile Include="SerialPort.cs" />
<Reference Include="SDRSharp.Common, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>../Common/SDRSharp.Common.dll</HintPath>
</Reference>
<!--<Reference Include="SDRSharp.PanView, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>../Common/SDRSharp.PanView.dll</HintPath>
</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">
<SubType>UserControl</SubType>
</Compile>

View File

@ -1,5 +1,5 @@
<?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>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>

View File

@ -1,7 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# 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}"
EndProject
Global

View File

@ -61,7 +61,7 @@
this.btnRefreshPorts.Image = ((System.Drawing.Image)(resources.GetObject("btnRefreshPorts.Image")));
this.btnRefreshPorts.Location = new System.Drawing.Point(188, 2);
this.btnRefreshPorts.Name = "btnRefreshPorts";
this.btnRefreshPorts.Size = new System.Drawing.Size(30, 23);
this.btnRefreshPorts.Size = new System.Drawing.Size(30, 30);
this.btnRefreshPorts.TabIndex = 3;
this.btnRefreshPorts.UseVisualStyleBackColor = true;
this.btnRefreshPorts.Click += new System.EventHandler(this.BtnRefreshPortsClick);
@ -89,8 +89,8 @@
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";
this.label1.Text = "Accept some TS-50 CAT commands via serial interface. " +
"Made by Uzix, 2016. Based on plugin by pewusoft, 2015";
//
// SerialControllerPanel
//

View File

@ -45,7 +45,11 @@ namespace SDRSharp.SerialController
}
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;
btnRefreshPorts.Enabled = !cbEnable.Checked;
cbLogToFile.Enabled = !cbEnable.Checked;

View File

@ -112,10 +112,10 @@
<value>2.0</value>
</resheader>
<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 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>
<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">

View File

@ -33,6 +33,7 @@ namespace SDRSharp.SerialController
_control = control;
_serialPort = new SerialPortCtrl();
_serialPort.OnFrequencyChange += UpdateFrequency;
_serialPort.OnGetFrequency += GetFrequency;
_controlPanel = new SerialControllerPanel(_serialPort);
_controlPanel.readSettings();
@ -41,7 +42,10 @@ namespace SDRSharp.SerialController
void UpdateFrequency(object sender, long freq) {
_control.Frequency = freq;
_controlPanel.addToLogList(freq.ToString("N0")+" Hz");
}
long GetFrequency() {
return _control.Frequency;
}
public void Close()

View File

@ -20,6 +20,9 @@ namespace SDRSharp.SerialController
set { this._enableLogging = value; }
get { return this._enableLogging; }
}
public bool IsOpen {
get { return _port != null && _port.IsOpen; }
}
StreamWriter logger;
SerialPort _port;
@ -27,28 +30,30 @@ namespace SDRSharp.SerialController
public delegate void FrequencyChangeHandler(object sender, long freq);
public event FrequencyChangeHandler OnFrequencyChange;
public delegate long GetFrequencyHandler();
public event GetFrequencyHandler OnGetFrequency;
public static string[] GetAllPorts()
{
try {
return SerialPort.GetPortNames();
} catch {
MessageBox.Show("Exception while getting available serial ports", "SerialController", MessageBoxButtons.OK, MessageBoxIcon.Error);
} catch (Exception e) {
MessageBox.Show("Cannot 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) {
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;
_port.DataReceived += new SerialDataReceivedEventHandler( Port_DataReceived );
if (_port != null) {
_port.Open();
@ -59,8 +64,9 @@ namespace SDRSharp.SerialController
return true;
}
return false;
} catch (Exception) {
MessageBox.Show("Couldn't open port "+portName, "SerialController", MessageBoxButtons.OK, MessageBoxIcon.Error);
} catch (Exception e) {
MessageBox.Show("Couldn't open port "+portName+":\n"+e.ToString(), "SerialController",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
@ -87,15 +93,33 @@ namespace SDRSharp.SerialController
void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (OnFrequencyChange == null) return;
string data = "";
while( data.IndexOf(';') < 0 ) {
byte[] bytes = new byte[_port.BytesToRead+32];
try {
_port.Read(bytes, 0, _port.BytesToRead);
}
catch (Exception) {
log("Error reading COM port");
return;
}
data += System.Text.Encoding.UTF8.GetString(bytes);
}
data = data.Substring(0, data.IndexOf(';'));
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)) {
// TS-50 command parse
if (data.StartsWith("IF", StringComparison.Ordinal)) {
long freq = OnGetFrequency();
string response = "IF";
response += String.Format("{0:00000000000}", freq);
response += "000000000000000000000000;";
_port.Write(response);
}
if (data.StartsWith("FA", StringComparison.Ordinal)) {
long freq;
if (long.TryParse(data.Substring("RF".Length), out freq)) {
if (long.TryParse(data.Substring(2), out freq)) {
log("Received on COM port: "+data);
if (OnFrequencyChange == null) return;
OnFrequencyChange(this, freq);
log("Changing frequency to: "+freq.ToString("N0"));
}