private void SetPort() { _serialPort = new SerialPort { PortName = _setupData.GetString(_setupNode, "Name", "COM1"), BaudRate = _setupData.GetInteger(_setupNode, "Baud", 57600), DataBits = _setupData.GetInteger(_setupNode, "DataBits", 8), Parity = (Parity)Enum.Parse(typeof(Parity), _setupData.GetString(_setupNode, "Parity", Parity.None.ToString())), StopBits = (StopBits)Enum.Parse(typeof(StopBits), _setupData.GetString(_setupNode, "StopBits", StopBits.One.ToString())), Handshake = Handshake.None, Encoding = Encoding.UTF8 }; var nodeAlways = Xml.GetNodeAlways(_setupNode, "Header"); _headerChecked = (nodeAlways.Attributes != null && ((nodeAlways.Attributes["checked"] != null) && (nodeAlways.Attributes["checked"].Value == bool.TrueString))); _header = Encoding.ASCII.GetBytes(nodeAlways.InnerText); nodeAlways = Xml.GetNodeAlways(_setupNode, "Footer"); _footerChecked = (nodeAlways.Attributes != null && ((nodeAlways.Attributes["checked"] != null) && (nodeAlways.Attributes["checked"].Value == bool.TrueString))); _footer = Encoding.ASCII.GetBytes(nodeAlways.InnerText); }
private void InitSerialPort() { _serialPort = new SerialPort(_setupData.GetString(_setupNode, PortNode, "COM1"), _setupData.GetInteger(_setupNode, BaudNode, 19200), (Parity)Enum.Parse(typeof(Parity), _setupData.GetString(_setupNode, ParityNode, Parity.None.ToString())), _setupData.GetInteger(_setupNode, DataNode, 8), (StopBits)Enum.Parse(typeof(StopBits), _setupData.GetString(_setupNode, StopNode, StopBits.One.ToString()))) { WriteTimeout = 500 }; }
private void SetPort() { if ((_serialPort != null) && _serialPort.IsOpen) { _serialPort.Close(); } _serialPort = new SerialPort(_setupData.GetString(_setupNode, PortNode, "COM1"), _setupData.GetInteger(_setupNode, BaudNode, 19200), (Parity)Enum.Parse(typeof(Parity), _setupData.GetString(_setupNode, ParityNode, Parity.None.ToString())), _setupData.GetInteger(_setupNode, DataNode, 8), (StopBits)Enum.Parse(typeof(StopBits), _setupData.GetString(_setupNode, StopNode, StopBits.One.ToString()))) { Handshake = Handshake.None, Encoding = Encoding.UTF8 }; }
protected override void SendPacket(List <byte> bytes) { try { _serialPort.Write(bytes.ToArray(), 0, bytes.Count); } catch (InvalidOperationException) { if (SerialPort.GetPortNames().Contains(_setupData.GetString(_setupNode, PortNode, "COM1"))) { "Reconnecting...".CrashLog(); try { InitSerialPort(); _serialPort.Open(); "Success!".CrashLog(); } catch (Exception e) { ("Failed! " + e.Message).CrashLog(); } } } catch (IOException ioe) { ("IO Exception: " + ioe.Message).CrashLog(); } }
public void Initialize(IExecutable executableObject, SetupData setupData, XmlNode setupNode) { /* * Called anytime Vixen needs to make sure the plug-in's setup or other initialization is up to date. * Initialize is called before the plug-in is setup, before sequence execution, and other times. * It's called from multiple places at any time, therefore the plug-in can make no assumptions * about the state of the program or sequence due to a call to Initialize. * * channels: An array of Channel objects representing the channels present in the owning sequence. * setupData: A SetupData reference that provides some plug-incentric convenience methods. * It can be safely ignored. * setupNode: An XmlNode representing the root of the plug-in's setup data in the sequence. * Please see the Vixen.Xml class for some convenience methods. */ // Store the SetupData and root XML node passed by Vixen m_setupData = setupData; m_setupNode = setupNode; // Load this plug-in's settings IPAddress.TryParse(m_setupData.GetString(m_setupNode, IPAddr, "10.10.10.10"), out m_RemoteIPAddr); m_minIntensity = m_setupData.GetInteger(m_setupNode, MinIntensity, 1); }
private void InitPortData() { _hostName = _setupData.GetString(_setupNode, HostNode, "192.168.1.0"); _portNumber = _setupData.GetInteger(_setupNode, PortNode, 23); }