Ejemplo n.º 1
0
        /// <summary>
        /// Execute Service by SID.
        /// </summary>
        /// <param name="sid"> Service Id. </param>
        void Excute(byte sid)
        {
            if (!_adapter.IsConnected)
            {
                throw new CanAdapterException("Adapter is Disconnected. Code:-8604."); //Doc
            }
            lock (_adapter.LockObj)
            {
                UInt16 status  = 0;
                byte[] request = new byte[CanAdapterDevice.UsbAttrOutEpSize];

                int bytes = MakeServiceRequest(request, _adapter.FrameCnt, sid);
                _adapter.WriteUsbAttrPipe(request, bytes);

                byte[] response;
                byte   cnt;
                _adapter.ReadUsbAttrPipe(out response, out bytes);
                ParseActionResponse(response, out cnt, out status);
                if (_adapter.FrameCnt != cnt)
                {
                    throw new CanAdapterException("Sync Error. Code:-8610."); //Doc
                }
                if ((status & 0x8000) == 0x8000)
                {
                    throw new CanAdapterException("Error." + CanStatus.Decode(status)); //Doc
                }
                else if ((status & 0x4000) == 0x4000)
                {
                    throw new CanAdapterException("Warning." + CanStatus.Decode(status)); //Doc
                }
                _adapter.FrameCnt++;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="attrId"></param>
        /// <param name="value"></param>
        internal void AttributeU32Write(UInt32 attrId, UInt32 value)
        {
            if (!_adapter.IsConnected)
            {
                throw new CanAdapterException("Adapter is Disconnected. Code:-8604."); //Doc
            }
            lock (_adapter.LockObj)
            {
                UInt16 status = 0;
                byte[] buffer = null;
                byte[] response;
                int    resBytes = 0;
                byte[] request  = new byte[CanAdapterDevice.UsbAttrOutEpSize];
                int    reqBytes = 0;
                byte   cnt;

                reqBytes = MakeAttriubtRequest(request, _adapter.FrameCnt, CanServices.SID_ATTR_WRITE, attrId, value, 8);
                _adapter.WriteUsbAttrPipe(request, reqBytes);
                _adapter.ReadUsbAttrPipe(out response, out resBytes);
                ParseAttributeResponse(response, out cnt, out buffer, out status);
                if (_adapter.FrameCnt != cnt)
                {
                    throw new CanAdapterException("Sync Error. Code:-8610."); //Doc
                }
                _adapter.FrameCnt++;
                if ((status & 0x8000) == 0x8000)
                {
                    throw new CanAdapterException("Error." + CanStatus.Decode(status)); //Doc
                }
                else if ((status & 0x4000) == 0x4000)
                {
                    throw new CanAdapterException("Warning." + CanStatus.Decode(status)); //Doc
                }
            }
        }