public void Run(IInputDevicePluginContext pluginContext) { var port = pluginContext.GetInput <int>("Listening port"); var millisecondThrottle = pluginContext.GetInput <int>("Incoming Midi Throttle (milliseconds)"); using (var listener = new OscReceiver(port)) { var stopWatch = new Stopwatch(); while (listener.State == OscSocketState.Connected) { stopWatch.Stop(); stopWatch.Reset(); stopWatch.Start(); var packet = listener.Receive(); var midiMessage = MidiMessage.FromOscPacket(packet); pluginContext.SetOutput("Midi note", midiMessage.MidiNote.Note); pluginContext.SetOutput("Midi octave", midiMessage.MidiNote.Octave); pluginContext.SetOutput("Midi velocity", midiMessage.Velocity); pluginContext.SignalOutputChange(); while (stopWatch.ElapsedMilliseconds < millisecondThrottle) { listener.Receive(); } } } }
private void ListenLoop() { try { while (_server.State != OscSocketState.Closed) { if (_server.State == OscSocketState.Connected) { // get the next message // this will block until one arrives or the socket is closed OscPacket packet = _server.Receive(); if (packet.Error != OscPacketError.None) { continue; } ProcessOscPacket(string.Empty, packet); } } } catch (Exception ex) { // if the socket was connected when this happens // then tell the user if (_server.State == OscSocketState.Connected) { _logger.LogError(ex, "Exception in OSC listen loop"); } } }
private void ListenLoop() { try { while (_receiver.State != OscSocketState.Closed) { // if we are in a state to recieve if (_receiver.State == OscSocketState.Connected) { // get the next message // this will block until one arrives or the socket is closed OscPacket packet = _receiver.Receive(); if (packet is OscMessage msg) { _messages.Enqueue(msg); } else if (packet is OscBundle bnd) { foreach (OscMessage m in bnd) { _messages.Enqueue(m); } } } } } catch (Exception ex) { if (_receiver.State == OscSocketState.Connected) { _exceptions.Enqueue(ex); } } }
//受信Thread private void ReceiveThread() { try { //ソケットが閉じていない間受信を続ける while (oscReceiver.State != OscSocketState.Closed) { //接続状態なら処理を行う if (oscReceiver.State == OscSocketState.Connected) { //受信を行う var packet = oscReceiver.Receive(); ProcessPacket(packet); } else { //接続されていない場合は待つ Thread.Sleep(16); } } } catch (Exception e) { //ソケットが閉じられた例外のときは無視する if (e.Message != "The receiver socket has been disconnected") { Console.WriteLine("# ReceiveThread : " + e); } } }
private void ReceiverMethod() { try { while (oscReceiver.State != OscSocketState.Closed) { if (oscReceiver.State == OscSocketState.Connected) { ReceiverSemaphore.WaitOne(); data = oscReceiver.Receive(); if (((OscMessage)data).Address == "/DTDT") { OnDataReceived?.Invoke(data); } ReceiverSemaphore.Release(); } } } catch (Exception ex) { if (oscReceiver.State == OscSocketState.Connected) { Console.WriteLine("Exception in listen loop"); Console.WriteLine(ex.Message); } } }
private void ListenLoop() { Console.WriteLine("ListenLoop"); try { while (oscReceiver.State != OscSocketState.Closed) { Console.WriteLine("wait..."); // if we are in a state to recieve if (oscReceiver.State == OscSocketState.Connected) { // get the next message // this will block until one arrives or the socket is closed OscPacket packet = oscReceiver.Receive(); // Write the packet to the console Console.WriteLine(packet.ToString()); // DO SOMETHING HERE! viewModel.OscText = packet.ToString(); } Thread.Sleep(10000); } } catch (Exception ex) { // if the socket was connected when this happens // then tell the user if (oscReceiver.State == OscSocketState.Connected) { Console.WriteLine("Exception in listen loop"); Console.WriteLine(ex.Message); } } }
/** * Listen is spawned by a thread in the Connect() method. It remains * in a loop receiving data as the connection is alive. * * @see Esc.StateListener.Connect */ private void Listen() { while (connected) { try { OscPacket packet = receiver.Receive(); if (null != packet) { // UnityMainThreadDispatcher.Instance ().Enqueue (ExsecuteOnMainThread_TimeCheck ()); lock (processQueue) { if (packet.IsBundle()) { ArrayList messages = packet.Values; for (int i = 0; i < messages.Count; i++) { processQueue.Add((OscMessage)messages [i]); } } else { processQueue.Add((OscMessage)packet); } } } } catch (Exception e) { Debug.LogError(e.Message); } } }
private void ListenToMessage(IPAddress ipAddress, int port, CancellationToken token) { try { using (_oscReveiver = new OscReceiver(ipAddress, OscServerPort)) { _oscReveiver.Connect(); while (_oscReveiver.State != OscSocketState.Closed && !token.IsCancellationRequested) { // if we are in a state to recieve if (_oscReveiver.State != OscSocketState.Connected) { continue; } // get the next message // this will block until one arrives or the socket is closed var packet = _oscReveiver.Receive(); //Treat the message _taskQueue.Enqueue(() => Task.Run(() => OnMessageReceive(packet))); } } } catch (Exception) { //Exception cause here do nothing for the moment } }
private void ListenerWork() { while (_receiver.State != OscSocketState.Closed) { // if we are in a state to recieve if (_receiver.State == OscSocketState.Connected) { // get the next message // this will block until one arrives or the socket is closed OscPacket packet = _receiver.Receive(); // parse the message string[] msg = OscDeserializer.ParseOscPacket(packet); string[] msgAddress = OscDeserializer.GetMessageAddress(msg); var ip = OscDeserializer.GetMessageIp(msg); var port = OscDeserializer.GetMessagePort(msg); var binSeq = OscDeserializer.GetMessageBinSeq(msg); // if the sessionWorker already exists, update config. Otherwise, create a new sessionWorker SessionWorker session = CheckSession(ip, port); if (session == null) { session = new SessionWorker(ip, port, _dataPub, _sessionManager); _sessionManager.AddConnection(session); session.SetTimers(); } session.SetLookupFlags(binSeq); } } }
private void ReceiveLoop() { try { while (oscReceiver.State != OscSocketState.Closed) { // if we are in a state to receive if (oscReceiver.State == OscSocketState.Connected) { // get the next callback // this will block until one arrives or the socket is closed OscPacket packet = oscReceiver.Receive(); connection.PacketReceived(packet); } } } catch (Exception ex) { if (oscReceiver.State != OscSocketState.Closed && oscReceiver.State != OscSocketState.Closing) { connection.OnException(Strings.UdpConnectionImplementation_ErrorReceiving, ex); } } }
private async Task ListenLoop() { while (_receiver.State != OscSocketState.Connected) { await Task.Delay(1000); SendServerState(); } while (_receiver.State == OscSocketState.Connected) { try { var packet = _receiver.Receive(); //Console.WriteLine($"Received from ORAC: {packet.ToString()} {packet.GetType()}"); if (packet is Rug.Osc.OscMessage m) { OscMessageArrived?.Invoke(this, new OscMessage { Address = m.Address, Arg = m.ToArray() }); SendServerState(); var change = false; if (!_moduleLoaded && m.Address == "/module") { _moduleLoaded = true; change = true; } if (!_menuLoaded && m.Address == "/text" && (int)m.ToArray()[0] == 5) { _menuLoaded = true; change = true; } if (change && _menuLoaded && _moduleLoaded) { // Send special message to all of the components that connect has completed OscMessageArrived?.Invoke(this, new OscMessage { Address = "/ConnectComplete" }); } } } catch (Exception e) when(e.Message != "The receiver socket has been disconnected") { Console.WriteLine($"Error! {e.Message}"); } catch (Exception e) when(e.Message == "The receiver socket has been disconnected") { } } }
private void ListenLoop() { try { while (m_Receiver.State != OscSocketState.Closed) { // if we are in a state to recieve if (m_Receiver.State == OscSocketState.Connected) { // get the next message // this will block until one arrives or the socket is closed OscPacket packet = m_Receiver.Receive(); switch (m_Listener.ShouldInvoke(packet)) { case OscPacketInvokeAction.Invoke: packetCounter.Increment(); //textBoxBuffer.WriteLine("Received packet"); textBoxBuffer.WriteLine(packet.ToString()); m_Listener.Invoke(packet); break; case OscPacketInvokeAction.DontInvoke: textBoxBuffer.WriteLine("Cannot invoke"); textBoxBuffer.WriteLine(packet.ToString()); break; case OscPacketInvokeAction.HasError: textBoxBuffer.WriteLine("Error reading osc packet, " + packet.Error); textBoxBuffer.WriteLine(packet.ErrorMessage); break; case OscPacketInvokeAction.Pospone: textBoxBuffer.WriteLine("Posponed bundle"); textBoxBuffer.WriteLine(packet.ToString()); break; default: break; } } } } catch (Exception ex) { // if the socket was connected when this happens // then tell the user if (m_Receiver.State == OscSocketState.Connected) { textBoxBuffer.WriteLine("Exception in listen loop"); textBoxBuffer.WriteLine(ex.Message); } } }
private void OpenReceiver(ushort port) { // Update port list if (!receivePorts.Contains(port)) { receivePorts.Add(port); receivePorts.Sort(); } toolStripMenuItemReceivePort.DropDownItems.Clear(); foreach (ushort p in receivePorts) { toolStripMenuItemReceivePort.DropDownItems.Add(p.ToString()); } toolStripMenuItemReceivePort.DropDownItems.Add("..."); // Check selected port foreach (ToolStripMenuItem toolStripMenuItem in toolStripMenuItemReceivePort.DropDownItems) { if (toolStripMenuItem.Text == port.ToString()) { toolStripMenuItem.Checked = true; } } // Open receiver if (oscReceiver != null) { oscReceiver.Close(); } if (thread != null) { thread.Join(); } oscReceiver = new OscReceiver(port); thread = new Thread(new ThreadStart(delegate() { try { while (oscReceiver.State != OscSocketState.Closed) { if (oscReceiver.State == OscSocketState.Connected) { DeconstructPacket(oscReceiver.Receive()); } } } catch { } })); oscReceiver.Connect(); thread.Start(); }
/// <summary> /// Receives the next available OSC packet, splits the csv data values, and stores into a string array /// </summary> public void GetOSCPacket() { try { if (_OSCReceiver.State == OscSocketState.Connected) { OscPacket packet = _OSCReceiver.Receive(); _OSCPacket = packet.ToString().Split(','); } } catch (Exception e) { Debug.Log(e.Message); _OSCReceiver.Close(); } }
/// <summary> /// Receives the next available OSC packet relative to the Pozyx TagID, /// splits the csv data values, and stores into a string array /// </summary> public static string[] GetOSCPacket(string tagID) { OscPacket packet; string[] extractData = null; const string START_LINE = "/position"; bool gotCorrectPacket = false; // Attempt to establish an OSC connection and receive packet try { // Connect to OSC _OSCReceiver.Connect(); do { if (_OSCReceiver.State == OscSocketState.Connected) { // Attempt to receive OSC packet packet = _OSCReceiver.Receive(); // Extract data from OSC packet if (packet.ToString().StartsWith(START_LINE)) { extractData = packet.ToString().Split(','); // Multi-Tag Functionality // Checks packet "TagID" matches GameObject "TagID" (in Hexadecimal) if (Convert.ToInt32(extractData[1]).ToString("X") == tagID) { gotCorrectPacket = true; } } } } while (!gotCorrectPacket); // Close OSC _OSCReceiver.Close(); } catch (Exception e) { Debug.Log(e.Message); } return(extractData); }
protected override void OnStart(string[] args) { MidiIn = CreateMidiIn(Settings.Default.InputMidiDevice); OscOut = new OscSender(IPAddress.Parse(Settings.Default.OscHost), 0, Settings.Default.OscPortOut); OscOut.Connect(); OscIn = new OscReceiver(IPAddress.Parse(Settings.Default.OscHost), Settings.Default.OscPortIn); Task.Run(() => { OscIn.Connect(); var running = true; while (running) { try { var packet = OscIn.Receive(); var messages = ExplodeBundle(packet); foreach (var message in messages) { try { var msg = new OscEventArgs(message.Address, message.ToArray()); WriteDebug($"Got OSC: {msg}"); OscMessageReceived?.Invoke(this, msg); } catch { // ignore } } } catch { running = false; } } }); LoadPlugins(); }
private void ListenLoop() { try { while (_server.State != OscSocketState.Closed) { if (_server.State == OscSocketState.Connected) { // get the next message // this will block until one arrives or the socket is closed OscPacket packet = _server.Receive(); if (packet.Error != OscPacketError.None) { Logger.Instance.LogMessage(TracingLevel.ERROR, $"Recieved corrupt OSC packet: {packet.ErrorMessage}"); } switch (packet) { case OscBundle b: foreach (OscMessage m in b) { ProcessOscMessage(m); } break; case OscMessage m: ProcessOscMessage(m); break; } } } } catch (Exception ex) { // if the socket was connected when this happens // then tell the user if (_server.State == OscSocketState.Connected) { Logger.Instance.LogMessage(TracingLevel.ERROR, $"Exception in OSC listen loop: {ex.Message}"); } } }
void ListenLoop() { try { while (m_Receiver.State != OscSocketState.Closed) { // if we are in a state to recieve if (m_Receiver.State == OscSocketState.Connected) { // get the next message // this will block until one arrives or the socket is closed OscPacket packet = m_Receiver.Receive(); if (packet == null) { continue; } if (packet.Error == OscPacketError.None) { this.Invoke(new StringEvent(AppendLine), packet.ToString()); } else { this.Invoke(new StringEvent(AppendLine), "Error reading packet, " + packet.Error); this.Invoke(new StringEvent(AppendLine), packet.ErrorMessage); } } } } catch (Exception ex) { // if the socket was connected when this happens // then tell the user if (m_Receiver.State == OscSocketState.Connected) { this.Invoke(new StringEvent(AppendLine), "Exception in listen loop"); this.Invoke(new StringEvent(AppendLine), ex.Message); } } }
static void ListenLoop() { try { while (m_Receiver.State != OscSocketState.Closed) { // if we are in a state to recieve if (m_Receiver.State == OscSocketState.Connected) { // get the next message // this will block until one arrives or the socket is closed OscPacket packet = m_Receiver.Receive(); if (packet == null) { continue; } if (packet.Error == OscPacketError.None) { m_Listener.Invoke(packet); } else { Console.WriteLine("Error reading osc packet, " + packet.Error); Console.WriteLine(packet.ErrorMessage); } } } } catch (Exception ex) { // if the socket was connected when this happens // then tell the user if (m_Receiver.State == OscSocketState.Connected) { Console.WriteLine("Exception in listen loop"); Console.WriteLine(ex.Message); } } }
private void ListenLoop() { try { while (_resolumeOscReceiver.State != OscSocketState.Closed) { // if we are in a state to recieve if (_resolumeOscReceiver.State == OscSocketState.Connected) { // get the next message, this will block until one arrives or the socket is closed OscBundle packet = _resolumeOscReceiver.Receive() as OscBundle; foreach (OscMessage message in packet) { object argument = ExtractArgumentFromMessage(message); ResolumeValue resolumeValue; if (!_values.TryGetValue(message.Address, out resolumeValue)) { resolumeValue = GenerateNewResolumeValue(argument); _values[message.Address] = resolumeValue; } else { UpdateExistingResolumeValue(argument, resolumeValue); } ValueChanged?.Invoke(message.Address, resolumeValue); } } } } catch (Exception ex) { // if the socket was connected when this happens // then tell the user if (_resolumeOscReceiver.State == OscSocketState.Connected) { Console.WriteLine("Exception in listen loop"); Console.WriteLine(ex.Message); } } }
static void StartLoop(OscReceiver oscReceiver) { OscPacket packet = null; string[] extractData = null; const string START_LINE = "/position"; // Attempt to establish an OSC connection try { do { if (oscReceiver.State == OscSocketState.Connected) { // Attempt receive OSC packet packet = oscReceiver.Receive(); // Extract position data from OSC packet if (packet.ToString().StartsWith(START_LINE)) { extractData = packet.ToString().Split(','); } foreach (string dataItem in extractData) { Console.Write(dataItem + "\t"); } Console.Write("TagID: " + Convert.ToInt16(extractData[1]).ToString("X")); // Converts decimal (26400) into hexadecimal (6270) Console.WriteLine(); } } while (true); } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { Console.WriteLine("OSC Server."); // 12345ポートでOscレシーバーを作成 using var oscReceiver = new OscReceiver(2345); // 接続処理 oscReceiver.Connect(); // 無限ループにして受信待ち while (true) { var oscPacket = oscReceiver.Receive(); var msg = oscPacket.ToString(); Console.WriteLine(msg); var f_t = msg.Split(" "); Console.WriteLine($"{f_t[0]} {f_t[1]} {f_t[2]}"); if (int.TryParse(f_t[1], out int freq) && int.TryParse(f_t[2], out int time)) { Console.Beep(freq, time); } } }
// Loop for listening and updating dashboard data. static void ListenLoop() { try { while (Receiver.State != OscSocketState.Closed) { if (Receiver.State == OscSocketState.Connected) { // Get the next message, this will block until one arrives or the socket is closed. OscPacket Packet = Receiver.Receive(); // Slap the packet in the most recent message variable. App.Current.Dispatcher.InvokeAsync(() => { // Parses the packet into a message array. OscBundle MessageBundle = OscBundle.Parse(Packet.ToString()); foreach (OscPacket MessagePacket in MessageBundle.ToArray()) { // Get the latest message. OscMessage LatestMessage = OscMessage.Parse(MessagePacket.ToString()); // Determine if the message should be overwritten. bool OverwriteMessage = false; int OverwriteMessageIndex = 0; foreach (OscData Message in ReceivedOscData) { if (Message.Path == LatestMessage.Address) { OverwriteMessageIndex = ReceivedOscData.IndexOf(Message); OverwriteMessage = true; } } // Cut the address out of the data string. string DataString = ""; string[] DataArray = LatestMessage.ToString().Split(','); for (int i = 1; i < DataArray.Length; i++) { DataString += DataArray[i]; } // Add the message to the data grid, or overwrite its data. if (OverwriteMessage) { ReceivedOscData.RemoveAt(OverwriteMessageIndex); ReceivedOscData.Insert(OverwriteMessageIndex, new OscData() { Path = LatestMessage.Address, Data = DataString }); } else { ReceivedOscData.Add(new OscData() { Path = LatestMessage.Address, Data = DataString }); } } }); } } } catch (Exception Ex) { // Display the exeception if it occurred, while receiving. if (Receiver.State == OscSocketState.Connected) { MessageBox.Show(Ex.Message, "Exception Occurred", MessageBoxButton.OK, MessageBoxImage.Warning); } } }
private static void OscWorker_DoWork(object sender, DoWorkEventArgs e) { try { while (receiver.State != OscSocketState.Closed) { if (oscWorker.CancellationPending) { return; } if (receiver.State == OscSocketState.Connected) { string command = receiver.Receive().ToString(); Application.Current.Dispatcher.Invoke(new Action(() => { if (!oscMute) { if ((command.StartsWith("/video") || command.StartsWith("/eos/out"))) { Match match = Regex.Match(command, @".*/(\d+)/fire.*$"); if (match.Success) { Debug.WriteLine(match.Groups[1].Value); if (int.TryParse(match.Groups[1].Value, out int cueNr)) { for (int i = 0; i < CuelistCtrl.cues.Count; ++i) { Cue cue = CuelistCtrl.cues[i]; if (cue.trigger != null && cue.trigger.type == TriggerType.OSC && cue.trigger.oscCmd.intVal == cueNr) { if (Core.win.saveTriggerCheckbox.IsChecked && Core.win.cueTable.SelectedIndex != i) { LogCtrl.Error("In: " + command); } else { LogCtrl.Success("In: " + command); GoCtrl.Go(i); } return; } } } } LogCtrl.Status("In: " + command); } else { LogCtrl.Status("In: " + command); } } else { LogCtrl.Warning("In: " + command); } })); } } } catch (Exception ex) { Application.Current.Dispatcher.Invoke(new Action(() => { LogCtrl.Error(ex.Message); })); } }