Example #1
0
        public J2534Err WriteMsgs(int channelId, ref PassThruMsg msg, ref int numMsgs, int timeout)
        {
            UnsafePassThruMsg uMsg = ConvertPassThruMsg(msg);

            // TODO: change function to accept a list? of PassThruMsg
            return((J2534Err)m_wrapper.WriteMsgs(channelId, ref uMsg, ref numMsgs, timeout));
        }
Example #2
0
        public J2534Err ReadMsgs(int channelId, ref List <PassThruMsg> msgs, ref int numMsgs, int timeout)
        {
            UnsafePassThruMsg[] pMsgs       = new UnsafePassThruMsg[numMsgs];
            J2534Err            returnValue = (J2534Err)m_wrapper.ReadMsgs(channelId, ref pMsgs[0], ref numMsgs, timeout);

            if (returnValue == J2534Err.STATUS_NOERROR)
            {
                for (int i = 0; i < numMsgs; i++)
                {
                    msgs.Add(ConvertPassThruMsg(pMsgs[i]));
                }
            }


            /*
             * IntPtr pMsg = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(UnsafePassThruMsg)) * 50);
             * IntPtr pNextMsg = IntPtr.Zero;
             * IntPtr[] pMsgs = new IntPtr[50];
             *
             * J2534Err returnValue = (J2534Err)m_wrapper.ReadMsgs(channelId, pMsg, ref numMsgs, timeout);
             * if (returnValue == J2534Err.STATUS_NOERROR)
             * {
             *  for (int i = 0; i < numMsgs; i++)
             *  {
             *      pNextMsg = (IntPtr)(Marshal.SizeOf(typeof(UnsafePassThruMsg)) * i + (int)pMsg);
             *      UnsafePassThruMsg uMsg = (UnsafePassThruMsg)Marshal.PtrToStructure(pMsg, typeof(UnsafePassThruMsg));
             *      msgs.Add(ConvertPassThruMsg(uMsg));
             *  }
             * }
             * Marshal.FreeHGlobal(pMsg);
             */
            return(returnValue);
        }
Example #3
0
        private static PassThruMsg ConvertPassThruMsg(UnsafePassThruMsg uMsg)
        {
            PassThruMsg msg = new PassThruMsg();

            msg.ProtocolID     = (ProtocolID)uMsg.ProtocolID;
            msg.RxStatus       = (RxStatus)uMsg.RxStatus;
            msg.Timestamp      = uMsg.Timestamp;
            msg.TxFlags        = (TxFlag)uMsg.TxFlags;
            msg.ExtraDataIndex = uMsg.ExtraDataIndex;
            msg.Data           = new byte[uMsg.DataSize];
            unsafe
            {
                for (int i = 0; i < uMsg.DataSize; i++)
                {
                    msg.Data[i] = uMsg.Data[i];
                }
            }
            return(msg);
        }
Example #4
0
        public J2534Err FastInit(int channelId, PassThruMsg txMsg, ref PassThruMsg rxMsg)
        {
            IntPtr            input  = IntPtr.Zero;
            IntPtr            output = IntPtr.Zero;
            UnsafePassThruMsg uTxMsg = ConvertPassThruMsg(txMsg);
            UnsafePassThruMsg uRxMsg = new UnsafePassThruMsg();

            Marshal.StructureToPtr(uTxMsg, input, true);
            Marshal.StructureToPtr(uRxMsg, output, true);

            J2534Err returnValue = (J2534Err)m_wrapper.Ioctl(channelId, (int)Ioctl.FAST_INIT, input, output);

            if (returnValue == J2534Err.STATUS_NOERROR)
            {
                Marshal.PtrToStructure(output, uRxMsg);
            }

            rxMsg = ConvertPassThruMsg(uRxMsg);
            return(returnValue);
        }
Example #5
0
        private UnsafePassThruMsg ConvertPassThruMsg(PassThruMsg msg)
        {
            UnsafePassThruMsg uMsg = new UnsafePassThruMsg();

            uMsg.ProtocolID     = (int)msg.ProtocolID;
            uMsg.RxStatus       = (int)msg.RxStatus;
            uMsg.Timestamp      = msg.Timestamp;
            uMsg.TxFlags        = (int)msg.TxFlags;
            uMsg.ExtraDataIndex = msg.ExtraDataIndex;
            uMsg.DataSize       = msg.Data.Length;
            unsafe
            {
                for (int i = 0; i < msg.Data.Length; i++)
                {
                    uMsg.Data[i] = msg.Data[i];
                }
            }

            return(uMsg);
        }
