internal void Save(XmlElement parent) { XmlElement node = Helper.CreateElement(parent, "ConnectionInformation"); Helper.AppendAttributeAndValue(node, "ConnectionType", ConnectionType.ToString()); if (ConnectionInfo is UdpConnectionInfo) { UdpConnectionInfo info = ConnectionInfo as UdpConnectionInfo; Helper.AppendAttributeAndValue(node, "SendIPAddress", info.SendIPAddress.ToString()); Helper.AppendAttributeAndValue(node, "SendPort", info.SendPort.ToString()); Helper.AppendAttributeAndValue(node, "AdapterIPAddress", info.AdapterIPAddress.ToString()); Helper.AppendAttributeAndValue(node, "ReceivePort", info.ReceivePort); Helper.AppendAttributeAndValue(node, "AdapterName", info.AdapterName); } else if (ConnectionInfo is SerialConnectionInfo) { SerialConnectionInfo info = ConnectionInfo as SerialConnectionInfo; Helper.AppendAttributeAndValue(node, "PortName", info.PortName); Helper.AppendAttributeAndValue(node, "BaudRate", info.BaudRate); Helper.AppendAttributeAndValue(node, "RtsCtsEnabled", info.RtsCtsEnabled); } else if (ConnectionInfo is SDCardFileConnectionInfo) { SDCardFileConnectionInfo info = ConnectionInfo as SDCardFileConnectionInfo; Helper.AppendAttributeAndValue(node, "FilePath", info.FilePath); } parent.AppendChild(node); }
public SerialConnectionImplementation(Connection conn, SerialConnectionInfo info, OscCommunicationStatistics statistics) { connection = conn; serialConnectionInfo = info; // We set the buffer size to double that of the DefaultPacketSize to hold the maximum number of SLIP escaped bytes oscSerial = new OscSerial(info.PortName, (int)info.BaudRate, info.RtsCtsEnabled, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One, OscReceiver.DefaultPacketSize * 2); oscSerial.Statistics = statistics; }
private void SerialDeviceDiscovered(string serialNumber, SerialConnectionInfo obj) { ConnectionSearchResult connectionSearchResult = new ConnectionSearchResult(serialNumber, obj); lock (autoConnectionInfoListSyncLock) { connectionSearchResults.Add(connectionSearchResult); } DeviceDiscovered?.Invoke(connectionSearchResult); }
public void BeginSearch(int sendInterval = 100) { EndSearch(); lock (searchSyncLock) { ahoyServiceInfoList.Clear(); shouldSearch = true; searchComplete.Reset(); searchThread = new Thread(delegate() { Connection imuConnection = null; string serialNumber; SerialConnectionInfo serialConnectionInfo = new SerialConnectionInfo() { PortName = portName, BaudRate = 115200, RtsCtsEnabled = false, }; try { do { //Thread.CurrentThread.Join(100); try { imuConnection = new Connection(serialConnectionInfo); imuConnection.Connect(); } catch { imuConnection?.Dispose(); imuConnection = null; } }while (shouldSearch == true && imuConnection == null); if (shouldSearch == false) { return; } do { //Thread.CurrentThread.Join(100); //SerialConnectionInfo info; //string serialNumber; //if (TryConnection(portName, 115200, false, sendInterval, 1, out info, out serialNumber) == false) //{ // continue; //} try { if (Commands.Send(imuConnection, Command.Ahoy, sendInterval, 1, out serialNumber) != CommunicationProcessResult.Success) { continue; } } catch { continue; } AhoyServiceInfo serviceInfo = new AhoyServiceInfo(IPAddress.Any, IPAddress.Any, 0, 0, serialNumber, string.Empty, new object[] { serialConnectionInfo }, 0); if (ahoyServiceInfoList.Contains(serviceInfo) == true) { continue; } ahoyServiceInfoList.Add(serviceInfo); ServiceDiscovered?.Invoke(serviceInfo); SerialDeviceDiscovered?.Invoke(serialNumber, serialConnectionInfo); return; }while (shouldSearch == true); } finally { imuConnection?.Dispose(); searchComplete.Set(); } }); searchThread.Name = "Ahoy Scan Port " + portName; searchThread.Start(); } }
public void BeginSearch(int sendInterval = 100) { EndSearch(); lock (scanSyncLock) { ahoyServiceInfoList.Clear(); shouldScanForPorts = true; portScanComplete.Reset(); scanForNewPortsThread = new Thread(delegate() { try { List <string> portNames = new List <string>(); List <string> removed = new List <string>(); while (shouldScanForPorts == true) { portNames.Clear(); portNames.AddRange(Helper.GetSerialPortNames()); foreach (string portName in portNames) { if (serialPortQueriesList.ContainsKey(portName) == true) { continue; } AhoyQuerySerialPort query = new AhoyQuerySerialPort(portName); serialPortQueriesList.Add(portName, query); query.AnyReceived += OnAnyReceived; query.MessageReceived += OnMessageReceived; query.MessageSent += OnMessageSent; query.ServiceDiscovered += OnServiceDiscovered; query.SerialDeviceDiscovered += OnSerialDeviceDiscovered; query.BeginSearch(sendInterval); } removed.Clear(); foreach (string portName in serialPortQueriesList.Keys) { if (portNames.Contains(portName) == false) { removed.Add(portName); } } foreach (string portName in removed) { AhoyQuerySerialPort query = serialPortQueriesList[portName] as AhoyQuerySerialPort; query.EndSearch(); serialPortQueriesList.Remove(portName); foreach (AhoyServiceInfo serviceInfo in query) { ServiceExpired?.Invoke(serviceInfo); SerialConnectionInfo connInfo = new SerialConnectionInfo() { PortName = portName, BaudRate = 115200, RtsCtsEnabled = false, }; SerialDeviceExpired?.Invoke(serviceInfo.Descriptor, connInfo); ahoyServiceInfoList.Remove(serviceInfo); } } Thread.CurrentThread.Join(sendInterval); } } finally { portScanComplete.Set(); } }); scanForNewPortsThread.Name = "Ahoy Scan For New Ports Thread"; scanForNewPortsThread.Start(); } }
private void OnSerialDeviceDiscovered(string serialNumber, SerialConnectionInfo serialConnectionInfo) { SerialDeviceDiscovered?.Invoke(serialNumber, serialConnectionInfo); }