Пример #1
0
        /// <summary>
        /// Writes a single packet to the stream at the current position.
        /// </summary>
        /// <param name="packet">A osc packet</param>
        public void Write(OscPacket packet)
        {
            switch (Format)
            {
            case OscPacketFormat.Binary:
                byte[] bytes = packet.ToByteArray();

                // write the length
                Helper.Write(binaryWriter, bytes.Length);

                // write the packet
                binaryWriter.Write(bytes);
                break;

            case OscPacketFormat.Slip:
                byte[] preSlipBytes = packet.ToByteArray();
                byte[] slipBytes    = Slip.SlipPacketWriter.Write(preSlipBytes, 0, preSlipBytes.Length);

                // write the packet
                binaryWriter.Write(slipBytes);
                break;

            case OscPacketFormat.String:
                stringWriter.WriteLine(packet.ToString());
                break;

            default:
                throw new Exception($@"Invalid OSC stream format ""{Format}"".");
            }
        }
Пример #2
0
        public void Send(OscPacket packet)
        {
            if (serialPort == null)
            {
                throw new Exception("Serial port is not connected");
            }

            byte[] packetBytes  = packet.ToByteArray();
            byte[] slippedBytes = SlipPacketWriter.Write(packetBytes, 0, packetBytes.Length);

            if (Statistics != null)
            {
                packet.IncrementSendStatistics(Statistics);

                Statistics.BytesSent.Increment(packetBytes.Length);
            }

            serialPort.Write(slippedBytes, 0, slippedBytes.Length);
        }