Example #6
0
        public J2534Err StartMsgFilter
        (
            int channelid,
            FilterType filterType,
            ref PassThruMsg maskMsg,
            ref PassThruMsg patternMsg,
            ref int filterId
        )
        {
            int nada = 0;
            UnsafePassThruMsg uMaskMsg    = ConvertPassThruMsg(maskMsg);
            UnsafePassThruMsg uPatternMsg = ConvertPassThruMsg(patternMsg);

            return((J2534Err)m_wrapper.StartPassBlockMsgFilter
                   (
                       channelid,
                       (int)filterType,
                       ref uMaskMsg,
                       ref uPatternMsg,
                       nada,
                       ref filterId
                   ));
        }
Example #7
0
        public J2534Err StartMsgFilter
        (
            int channelid,
            FilterType filterType,
            ref PassThruMsg maskMsg,
            ref PassThruMsg patternMsg,
            ref PassThruMsg flowControlMsg,
            ref int filterId
        )
        {
            UnsafePassThruMsg uMaskMsg        = ConvertPassThruMsg(maskMsg);
            UnsafePassThruMsg uPatternMsg     = ConvertPassThruMsg(patternMsg);
            UnsafePassThruMsg uFlowControlMsg = ConvertPassThruMsg(flowControlMsg);

            return((J2534Err)m_wrapper.StartMsgFilter
                   (
                       channelid,
                       (int)filterType,
                       ref uMaskMsg,
                       ref uPatternMsg,
                       ref uFlowControlMsg,
                       ref filterId
                   ));
        }
Example #8
0
        public J2534Err StartPeriodicMsg(int channelId, ref PassThruMsg msg, ref int msgId, int timeInterval)
        {
            UnsafePassThruMsg uMsg = ConvertPassThruMsg(msg);

            return((J2534Err)m_wrapper.StartPeriodicMsg(channelId, ref uMsg, ref msgId, timeInterval));
        }
Example #9
0
        private static PassThruMsg ConvertPassThruMsg(UnsafePassThruMsg uMsg)
        {
            PassThruMsg msg = new PassThruMsg();

            msg.ProtocolID = (ProtocolID)uMsg.ProtocolID;
            msg.RxStatus = (RxStatus)uMsg.RxStatus;
            msg.Timestamp = uMsg.Timestamp;
            msg.TxFlags = (TxFlag)uMsg.TxFlags;
            msg.ExtraDataIndex = uMsg.ExtraDataIndex;
            msg.Data = new byte[uMsg.DataSize];
            unsafe
            {
                for (int i = 0; i < uMsg.DataSize; i++)
                {
                    msg.Data[i] = uMsg.Data[i];
                }
            }

            return msg;
        }
Example #10
0
        private UnsafePassThruMsg ConvertPassThruMsg(PassThruMsg msg)
        {
            UnsafePassThruMsg uMsg = new UnsafePassThruMsg();

            uMsg.ProtocolID = (int)msg.ProtocolID;
            uMsg.RxStatus = (int)msg.RxStatus;
            uMsg.Timestamp = msg.Timestamp;
            uMsg.TxFlags = (int)msg.TxFlags;
            uMsg.ExtraDataIndex = msg.ExtraDataIndex;
            uMsg.DataSize = msg.Data.Length;
            unsafe
            {
                for (int i = 0; i < msg.Data.Length; i++)
                {
                    uMsg.Data[i] = msg.Data[i];
                }
            }

            return uMsg;
        }
Example #11
0
        public J2534Err FastInit(int channelId, PassThruMsg txMsg, ref PassThruMsg rxMsg)
        {
            IntPtr input = IntPtr.Zero;
            IntPtr output = IntPtr.Zero;
            UnsafePassThruMsg uTxMsg = ConvertPassThruMsg(txMsg);
            UnsafePassThruMsg uRxMsg = new UnsafePassThruMsg();

            Marshal.StructureToPtr(uTxMsg, input, true);
            Marshal.StructureToPtr(uRxMsg, output, true);

            J2534Err returnValue = (J2534Err)m_wrapper.Ioctl(channelId, (int)Ioctl.FAST_INIT, input, output);
            if (returnValue == J2534Err.STATUS_NOERROR)
            {
                Marshal.PtrToStructure(output, uRxMsg);
            }

            rxMsg = ConvertPassThruMsg(uRxMsg);
            return returnValue;
        }