/// <summary> /// /// </summary> /// <param name="actId"></param> /// <param name="attrId"></param> /// <param name="data"></param> internal void AttributeRead(byte actId, UInt32 attrId, out byte[] data) { if (!_adapter.IsConnected) { throw new CanAdapterException("Adapter is Disconnected. Code:-8604."); //Doc } lock (_adapter.LockObj) { UInt16 status = 0; byte[] response; int resBytes = 0; byte[] request = new byte[CanAdapterDevice.UsbAttrOutEpSize]; int reqBytes = 0; byte cnt; reqBytes = MakeAttriubtRequest(request, _adapter.FrameCnt, actId, attrId, 0, 4); _adapter.WriteUsbAttrPipe(request, reqBytes); _adapter.ReadUsbAttrPipe(out response, out resBytes); ParseAttributeResponse(response, out cnt, out data, out status); if (_adapter.FrameCnt != cnt) { throw new CanAdapterException("Sync Error. Code:-8610."); } _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 } } }
/// <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++; } }