-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuNavUtils.cs
55 lines (49 loc) · 1.59 KB
/
uNavUtils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace uNav
{
public static class uNavUtils
{
public static bool IsValidIPandPort(string src, out string ipAddres, out ushort port)
{
bool result = false;
ipAddres = null;
port = 0;
var splits = src.Split(":".ToCharArray());
if (splits.Length == 2)
{
if (ushort.TryParse(splits[1], out port))
{
var splits2 = splits[0].Split(".".ToCharArray());
if (splits2.Length == 4)
{
if (byte.TryParse(splits2[0], out _) &&
byte.TryParse(splits2[1], out _) &&
byte.TryParse(splits2[2], out _) &&
byte.TryParse(splits2[3], out _))
{
ipAddres = splits[0];
result = true;
}
}
}
}
return result;
}
public static string[] GetSerialPortNamesExcept(string ePort)
{
List<string> result = new List<string>();
var spNames = SerialPort.GetPortNames();
foreach (var s in spNames)
{
if (s != ePort)
result.Add(s);
}
return result.ToArray();
}
}
}