Ejemplo n.º 1
0
        public int Send(byte[] buffer, int offset, int data_length, BacnetAddress address, bool wait_for_transmission, int timeout)
        {
            if (m_TS == -1)
            {
                throw new Exception("Source address must be set up before sending messages");
            }

            //add to queue
            BacnetNpduControls   function   = NPDU.DecodeFunction(buffer, offset);
            BacnetMstpFrameTypes frame_type = (function & BacnetNpduControls.ExpectingReply) == BacnetNpduControls.ExpectingReply ? BacnetMstpFrameTypes.FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY : BacnetMstpFrameTypes.FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;

            byte[] copy = new byte[data_length + MSTP.MSTP_HEADER_LENGTH + 2];
            Array.Copy(buffer, offset, copy, MSTP.MSTP_HEADER_LENGTH, data_length);
            MessageFrame f = new MessageFrame(frame_type, address.adr[0], copy, data_length);

            lock (m_send_queue)
                m_send_queue.AddLast(f);
            if (m_reply == null)
            {
                m_reply = f;
                m_reply_mutex.Set();
            }

            //wait for message to be sent
            if (wait_for_transmission)
            {
                if (!f.send_mutex.WaitOne(timeout))
                {
                    return(-ETIMEDOUT);
                }
            }

            return(data_length);
        }
Ejemplo n.º 2
0
        public override int Send(byte[] buffer, int offset, int dataLength, BacnetAddress address,
                                 bool waitForTransmission, int timeout)
        {
            if (SourceAddress == -1)
            {
                throw new Exception("Source address must be set up before sending messages");
            }

            //add to queue
            var function  = NPDU.DecodeFunction(buffer, offset);
            var frameType = (function & BacnetNpduControls.ExpectingReply) == BacnetNpduControls.ExpectingReply
                                ? BacnetMstpFrameTypes.FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY
                                : BacnetMstpFrameTypes.FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
            var copy = new byte[dataLength + MSTP.MSTP_HEADER_LENGTH + 2];

            Array.Copy(buffer, offset, copy, MSTP.MSTP_HEADER_LENGTH, dataLength);
            var f = new MessageFrame(frameType, address.adr[0], copy, dataLength);

            lock (_sendQueue)
                _sendQueue.AddLast(f);
            if (_reply == null)
            {
                _reply = f;
                _replyMutex.Set();
            }

            if (!waitForTransmission)
            {
                return(dataLength);
            }

            //wait for message to be sent
            if (!f.SendMutex.WaitOne(timeout))
            {
                return(-ETIMEDOUT);
            }

            return(dataLength);
        }