/// <summary>
        ///
        /// </summary>
        /// <param name="slaveMacId"></param>
        /// <param name="classCode"></param>
        /// <param name="instanceId"></param>
        public void ObjectResetService(int slaveMacId, byte classCode, byte instanceId)
        {
            byte[] request = new byte[]
            {
                (byte)MasterMacId,                  /*Source MAC Id: 0..64 */
                Services.SRVS_RESET,                /*Get Attribute Single*/
                classCode,                          /*Class Code*/
                instanceId,                         /*Instance Id*/
            };

            Adapter.Write(new CanMessage[]
            {
                new CanMessage(DeviceNetAddressing.GetExplicitRequestCanId(slaveMacId), request)
            });

            int  retrty    = 3;
            long timestamp = DateTime.Now.Ticks;
            bool isTimeout = false;

            CanMessage[] rxMsgBuffer = new CanMessage[1];
            do
            {
                do
                {
                    if (Adapter.Attributes.PendingRxMessages > 0)
                    {
                        isTimeout = false;
                        Adapter.Read(rxMsgBuffer, 0, 1);
                        break;
                    }
                    isTimeout = DateTime.Now.Ticks - timestamp > 1000 * 10000;
                } while (!isTimeout);

                if (isTimeout && retrty != 0)
                {
                    timestamp = DateTime.Now.Ticks;
                }
            } while (--retrty != 0 && isTimeout);

            if (isTimeout)
            {
                throw new DeviceNetException("DeviceNet: Response Timeout.");
            }

            byte[] response = rxMsgBuffer[0].Data;

            if (response[1] == 0x94)
            {
                throw new DeviceNetException("DeviceNet:" + DeviceNetException.ErrorMessageToString(response[2], response[3]));
            }

            if ((response[1] & 0x80) != 0x80)
            {
                throw new ApplicationException("DeviceNet:" + "Response Invalid.");
            }
        }
        /// <summary>
        ///
        /// </summary>
        public void AllocateExplicitConnection(int slaveMacId)
        {
            Adapter.Write(new CanMessage[]
            {
                new CanMessage(DeviceNetAddressing.GetUnconnctedExplicitRequestCanId(slaveMacId), new byte[] { 0x00, 0x4B, 0x03, 0x01, 0x01, 0x00 })
            });

            int  retrty    = 3;
            long timestamp = DateTime.Now.Ticks;
            bool isTimeout = false;

            CanMessage[] rxMsgBuffer = new CanMessage[1];
            do
            {
                do
                {
                    if (Adapter.Attributes.PendingRxMessages > 0)
                    {
                        isTimeout = false;
                        Adapter.Read(rxMsgBuffer, 0, 1);
                        break;
                    }
                    isTimeout = DateTime.Now.Ticks - timestamp > 1000 * 10000;
                } while (!isTimeout);

                if (isTimeout && retrty != 0)
                {
                    timestamp = DateTime.Now.Ticks;
                }
            } while (--retrty != 0 && isTimeout);

            CanMessage response = rxMsgBuffer[0];

            if (isTimeout)
            {
                throw new DeviceNetException("DeviceNet: Response Timeout.");
            }

            if (response.Data[1] == 0x94)
            {
                throw new DeviceNetException("DeviceNet:" + DeviceNetException.ErrorMessageToString(response.Data[2], response.Data[3]));
            }

            if ((response.Data[1] & 0x80) != 0x80)
            {
                throw new ApplicationException("DeviceNet:" + "Response Invalid.");
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="slaveMacId"></param>
        /// <param name="classCode"></param>
        /// <param name="instanceId"></param>
        /// <param name="attributeId"></param>
        /// <param name="value"></param>
        public void SetAttribute(int slaveMacId, byte classCode, byte instanceId, byte attributeId, byte[] value)
        {
            //bool rxComplete = false;
            //byte fragCounter = 0;

            byte[] requestHeader = new byte[]
            {
                (byte)MasterMacId,                  /*Source MAC Id: 0..64 */
                Services.SRVS_SET_ATTRIB_SINGLE,    /*Set Attribute Single*/
                classCode,                          /*Class Code*/
                instanceId,                         /*Instance Id*/
                attributeId,                        /*Attribute Id*/
            };

            byte[] request = new byte[requestHeader.Length + value.Length];
            Buffer.BlockCopy(requestHeader, 0, request, 0, requestHeader.Length);
            Buffer.BlockCopy(value, 0, request, requestHeader.Length, value.Length);

            Adapter.Write(new CanMessage[]
            {
                new CanMessage(DeviceNetAddressing.GetExplicitRequestCanId(slaveMacId), request)
            });

            int  retrty    = 3;
            long timestamp = DateTime.Now.Ticks;
            bool isTimeout = false;

            CanMessage[] rxMsgBuffer = new CanMessage[1];
            do
            {
                do
                {
                    if (Adapter.Attributes.PendingRxMessages > 0)
                    {
                        isTimeout = false;
                        Adapter.Read(rxMsgBuffer, 0, 1);
                        break;
                    }
                    isTimeout = DateTime.Now.Ticks - timestamp > 1000 * 10000;
                } while (!isTimeout);

                if (isTimeout && retrty != 0)
                {
                    timestamp = DateTime.Now.Ticks;
                }
            } while (--retrty != 0 && isTimeout);

            if (isTimeout)
            {
                throw new DeviceNetException("DeviceNet: Response Timeout.");
            }

            byte[] response = rxMsgBuffer[0].Data;

            if (response[1] == 0x94)
            {
                throw new DeviceNetException("DeviceNet:" + DeviceNetException.ErrorMessageToString(response[2], response[3]));
            }

            if ((response[1] & 0x80) != 0x80)
            {
                throw new ApplicationException("DeviceNet:" + "Response Invalid.");
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="slaveMacId"></param>
        /// <param name="classCode"></param>
        /// <param name="instanceId"></param>
        /// <param name="attributeId"></param>
        /// <returns></returns>
        public byte[] GetAttribute(int slaveMacId, byte classCode, byte instanceId, byte attributeId)
        {
            bool rxComplete  = false;
            byte fragCounter = 0;

            byte[] response       = new byte[256];
            int    responseLength = 0;

            byte[] request = new byte[]
            {
                (byte)MasterMacId,                  /*Source MAC Id: 0..64 */
                Services.SRVS_GET_ATTRIB_SINGLE,    /*Get Attribute Single*/
                classCode,                          /*Class Code*/
                instanceId,                         /*Instance Id*/
                attributeId,                        /*Attribute Id*/
            };

            Adapter.Write(new CanMessage[]
            {
                new CanMessage(DeviceNetAddressing.GetExplicitRequestCanId(slaveMacId), request)
            });

            do
            {
                int          retrty      = 3;
                long         timestamp   = DateTime.Now.Ticks;
                bool         isTimeout   = false;
                CanMessage[] rxMsgBuffer = new CanMessage[1];
                do
                {
                    do
                    {
                        if (Adapter.Attributes.PendingRxMessages > 0)
                        {
                            isTimeout = false;
                            Adapter.Read(rxMsgBuffer, 0, 1);
                            break;
                        }
                        isTimeout = DateTime.Now.Ticks - timestamp > 1000 * 10000;
                    } while (!isTimeout);

                    if (isTimeout && retrty != 0)
                    {
                        timestamp = DateTime.Now.Ticks;
                    }
                } while (--retrty != 0 && isTimeout);

                if (isTimeout)
                {
                    throw new DeviceNetException("DeviceNet: Response Timeout.");
                }

                CanMessage responseBuffer = rxMsgBuffer[0];

                if ((responseBuffer.Data[0] & 0x80) == 0x80)
                { /*Fragmented Response*/
                    int fragmentType = (responseBuffer.Data[1] & 0xC0) >> 6;

                    if (fragmentType == 0x02)
                    {
                        rxComplete = true;
                    }

                    byte[] ack = new byte[]
                    {
                        (byte)(0x80 | MasterMacId),     /*0x80|MasterMacId*/
                        (byte)(0xC0 | fragCounter),     /*0xC0|FragCounter  -> ACK*/
                        0x00
                    };

                    Adapter.Write(new CanMessage[] {
                        new CanMessage(DeviceNetAddressing.GetExplicitRequestCanId(slaveMacId), ack)
                    });

                    Buffer.BlockCopy(responseBuffer.Data, 2, response, responseLength, responseBuffer.Data.Length - 2);
                    responseLength += responseBuffer.Data.Length - 2;
                    fragCounter++;
                }
                else
                { /*Not Fragmented Response*/
                    Buffer.BlockCopy(responseBuffer.Data, 1, response, 0, responseBuffer.Data.Length - 1);
                    responseLength += responseBuffer.Data.Length - 1;
                    rxComplete      = true;
                }
            } while (!rxComplete);

            if (response[0] == 0x94)
            {
                throw new DeviceNetException("DeviceNet:" + DeviceNetException.ErrorMessageToString(response[1], response[2]));
            }

            if ((response[0] & 0x80) != 0x80)
            {
                throw new ApplicationException("DeviceNet:" + "Response Invalid.");
            }

            byte[] value = new byte[responseLength - 1];
            Buffer.BlockCopy(response, 1, value, 0, responseLength - 1);

            return(value);
        }