private void WaxMainForm_FormClosed(object sender, FormClosedEventArgs e) { // Remove old wax manager if (waxManager != null) { waxManager.Dispose(); waxManager = null; } Thread.Sleep(500); }
private void toolStripButtonConnect_Click(object sender, EventArgs e) { // Remove old wax manager if (waxManager != null) { waxManager.Dispose(); waxManager = null; } if (!toolStripButtonConnect.Checked) { // Find port name if (PortName.Length != 0) { string port = FindPort(PortName); if (port != null) { PortName = port; } } waxManager = new WaxManager(); if (PortName.Length > 0) { // Create WAX manager try { string initiallySend = null; if (checkBoxSetMode.Checked) { // Set SLIP mode... [0=NONE,1=SLIP,2=TEXT,3=OSC] initiallySend = "\r\nMODE=1\r\n"; } waxManager.AddPacketSource(new SlipSource <WaxPacket>(waxManager.WaxPacketConverter, SlipSource <WaxPacket> .OpenSerialPort(PortName, initiallySend))); if (checkBoxBroadcast.Checked) { waxManager.AddPacketDest(new StompDest <WaxPacket>(waxManager.WaxPacketConverter, "localhost")); } } catch (Exception ex) { MessageBox.Show(this, "Error: " + ex.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { //MessageBox.Show(this, "Error: Port not specified.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); waxManager.AddPacketSource(new StompSource <WaxPacket>(waxManager.WaxPacketConverter, "localhost")); if (OscReceive) { waxManager.AddPacketSource(new OscSource <WaxPacket>(waxManager.WaxPacketConverter, "localhost:" + OscPort + "/wax")); } } if (waxManager != null) { // Set log file string file = LogFile; if (file != null && file.Length > 0) { DateTime now = DateTime.Now; string date = now.ToString(@"yyyy-MM-dd"); string time = now.ToString(@"HH-mm-ss"); file = file.Replace("{date}", date); file = file.Replace("{time}", time); waxManager.AddPacketDest(new LogDest <WaxPacket>(waxManager.WaxPacketConverter, new StreamWriter(new FileStream(file, FileMode.Append)))); } // Set WAX OSC transmission if (OscHost != null && OscHost.Length > 0 && OscPort > 0) { OscTransmitter tinyOscTransmitter = new OscTransmitter(OscHost, OscPort); waxManager.ReceivedPacket += (s, ea) => { try { WaxSample[] samples = ea.Packet.Samples; OscMessage[] messages = new OscMessage[samples.Length]; for (int i = 0; i < samples.Length; i++) { messages[i] = new OscMessage("/wax", (int)ea.Packet.DeviceId, samples[i].Index, samples[i].X / 256.0f, samples[i].Y / 256.0f, samples[i].Z / 256.0f); } OscBundle bundle = new OscBundle(OscBundle.TIMESTAMP_NOW, messages); tinyOscTransmitter.Send(bundle); } catch (Exception ex) { Console.Error.WriteLine("ERROR: Problem sending OSC packet - " + ex.Message); } }; } } // Set History panel to use WAX manager historyPanel.WaxManager = waxManager; // Update connection button toolStripButtonConnect.Checked = (waxManager != null); } else { // Update connection button toolStripButtonConnect.Checked = false; } // Update tool bar status bool connected = toolStripButtonConnect.Checked; toolStripLabelPort.Enabled = !connected; toolStripComboBoxPort.Enabled = !connected; toolStripLabelFile.Enabled = !connected; toolStripTextBoxLogFile.Enabled = !connected; toolStripButtonChooseFile.Enabled = !connected; // ... }