Ejemplo n.º 1
0
        public int StartPeriodicMessage(PeriodicMsg PeriodicMessage)
        {
            J2534Status  Status    = new J2534Status();
            J2534HeapInt MessageID = new J2534HeapInt();

            J2534HeapMessage PeriodicMessageHeap = new J2534HeapMessage(ProtocolID,
                                                                        PeriodicMessage.Message.TxFlags,
                                                                        PeriodicMessage.Message.Data);

            lock (Device.Library.API_LOCK)
            {
                Status.Code = Device.Library.API.StartPeriodicMsg(ChannelID,
                                                                  PeriodicMessageHeap.Ptr,
                                                                  MessageID.Ptr,
                                                                  PeriodicMessage.Interval);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                    throw new J2534Exception(Status);
                }
                PeriodicMessage.MessageID = MessageID;
                PeriodicMsgList.Add(PeriodicMessage);
            }
            return(PeriodicMsgList.IndexOf(PeriodicMessage));
        }
Ejemplo n.º 2
0
        public J2534ERR ConnectToDevice(string Device)
        {
            J2534ERR Status;

            IntPtr pDeviceName = IntPtr.Zero;

            if (!string.IsNullOrEmpty(Device))
            {
                pDeviceName = Marshal.StringToHGlobalAnsi(Device);
            }
            else
            {
                DeviceName = string.Format("Device {0}", J2534Discovery.PhysicalDevices.FindAll(Listed => Listed.Library == this.Library).Count + 1);
            }

            J2534HeapInt DeviceID = new J2534HeapInt();

            lock (Library.API_LOCK)
            {
                Status = (J2534ERR)Library.API.Open(pDeviceName, DeviceID);

                Marshal.FreeHGlobal(pDeviceName);

                if (Status == J2534ERR.STATUS_NOERROR || (Library.API_Signature.SAE_API == SAE_API.V202_SIGNATURE &&
                                                          J2534Discovery.PhysicalDevices.FindAll(Listed => Listed.Library == this.Library).Count == 0 &&
                                                          IsConnected))
                {
                    this.DeviceID = DeviceID;
                    ValidDevice   = true;
                    GetVersion();
                }
                return(Status);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Starts a single message filter and if successful, adds it to the FilterList.
        /// </summary>
        /// <param name="Filter"></param>
        /// <returns>Returns false if successful</returns>
        public int StartMsgFilter(MessageFilter Filter)
        {
            J2534Status  Status   = new J2534Status();
            J2534HeapInt FilterID = new J2534HeapInt();

            J2534HeapMessage Mask        = new J2534HeapMessage(ProtocolID, Filter.TxFlags, Filter.Mask);
            J2534HeapMessage Pattern     = new J2534HeapMessage(ProtocolID, Filter.TxFlags, Filter.Pattern);
            J2534HeapMessage FlowControl = new J2534HeapMessage(ProtocolID, Filter.TxFlags, Filter.FlowControl);

            lock (Device.Library.API_LOCK)
            {
                Status.Code = Device.Library.API.StartMsgFilter(ChannelID,
                                                                (int)Filter.FilterType,
                                                                Mask.Ptr,
                                                                Pattern.Ptr,
                                                                Filter.FilterType == J2534FILTER.FLOW_CONTROL_FILTER ? FlowControl.Ptr : IntPtr.Zero,
                                                                FilterID.Ptr);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                    throw new J2534Exception(Status);
                }
                filterlist.Add(Filter);
            }
            return(filterlist.IndexOf(Filter));
        }
Ejemplo n.º 4
0
 public void PopulateWith(J2534PROTOCOL ProtocolID, J2534TXFLAG TxFlags, byte[] Data)
 {
     Length = 1;
     Marshal.WriteInt32(pMessages, (int)ProtocolID);
     Marshal.WriteInt32(pMessages, 8, (int)TxFlags);
     Marshal.WriteInt32(pMessages, 16, Data.Length);
     Marshal.Copy(Data, 0, IntPtr.Add(pMessages, 24), Data.Length);
 }
Ejemplo n.º 5
0
 public void PopulateWith(List <J2534Message> Messages)
 {
     Length = Messages.Count;
     for (int i = 0; i < Messages.Count; i++)
     {
         this[i] = Messages[i];
     }
 }
 public J2534HeapMessageArray(int Length)
 {
     if (Length < 1)
     {
         throw new ArgumentException("Length must be at least 1 (HEAPMessageArray");
     }
     array_max_length = Length;
     length           = new J2534HeapInt();
     pMessages        = Marshal.AllocHGlobal(CONST.J2534MESSAGESIZE * Length);
 }
Ejemplo n.º 7
0
        private J2534ERR StartPeriodicMessage(int Index)
        {
            J2534ERR Status;

            J2534HeapInt MessageID = new J2534HeapInt();

            J2534HeapMessage Message = new J2534HeapMessage(PeriodicMsgList[Index].Message);

            Status = (J2534ERR)Device.Library.API.StartPeriodicMsg(ChannelID, Message, MessageID, PeriodicMsgList[Index].Interval);

            PeriodicMsgList[Index].MessageID = MessageID;
            return(Status);
        }
Ejemplo n.º 8
0
        public int MeasureProgrammingVoltage()
        {
            J2534ERR     Status;
            J2534HeapInt Voltage = new J2534HeapInt();

            lock (Library.API_LOCK)
            {
                Status = (J2534ERR)Library.API.IOCtl(DeviceID, (int)J2534IOCTL.READ_PROG_VOLTAGE, IntPtr.Zero, Voltage);
                if (Status != J2534ERR.STATUS_NOERROR)
                {
                    throw new J2534Exception(Status, Library.GetLastError());
                }
                return(Voltage);
            }
        }
Ejemplo n.º 9
0
        public int MeasureProgrammingVoltage()
        {
            J2534Status  Status  = new J2534Status();
            J2534HeapInt Voltage = new J2534HeapInt();

            lock (Library.API_LOCK)
            {
                Status.Code = Library.API.IOCtl(DeviceID, (int)J2534IOCTL.READ_PROG_VOLTAGE, IntPtr.Zero, Voltage);
                if (Status.IsNotOK)
                {
                    Status.Description = Library.GetLastError();
                    throw new J2534Exception(Status);
                }
                return(Voltage);
            }
        }
Ejemplo n.º 10
0
        private void Connect()
        {
            J2534HeapInt ChannelID = new J2534HeapInt();

            lock (Device.Library.API_LOCK)
            {
                ConnectionStatus = (J2534ERR)Device.Library.API.Connect(Device.DeviceID, (int)ProtocolID, (int)ConnectFlags, Baud, ChannelID);
                if (ConnectionStatus == J2534ERR.STATUS_NOERROR)
                {
                    IsOpen         = true;
                    this.ChannelID = ChannelID;
                }
                //else
                //    throw new J2534Exception(Status, Device.Library.GetLastError());
            }
        }
Ejemplo n.º 11
0
 public int MeasureBatteryVoltage()
 {
     if (Device.Library.API_Signature.SAE_API == SAE_API.V202_SIGNATURE)
     {
         J2534ERR     Status;
         J2534HeapInt Voltage = new J2534HeapInt();
         lock (Device.Library.API_LOCK)
         {
             Status = (J2534ERR)Device.Library.API.IOCtl(ChannelID, (int)J2534IOCTL.READ_VBATT, IntPtr.Zero, Voltage);
             if (Status != J2534ERR.STATUS_NOERROR)
             {
                 throw new J2534Exception(Status, Device.Library.GetLastError());
             }
             return(Voltage);
         }
     }
     return(Device.MeasureBatteryVoltage());
 }
Ejemplo n.º 12
0
        private void Connect()
        {
            J2534HeapInt ChannelID = new J2534HeapInt();

            lock (Device.Library.API_LOCK)
            {
                ConnectionStatus.Code = Device.Library.API.Connect(Device.DeviceID, (int)ProtocolID, (int)ConnectFlags, Baud, ChannelID.Ptr);
                if (ConnectionStatus.IsOK)
                {
                    IsOpen         = true;
                    this.ChannelID = ChannelID;
                }
                else
                {
                    ConnectionStatus.Description = Device.Library.GetLastError();
                }
            }
        }
Ejemplo n.º 13
0
 public int MeasureBatteryVoltage()
 {
     if (Device.Library.API_Signature.SAE_API == SAE_API.V202_SIGNATURE)
     {
         J2534Status  Status  = new J2534Status();
         J2534HeapInt Voltage = new J2534HeapInt();
         lock (Device.Library.API_LOCK)
         {
             Status.Code = Device.Library.API.IOCtl(ChannelID, (int)J2534IOCTL.READ_VBATT, IntPtr.Zero, Voltage.Ptr);
             if (Status.IsNotOK)
             {
                 Status.Description = Device.Library.GetLastError();
                 throw new J2534Exception(Status);
             }
             return(Voltage);
         }
     }
     return(Device.MeasureBatteryVoltage());
 }
Ejemplo n.º 14
0
        public int MeasureBatteryVoltage()
        {
            J2534ERR Status;

            J2534HeapInt Voltage = new J2534HeapInt();

            lock (Library.API_LOCK)
            {
                Status = (J2534ERR)Library.API.IOCtl(DeviceID, (int)J2534IOCTL.READ_VBATT, IntPtr.Zero, Voltage);
                if (Status != J2534ERR.STATUS_NOERROR)
                {
                    throw new J2534Exception(Status, Library.GetLastError());
                }

                //The return was kept inside the lock here to ensure the conversion to INT is done before the
                //lock is released.  This is in case the API reuses the Ptr location for this data on subsequent
                //calls.  In that case, two back to back calls could interfere with each other of the second
                //call is allowed to execute before the first call marshals the Int from the heap.
                return(Voltage);
            }
        }
Ejemplo n.º 15
0
        private J2534ERR StartMsgFilter(int Index)
        {
            J2534ERR     Status;
            J2534HeapInt FilterID = new J2534HeapInt();

            J2534HeapMessage Mask        = new J2534HeapMessage(new J2534Message(ProtocolID, FilterList[Index].TxFlags, FilterList[Index].Mask));
            J2534HeapMessage Pattern     = new J2534HeapMessage(new J2534Message(ProtocolID, FilterList[Index].TxFlags, FilterList[Index].Pattern));
            J2534HeapMessage FlowControl = new J2534HeapMessage(new J2534Message(ProtocolID, FilterList[Index].TxFlags, FilterList[Index].FlowControl));

            //The lock is performed in the calling method to protect the 'FilterList' coherency.
            if (FilterList[Index].FilterType == J2534FILTER.FLOW_CONTROL_FILTER)
            {
                Status = (J2534ERR)Device.Library.API.StartMsgFilter(ChannelID, (int)FilterList[Index].FilterType, Mask, Pattern, FlowControl, FilterID);
            }
            else
            {
                Status = (J2534ERR)Device.Library.API.StartMsgFilter(ChannelID, (int)FilterList[Index].FilterType, Mask, Pattern, IntPtr.Zero, FilterID);
            }

            FilterList[Index].FilterId = FilterID;
            return(Status);
        }
Ejemplo n.º 16
0
 public J2534HeapMessageArray(int Length)
 {
     array_max_length = Length;
     length           = new J2534HeapInt();
     pMessages        = Marshal.AllocHGlobal(CONST.J2534MESSAGESIZE * Length);
 }
Ejemplo n.º 17
0
 public void PopulateWith(J2534Message Message)
 {
     Length  = 1;
     this[0] = Message;
 }