diff --git a/PCR1000.Network/PCR1000.Network.csproj b/PCR1000.Network/PCR1000.Network.csproj
new file mode 100644
index 0000000..8ecd312
--- /dev/null
+++ b/PCR1000.Network/PCR1000.Network.csproj
@@ -0,0 +1,62 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {C4792356-055E-4181-9ECE-EC75FB04FDA0}
+ Library
+ Properties
+ PCR1000.Network
+ PCR1000.Network
+ v4.6
+ 512
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {29487920-2926-48b7-bd8c-b2761696663b}
+ PCR1000
+
+
+
+
+
\ No newline at end of file
diff --git a/PCR1000/PcrNetworkComm.cs b/PCR1000.Network/PcrNetworkComm.cs
similarity index 62%
rename from PCR1000/PcrNetworkComm.cs
rename to PCR1000.Network/PcrNetworkComm.cs
index 87e92ba..95f9f06 100644
--- a/PCR1000/PcrNetworkComm.cs
+++ b/PCR1000.Network/PcrNetworkComm.cs
@@ -16,263 +16,11 @@
using System.IO;
using System.Net.Security;
using System.Net.Sockets;
-using System.Security.Authentication;
using System.Text;
using System.Threading;
-namespace PCR1000
+namespace PCR1000.Network
{
- /*public class PcrNetworkClientComm : IComm
- {
- private string server;
- private int port;
- private bool ssl;
- private string password;
- private TcpClient _tcpClient;
- private Stream _tcpStream;
- private Thread _listenThread;
- private bool isAuthenticated;
-
- private void ListenThread()
- {
-
- while (isAuthenticated)
- {
- _tcpStream.Length;
-
- _tcpStream.Read()
- _tcpStream.Flush();
- }
- }
-
- public PcrNetworkClientComm(string server, int port = 4456, bool ssl = false, string password = "")
- {
- this.server = server;
- this.port = port;
- this.ssl = ssl;
- this.password = password;
-
- if (string.IsNullOrWhiteSpace(password))
- {
- isAuthenticated = true;
- }
- }
-
- public bool PcrOpen()
- {
- try
- {
- _tcpClient = new TcpClient();
- _tcpClient.Connect(server, port);
- _tcpStream = ssl
- ? (Stream) new SslStream(_tcpClient.GetStream())
- : _tcpClient.GetStream();
-
- _listenThread = new Thread(ListenThread);
- _listenThread.Start();
-
- if (!isAuthenticated)
- {
- var str = SendWait("" + password + "");
- if (str != "pass")
- {
- _listenThread.Abort();
- throw new AuthenticationException("Not Authorised");
- }
- isAuthenticated = true;
- }
- }
- catch (Exception)
- {
- return false;
- }
- return true;
- }
-
- public bool PcrClose()
- {
- _listenThread.Abort();
- return true;
- }
-
- public void Dispose()
- {
- Debug.WriteLine("PcrComm Dispose");
- PcrClose();
- }
-
- public event AutoUpdateDataRecv DataReceived;
- public bool AutoUpdate { get; set; }
- public object GetRawPort()
- {
- return _tcpClient;
- }
-
-#if DEBUG
- ///
- /// Keeps track of wheather debug logging is enabled.
- ///
- private bool _debugLogger;
-
- ///
- /// Enables or disables debug logging in the comminication library.
- ///
- /// Enable or disable.
- public void SetDebugLogger(bool debug)
- {
- Debug.WriteLine("PcrComm Debug Logging: " + debug);
- _debugLogger = debug;
- }
-#endif
-
- public bool Send(string cmd)
- {
- try
- {
- _tcpStream.WriteAsync(Encoding.ASCII.GetBytes(cmd), 0, cmd.Length);
- }
- catch (Exception)
- {
- return false;
- }
- return true;
- }
-
- ///
- /// Number of 50ms timeouts to wait before aborting in SendWait.
- ///
- private const int RecvTimeout = 20;
-
- ///
- /// Sends a message to the PCR1000 and waits for a reply.
- ///
- /// The command to send.
- /// When in autoupdate mode behaves like Send()
- /// this overrides that behaviour.
- /// The reply or "" if nothing is received.
- public string SendWait(string cmd, bool overrideAutoupdate = false)
- {
- Debug.WriteLine("PcrComm SendWait");
- Send(cmd);
- if (AutoUpdate && !overrideAutoupdate) return "";
- var dt = DateTime.Now;
- for (var i = 0; i < RecvTimeout; i++)
- {
- if (dt < _msgSlot1.Time)
- {
- return dt < _msgSlot2.Time ? _msgSlot2.Message : _msgSlot1.Message;
- }
- Thread.Sleep(50);
- }
- return "";
- }
-
- ///
- /// Received message structure.
- ///
- private struct RecvMsg
- {
- ///
- /// The message received.
- ///
- public string Message;
-
- ///
- /// The time the message was received.
- ///
- public DateTime Time;
- }
-
- ///
- /// Last two received messages.
- ///
- private RecvMsg _msgSlot1, _msgSlot2;
-
- ///
- /// Gets the latest message from the PCR1000.
- ///
- /// The latest message.
- public string GetLastReceived()
- {
- Debug.WriteLine("PcrComm Last Recv");
- try
- {
- return _msgSlot1.Message;
- }
- catch (Exception)
- {
- return "";
- }
- }
-
- ///
- /// Gets the previously received message.
- ///
- /// The previous message.
- public string GetPrevReceived()
- {
- Debug.WriteLine("PcrComm PrevRecv");
- try
- {
- return _msgSlot2.Message;
- }
- catch (Exception)
- {
- return "";
- }
- }
- }*/
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
///
/// Client to connect to a remote radio.
///
@@ -380,22 +128,29 @@ public PcrNetworkClient(string server, int port = 4456, bool ssl = false, string
_ssl = ssl;
}
+ ///
+ /// Disposes of the PcrNetworkClient
+ ///
public void Dispose()
{
+ if (!_tcpClient.Connected) return;
+ _tcpListen.Abort();
+ _tcpListen.Join();
+ _tcpClient.Close();
}
///
- ///
+ /// Data was received from the remote radio.
///
public event AutoUpdateDataRecv DataReceived;
///
- ///
+ /// The remote radio should auto-update.
///
public bool AutoUpdate { get; set; }
///
- ///
+ /// Gets the underlying system port of the radio.
///
- ///
+ /// The network port connected to the remote radio.
public object GetRawPort()
{
return _tcpClient;
diff --git a/PCR1000/PcrNetworkServer.cs b/PCR1000.Network/PcrNetworkServer.cs
similarity index 99%
rename from PCR1000/PcrNetworkServer.cs
rename to PCR1000.Network/PcrNetworkServer.cs
index 8705fbb..2914b18 100644
--- a/PCR1000/PcrNetworkServer.cs
+++ b/PCR1000.Network/PcrNetworkServer.cs
@@ -7,7 +7,7 @@
using System.Text;
using System.Threading;
-namespace PCR1000
+namespace PCR1000.Network
{
///
/// Server class to manage remote connections.
diff --git a/PCR1000.Network/Properties/AssemblyInfo.cs b/PCR1000.Network/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..4570d91
--- /dev/null
+++ b/PCR1000.Network/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("PCR1000.Network")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("PCR1000.Network")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 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
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("c4792356-055e-4181-9ece-ec75fb04fda0")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/PCR1000.sln b/PCR1000.sln
index 5ed7300..46ccd0b 100644
--- a/PCR1000.sln
+++ b/PCR1000.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.21005.1
+# Visual Studio 14
+VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCR1000LibTest", "PCR1000LibTest\PCR1000LibTest.csproj", "{CFA2F945-2D45-4699-90BE-D42D9F738BE0}"
ProjectSection(ProjectDependencies) = postProject
@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCRNetworkServer", "PCRNetw
{29487920-2926-48B7-BD8C-B2761696663B} = {29487920-2926-48B7-BD8C-B2761696663B}
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCR1000.Network", "PCR1000.Network\PCR1000.Network.csproj", "{C4792356-055E-4181-9ECE-EC75FB04FDA0}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -33,6 +35,10 @@ Global
{8020673D-A3BA-4EE2-BC61-2B5A02385EBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8020673D-A3BA-4EE2-BC61-2B5A02385EBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8020673D-A3BA-4EE2-BC61-2B5A02385EBA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C4792356-055E-4181-9ECE-EC75FB04FDA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C4792356-055E-4181-9ECE-EC75FB04FDA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C4792356-055E-4181-9ECE-EC75FB04FDA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C4792356-055E-4181-9ECE-EC75FB04FDA0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/PCR1000/PCR1000.csproj b/PCR1000/PCR1000.csproj
index ad28f35..0dcf9c2 100644
--- a/PCR1000/PCR1000.csproj
+++ b/PCR1000/PCR1000.csproj
@@ -9,8 +9,9 @@
Properties
PCR1000
PCR1000
- v4.5
+ v4.6
512
+
true
@@ -37,13 +38,14 @@
-
-
+
+
+
diff --git a/PCR1000/PcrSerialComm.cs b/PCR1000/PcrSerialComm.cs
index c0288fb..531f49f 100644
--- a/PCR1000/PcrSerialComm.cs
+++ b/PCR1000/PcrSerialComm.cs
@@ -14,7 +14,9 @@
using System;
using System.Diagnostics;
using System.IO.Ports;
+using System.Linq;
using System.Threading;
+using PCR1000.SerialPorts;
namespace PCR1000
{
@@ -31,7 +33,7 @@ public class PcrSerialComm : IComm
///
/// The serial port of the PCR1000.
///
- private readonly SerialPort _serialPort;
+ private readonly PcrSerialPort _serialPort;
///
/// Gets and sets autoupdate mode.
@@ -72,12 +74,31 @@ private struct RecvMsg
///
/// Instantiate a new PcrComm object to communicate with the PCR1000.
///
- /// COM Port to communicate on. Defaults to COM1
+ /// COM Port to communicate on. Defaults to first COM device.
/// Baud rate to use. Defaults to 9600.
- public PcrSerialComm(string port = "COM1", int baud = 9600)
+ public PcrSerialComm(string port = null, int baud = 9600)
{
Debug.WriteLine("PcrComm Being Created");
- _serialPort = new SerialPort(port, baud, Parity.None, 8, StopBits.One);
+ var portNames = SerialPort.GetPortNames();
+ if (string.IsNullOrWhiteSpace(port))
+ {
+ if (portNames.Length == 0)
+ {
+ Debug.WriteLine("PcrComm Error: No port provided and no ports avalible.");
+ throw new InvalidOperationException("Cannot open serial port when there are none.");
+ }
+ port = portNames[0];
+ }
+
+ if (!portNames.Contains(port))
+ {
+ Debug.WriteLine("PcrComm Error: the serial port provided does not exist.");
+ throw new ArgumentException("Serial port provided does not exist.", nameof(port));
+ }
+
+ _serialPort = IsRunningOnMono()
+ ? (PcrSerialPort) new MonoSerialPort(port, baud, Parity.None, 8, StopBits.One)
+ : new MsSerialPort(port, baud, Parity.None, 8, StopBits.One);
_serialPort.DataReceived += SerialPortDataReceived;
_serialPort.DtrEnable = true;
_serialPort.Handshake = Handshake.RequestToSend;
@@ -281,11 +302,27 @@ public bool PcrClose()
}
}
+ ///
+ /// Dispose of the seial communications port.
+ ///
public void Dispose()
{
Debug.WriteLine("PcrComm Dispose");
PcrClose();
_serialPort.Dispose();
}
+
+ #region Mono
+ /*
+ Deal with mono specfic hacks here, to make it compatible with the
+ implementation it should have been.
+ */
+
+ private static bool IsRunningOnMono()
+ {
+ return Type.GetType("Mono.Runtime") != null;
+ }
+
+ #endregion
}
}
diff --git a/PCR1000/SerialPorts/MonoSerialPort.cs b/PCR1000/SerialPorts/MonoSerialPort.cs
new file mode 100644
index 0000000..87c3037
--- /dev/null
+++ b/PCR1000/SerialPorts/MonoSerialPort.cs
@@ -0,0 +1,109 @@
+using System;
+using System.IO.Ports;
+using System.IO;
+using System.Runtime.InteropServices;
+using System.Reflection;
+using System.Threading;
+// ReSharper disable PossibleNullReferenceException
+#pragma warning disable 1591
+
+namespace PCR1000.SerialPorts
+{
+ public class MonoSerialPort : PcrSerialPort
+ {
+ private int _fd;
+ private FieldInfo _disposedFieldInfo;
+ private Thread _listenThread;
+
+ public MonoSerialPort(string port, int baud, Parity parity, int dataBits, StopBits stopBits)
+ : base(port, baud, parity, dataBits, stopBits)
+ {
+ SerialPort.ReadTimeout = 100;
+ }
+
+ public override void Dispose()
+ {
+ if (_listenThread != null && _listenThread.IsAlive)
+ {
+ _listenThread.Abort();
+ _listenThread.Join();
+ }
+ SerialPort.Dispose();
+ }
+
+ public override void Open()
+ {
+ SerialPort.Open();
+
+ var fieldInfo = SerialPort.BaseStream.GetType().GetField("_fd", BindingFlags.Instance | BindingFlags.NonPublic);
+ _fd = (int) fieldInfo.GetValue(SerialPort.BaseStream);
+ _disposedFieldInfo = SerialPort.BaseStream.GetType().GetField("disposed", BindingFlags.Instance | BindingFlags.NonPublic);
+
+ _listenThread = new Thread(EventThreadFunction);
+ _listenThread.Start();
+ }
+
+ private void EventThreadFunction()
+ {
+ do
+ {
+ try
+ {
+ var stream = SerialPort.BaseStream;
+ if (stream == null)
+ {
+ return;
+ }
+
+ if (Poll(stream))
+ {
+ SerialPortDataReceived(SerialPort, null);
+ }
+ }
+ catch
+ {
+ return;
+ }
+ }
+ while (IsOpen);
+ }
+
+ [DllImport("MonoPosixHelper", SetLastError = true)]
+ private static extern bool poll_serial(int fd, out int error, int timeout);
+
+ private bool Poll(Stream stream)
+ {
+ CheckDisposed(stream);
+ if (IsOpen == false)
+ {
+ throw new Exception("port is closed");
+ }
+ int error;
+
+ var pollResult = poll_serial(_fd, out error, SerialPort.ReadTimeout);
+ if (error == -1)
+ {
+ ThrowIoException();
+ }
+ return pollResult;
+ }
+
+ [DllImport("libc")]
+ private static extern IntPtr strerror(int errnum);
+
+ private static void ThrowIoException()
+ {
+ var errnum = Marshal.GetLastWin32Error();
+ var errorMessage = Marshal.PtrToStringAnsi(strerror(errnum));
+ throw new IOException(errorMessage);
+ }
+
+ private void CheckDisposed(Stream stream)
+ {
+ if ((bool)_disposedFieldInfo.GetValue(stream))
+ {
+ throw new ObjectDisposedException(stream.GetType().FullName);
+ }
+ }
+ }
+}
diff --git a/PCR1000/SerialPorts/MsSerialPort.cs b/PCR1000/SerialPorts/MsSerialPort.cs
new file mode 100644
index 0000000..a195464
--- /dev/null
+++ b/PCR1000/SerialPorts/MsSerialPort.cs
@@ -0,0 +1,23 @@
+using System.IO.Ports;
+#pragma warning disable 1591
+
+namespace PCR1000.SerialPorts
+{
+ public class MsSerialPort : PcrSerialPort
+ {
+ public MsSerialPort(string port, int baud, Parity parity, int dataBits, StopBits stopBits)
+ : base(port, baud, parity, dataBits, stopBits)
+ {
+ }
+
+ public override void Open()
+ {
+ SerialPort.Open();
+ }
+
+ public override void Dispose()
+ {
+ SerialPort.Dispose();
+ }
+ }
+}
diff --git a/PCR1000/SerialPorts/PcrSerialPort.cs b/PCR1000/SerialPorts/PcrSerialPort.cs
new file mode 100644
index 0000000..e5a8e00
--- /dev/null
+++ b/PCR1000/SerialPorts/PcrSerialPort.cs
@@ -0,0 +1,64 @@
+using System;
+using System.IO.Ports;
+using System.Text;
+#pragma warning disable 1591
+
+namespace PCR1000.SerialPorts
+{
+ public abstract class PcrSerialPort : IDisposable
+ {
+ public event EventHandler DataReceived;
+ protected readonly SerialPort SerialPort;
+
+ protected PcrSerialPort(string port, int baud, Parity parity, int dataBits, StopBits stopBits)
+ {
+ SerialPort = new SerialPort(port, baud, parity, dataBits, stopBits);
+ SerialPort.DataReceived += SerialPortDataReceived;
+ }
+
+ protected void SerialPortDataReceived(object sender, SerialDataReceivedEventArgs e)
+ {
+ DataReceived?.Invoke(sender, e);
+ }
+
+ public void Close()
+ {
+ SerialPort.Close();
+ }
+
+ public abstract void Open();
+
+ public void Write(string cmd)
+ {
+ SerialPort.Write(cmd);
+ }
+
+ public int Read(byte[] buff, int offset, int count)
+ {
+ return SerialPort.Read(buff, offset, count);
+ }
+
+ public void DiscardInBuffer()
+ {
+ SerialPort.DiscardInBuffer();
+ }
+
+ public bool DtrEnable
+ {
+ get { return SerialPort.DtrEnable; }
+ set { SerialPort.DtrEnable = value; }
+ }
+ public Handshake Handshake
+ {
+ get { return SerialPort.Handshake; }
+ set { SerialPort.Handshake = value; }
+ }
+
+ public bool IsOpen => SerialPort.IsOpen;
+ public string PortName => SerialPort.PortName;
+ public int ReadBufferSize => SerialPort.ReadBufferSize;
+ public Encoding Encoding => SerialPort.Encoding;
+
+ public abstract void Dispose();
+ }
+}
diff --git a/PCR1000LibTest/App.config b/PCR1000LibTest/App.config
index 8e15646..2d2a12d 100644
--- a/PCR1000LibTest/App.config
+++ b/PCR1000LibTest/App.config
@@ -1,6 +1,6 @@
-
+
-
+
-
\ No newline at end of file
+
diff --git a/PCR1000LibTest/Form1.Designer.cs b/PCR1000LibTest/Control.Designer.cs
similarity index 98%
rename from PCR1000LibTest/Form1.Designer.cs
rename to PCR1000LibTest/Control.Designer.cs
index 69d35d2..086d7fa 100644
--- a/PCR1000LibTest/Form1.Designer.cs
+++ b/PCR1000LibTest/Control.Designer.cs
@@ -1,6 +1,6 @@
namespace PCR1000LibTest
{
- partial class Form1
+ partial class Control
{
///
/// Required designer variable.
diff --git a/PCR1000LibTest/Form1.cs b/PCR1000LibTest/Control.cs
similarity index 92%
rename from PCR1000LibTest/Form1.cs
rename to PCR1000LibTest/Control.cs
index 53b98d6..6cd02e3 100644
--- a/PCR1000LibTest/Form1.cs
+++ b/PCR1000LibTest/Control.cs
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
-using System.Data;
using System.Drawing;
-using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -11,9 +9,9 @@
namespace PCR1000LibTest
{
- public partial class Form1 : Form
+ public partial class Control : Form
{
- public Form1()
+ public Control()
{
InitializeComponent();
}
diff --git a/PCR1000LibTest/Form1.resx b/PCR1000LibTest/Control.resx
similarity index 100%
rename from PCR1000LibTest/Form1.resx
rename to PCR1000LibTest/Control.resx
diff --git a/PCR1000LibTest/PCR1000LibTest.csproj b/PCR1000LibTest/PCR1000LibTest.csproj
index a0b0ca8..307c48d 100644
--- a/PCR1000LibTest/PCR1000LibTest.csproj
+++ b/PCR1000LibTest/PCR1000LibTest.csproj
@@ -9,8 +9,9 @@
Properties
PCR1000LibTest
PCR1000LibTest
- v4.5
+ v4.6
512
+
AnyCPU
@@ -44,16 +45,16 @@
-
+
Form
-
- Form1.cs
+
+ Control.cs
-
- Form1.cs
+
+ Control.cs
ResXFileCodeGenerator
@@ -63,6 +64,7 @@
True
Resources.resx
+ True
SettingsSingleFileGenerator
diff --git a/PCR1000LibTest/Program.cs b/PCR1000LibTest/Program.cs
index 0af9ce1..963eb8b 100644
--- a/PCR1000LibTest/Program.cs
+++ b/PCR1000LibTest/Program.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -16,7 +15,7 @@ static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1());
+ Application.Run(new Control());
}
}
}
diff --git a/PCR1000LibTest/Properties/Resources.Designer.cs b/PCR1000LibTest/Properties/Resources.Designer.cs
index b455fd1..fe555c5 100644
--- a/PCR1000LibTest/Properties/Resources.Designer.cs
+++ b/PCR1000LibTest/Properties/Resources.Designer.cs
@@ -1,17 +1,17 @@
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
-// Runtime Version:4.0.30319.18408
+// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
-namespace PCR1000LibTest.Properties
-{
-
-
+namespace PCR1000LibTest.Properties {
+ using System;
+
+
///
/// A strongly-typed resource class, for looking up localized strings, etc.
///
@@ -22,48 +22,40 @@ namespace PCR1000LibTest.Properties
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class Resources
- {
-
+ internal class Resources {
+
private static global::System.Resources.ResourceManager resourceMan;
-
+
private static global::System.Globalization.CultureInfo resourceCulture;
-
+
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Resources()
- {
+ internal Resources() {
}
-
+
///
/// Returns the cached ResourceManager instance used by this class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager
- {
- get
- {
- if ((resourceMan == null))
- {
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PCR1000LibTest.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
-
+
///
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture
- {
- get
- {
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
return resourceCulture;
}
- set
- {
+ set {
resourceCulture = value;
}
}
diff --git a/PCR1000LibTest/Properties/Settings.Designer.cs b/PCR1000LibTest/Properties/Settings.Designer.cs
index f080b42..5fc67cc 100644
--- a/PCR1000LibTest/Properties/Settings.Designer.cs
+++ b/PCR1000LibTest/Properties/Settings.Designer.cs
@@ -1,28 +1,24 @@
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
-// Runtime Version:4.0.30319.18408
+// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
-namespace PCR1000LibTest.Properties
-{
-
-
+namespace PCR1000LibTest.Properties {
+
+
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
- internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
- {
-
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
-
- public static Settings Default
- {
- get
- {
+
+ public static Settings Default {
+ get {
return defaultInstance;
}
}
diff --git a/PCRNetworkServer/Cli.cs b/PCRNetworkServer/Cli.cs
index 45f5afa..9fda57c 100644
--- a/PCRNetworkServer/Cli.cs
+++ b/PCRNetworkServer/Cli.cs
@@ -1,5 +1,8 @@
using System;
+using System.IO.Ports;
+using System.Linq;
using PCR1000;
+using PCR1000.Network;
namespace PCRNetworkServer
{
@@ -69,7 +72,12 @@ private static void PrintHelp(Exception ex = null)
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("\t-s, --sport");
Console.ForegroundColor = ConsoleColor.Gray;
- Console.WriteLine("\t\tSerial port to use. Defaults to COM1.");
+ Console.WriteLine("\t\tSerial port to use. Defaults to first serial port.");
+
+ Console.ForegroundColor = ConsoleColor.White;
+ Console.WriteLine("\t-d, --devices");
+ Console.ForegroundColor = ConsoleColor.Gray;
+ Console.WriteLine("\t\tLists all avalible devices.");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("\nAUTHOR");
@@ -97,6 +105,16 @@ public static void Run()
return;
}
+ var portNames = SerialPort.GetPortNames();
+ if (Arguments.GetArgumentBool("devices") || Arguments.GetArgumentBool("d"))
+ {
+ foreach (var portName in portNames)
+ {
+ Console.WriteLine(portName);
+ }
+ return;
+ }
+
try
{
int nport;
@@ -109,12 +127,19 @@ public static void Run()
}
string sport;
- if (string.IsNullOrWhiteSpace(sport = Arguments.GetArgument("sport")))
+ if (string.IsNullOrWhiteSpace(sport = Arguments.GetArgument("sport")) && string.IsNullOrWhiteSpace(sport = Arguments.GetArgument("s")))
{
- if (string.IsNullOrWhiteSpace(sport = Arguments.GetArgument("s")))
+ if (portNames.Length == 0)
{
- sport = "COM1";
+ Console.Error.WriteLine("No serial ports are avalible for use!");
+ return;
}
+ sport = portNames[0];
+ }
+ else if (!portNames.Contains(sport))
+ {
+ Console.Error.WriteLine("Serial port provided does not exist on this system.");
+ return;
}
var passwd = Arguments.GetArgument("passwd");
diff --git a/PCRNetworkServer/Gui.cs b/PCRNetworkServer/Gui.cs
index 8d5ae0b..c61b300 100644
--- a/PCRNetworkServer/Gui.cs
+++ b/PCRNetworkServer/Gui.cs
@@ -3,6 +3,7 @@
using System.IO.Ports;
using System.Windows.Forms;
using PCR1000;
+using PCR1000.Network;
namespace PCRNetworkServer
{
diff --git a/PCRNetworkServer/PCRNetworkServer.csproj b/PCRNetworkServer/PCRNetworkServer.csproj
index 4e66a09..2332492 100644
--- a/PCRNetworkServer/PCRNetworkServer.csproj
+++ b/PCRNetworkServer/PCRNetworkServer.csproj
@@ -9,7 +9,7 @@
Properties
PCRNetworkServer
PCRNetworkServer
- v4.5.1
+ v4.6
512
@@ -61,6 +61,10 @@
+
+ {c4792356-055e-4181-9ece-ec75fb04fda0}
+ PCR1000.Network
+
{29487920-2926-48b7-bd8c-b2761696663b}
PCR1000
diff --git a/PCRNetworkServer/app.config b/PCRNetworkServer/app.config
index 884f984..b45f31e 100644
--- a/PCRNetworkServer/app.config
+++ b/PCRNetworkServer/app.config
@@ -1,3 +1,3 @@
-
+