예제 #1
0
        public object getProperty(ccParameter param, int start, int num)
        {
            //send request message

            routedMessage       m   = new routedMessage(node.address, new byte[] { 0x03, (byte)param.Index, (byte)start, (byte)num });
            MessageSubscription sub = new MessageSubscription()
            {
                singleShot = true, sent = m
            };

            con.SendRoutedMessage(m, 0, sub);
            //wait for reply
            asyncWaitForReply(sub, defaultTimeout);

            //decode message
            param.parseValue(sub.reply);

            return(param.Value);
        }
예제 #2
0
        private void asyncWaitForReply(MessageSubscription sub, int timeout)
        {
            // bit of a bodge but makes code so much simpler
            // for .net4.5 replace with async method
            DateTime start = DateTime.Now;

            while (sub.reply == null)
            {
                System.Windows.Forms.Application.DoEvents();

                if ((DateTime.Now - start).TotalMilliseconds >= timeout)
                {
                    if (sub.singleShot)
                    {
                        sub.expired = true;
                    }
                    throw new Exception("Routed Object reply timeout");
                }
            }
        }
예제 #3
0
        public void setProperty(ccParameter param, int start, int num)
        {
            //assume value already set in local param
            uint nBlocks   = 1;
            uint blockSize = 0;

            if (param.Value.GetType().IsArray)
            {
                if (start >= param.ArrayLen)
                {
                    throw (new Exception("Set routed Property index too big"));
                }
                num = Math.Min(num, (int)param.ArrayLen - start);
                //calc number of blocks to send
                blockSize = 32;
                nBlocks   = ((uint)num - 1) / blockSize + 1;
            }

            UInt32 startidx = (UInt32)start;

            for (int i = 0; i < nBlocks; i++)
            {
                byte size = (byte)Math.Min(blockSize, start + num - startidx);

                routedMessage       m   = new routedMessage(node.address, param.buildSetCmd(startidx, size));
                MessageSubscription sub = new MessageSubscription()
                {
                    singleShot = true, sent = m
                };

                con.SendRoutedMessage(m, 0, sub);
                //wait for ack
                asyncWaitForReply(sub, defaultTimeout);
                //TODO check ack?
                startidx += blockSize;
            }
        }