Пример #1
0
        private void loadDBCToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "DBC files (*.dbc)|*.dbc|All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 1;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                VehicleScapeAPI.Result result = VehicleScapeInterface.LoadDatabase(openFileDialog.FileName);
                if (result == VehicleScapeAPI.Result.ResultOk)
                {
                    Log(openFileDialog.FileName + " loaded successfully.");

                    GetDAQs();
                    LoadMessagesAndSignals();
                    // Detect devices here for the user's convenience
                    DetectDevices();
                }
                else
                {
                    Log("Failed to load " + openFileDialog.FileName + ".");
                    Log("Reason: " + VehicleScapeAPI.ResultToString(result) + ".");
                }
            }
        }
        public static VehicleScapeAPI.Result Transfer(uint deviceHandle, bool reflash)
        {
            if (deviceHandle == 0)
            {
                return(VehicleScapeAPI.Result.ResultInvalidHandle);
            }

            int storageMediaCount = 0;

            VehicleScapeAPI.GetStorageMediumsForDevice(deviceHandle, IntPtr.Zero, ref storageMediaCount);
            if (storageMediaCount < 0)
            {
                return(VehicleScapeAPI.Result.ResultInvalidMedium);
            }
            VehicleScapeAPI.MemoryType[] types = new VehicleScapeAPI.MemoryType[storageMediaCount];
            VehicleScapeAPI.GetStorageMediumsForDevice(deviceHandle, types, ref storageMediaCount);
            VehicleScapeAPI.Result result = VehicleScapeAPI.Result.ResultOk;
            if (reflash)
            {
                VehicleScapeAPI.ReflashDevice(deviceHandle);
            }
            if (result != VehicleScapeAPI.Result.ResultOk)
            {
                return(result);
            }
            return(VehicleScapeAPI.SendCoreMini(deviceHandle, types[0], VehicleScapeAPI.RUNCOREMINI | VehicleScapeAPI.SYNCRTC));
        }
        public static VehicleScapeAPI.Result LoadDatabase(string filename)
        {
            VehicleScapeAPI.Result result = Initialize();
            if (result != VehicleScapeAPI.Result.ResultOk && result != VehicleScapeAPI.Result.ResultAlreadyInitialized)
            {
                return(result);
            }

            if (result == VehicleScapeAPI.Result.ResultAlreadyInitialized)
            {
                result = VehicleScapeAPI.Result.ResultOk;
            }

            int networkCount = 0;

            result = VehicleScapeAPI.GetNetworks(IntPtr.Zero, ref networkCount);
            if (networkCount <= 0)
            {
                return(result);
            }
            VehicleScapeAPI.Network[] networks = new VehicleScapeAPI.Network[networkCount];
            VehicleScapeAPI.GetNetworks(networks, ref networkCount);
            uint networkHandle = networks[0].handle;

            VehicleScapeAPI.Database database = new VehicleScapeAPI.Database();
            result = VehicleScapeAPI.AddDatabase(networkHandle, filename, VehicleScapeAPI.DatabaseType.DatabaseTypeJ1939NoPgnOffset, ref database);
            return(result);
        }
 private static VehicleScapeAPI.Result Initialize()
 {
     VehicleScapeAPI.Result result = VehicleScapeAPI.Init();
     if (result == VehicleScapeAPI.Result.ResultOk)
     {
         Initialized = true;
         // VehicleScape automatically creates a DAQ for us and names it "DAQ 1."
         // We want it named "New DAQ" like any DAQ we create, so we'll change it here.
         VehicleScapeAPI.DAQ initialDAQ = GetDAQs()[0];
         initialDAQ.description = "New DAQ";
         VehicleScapeAPI.SetDAQProperties(ref initialDAQ);
     }
     return(result);
 }
        public static VehicleScapeAPI.Result Generate(GenerateParameters parameters, uint daqHandle, uint deviceHandle)
        {
            if (daqHandle == 0 || deviceHandle == 0)
            {
                return(VehicleScapeAPI.Result.ResultInvalidHandle);
            }
            // Set up our DAQ
            VehicleScapeAPI.DAQ daq = GetDAQByHandle(daqHandle);
            VehicleScapeAPI.SetDAQProperties(ref daq);

            // Set up our collection
            List <VehicleScapeAPI.DAQCollection> cols = GetDAQCollections(daqHandle);

            if (cols.Count == 0)
            {
                return(VehicleScapeAPI.Result.ResultUnableToSetupForCompile);
            }
            VehicleScapeAPI.DAQCollection col = cols[0];
            col.fileName = parameters.Name;
            col.stopNumMessages.numMessages = parameters.NumberOfMessagesToCollect;
            col.collectionType = VehicleScapeAPI.CollectionType.StartImmediatelyStopNumMessage;
            VehicleScapeAPI.SetDAQCollectionProperties(ref col);

            List <uint> channelHandles = new List <uint>();

            channelHandles.AddRange(parameters.MessageHandles);
            channelHandles.AddRange(parameters.SignalHandles);
            List <VehicleScapeAPI.DAQChannel> channels = new List <VehicleScapeAPI.DAQChannel>();

            // Set up our channels
            foreach (uint handle in channelHandles)
            {
                VehicleScapeAPI.DAQChannel channel = new VehicleScapeAPI.DAQChannel();
                channel.signalHandle = handle;
                VehicleScapeAPI.AddDAQChannel(daqHandle, handle, ref channel);
                VehicleScapeAPI.SetAlwaysCollectDAQChannel(handle);
                channels.Add(channel);
            }

            VehicleScapeAPI.Result retv = VehicleScapeAPI.GenerateCoreMini(daqHandle, deviceHandle);

            // Clear out the channels
            foreach (VehicleScapeAPI.DAQChannel channel in channels)
            {
                VehicleScapeAPI.RemoveDAQChannel(channel.signalHandle);
            }

            return(retv);
        }
Пример #6
0
        private void GenerateButton_Click(object sender, EventArgs e)
        {
            if (GetSelectedDAQHandle() == 0 || GetSelectedDeviceHandle() == 0)
            {
                MessageBox.Show("You must select a DAQ and a device to generate a CoreMini.");
                return;
            }
            UpdateDAQ();
            List <uint> messageHandles = new List <uint>();
            List <uint> signalHandles  = new List <uint>();

            foreach (ListViewItem item in SelectedChannelsListView.Items)
            {
                TagMetadata metadata = (TagMetadata)item.Tag;
                if (metadata.Type == TagMetadata.MetadataType.Message)
                {
                    messageHandles.Add(metadata.Handle);
                }
                else
                {
                    signalHandles.Add(metadata.Handle);
                }
            }

            GenerateParameters parameters = new GenerateParameters(
                messageHandles,
                signalHandles,
                CollectionNameTextBox.Text,
                int.Parse(MessageCountTextBox.Text),
                SleepMode,
                WakeMode,
                double.Parse(BusActivityThresholdTextBox.Text),
                RemoteWakeupCheckBox.Checked,
                StartNewFileOnWakeupCheckBox.Checked,
                double.Parse(OverallTimeoutTextBox.Text),
                double.Parse(ConnectionTimeoutTextBox.Text),
                double.Parse(VoltageCutoffTextBox.Text));

            Log("Generating CoreMini.");
            VehicleScapeAPI.Result result = VehicleScapeInterface.Generate(parameters, GetSelectedDAQHandle(), GetSelectedDeviceHandle());
            Log("Result: " + VehicleScapeAPI.ResultToString(result));
        }
        public static List <VehicleScapeAPI.Device> GetDevices()
        {
            List <VehicleScapeAPI.Device> devices = new List <VehicleScapeAPI.Device>();

            VehicleScapeAPI.Result result = Initialize();
            if (result != VehicleScapeAPI.Result.ResultOk && result != VehicleScapeAPI.Result.ResultAlreadyInitialized)
            {
                return(devices);
            }

            int deviceCount = 0;

            VehicleScapeAPI.GetDevices(IntPtr.Zero, ref deviceCount);
            if (deviceCount > 0)
            {
                VehicleScapeAPI.Device[] devs = new VehicleScapeAPI.Device[deviceCount];
                VehicleScapeAPI.GetDevices(devs, ref deviceCount);
                devices.AddRange(devs);
            }
            return(devices);
        }
Пример #8
0
 private void UploadButton_Click(object sender, EventArgs e)
 {
     Log("Transferring to device.");
     VehicleScapeAPI.Result result = VehicleScapeInterface.Transfer(GetSelectedDeviceHandle(), ReflashFirmwareCheckbox.Checked);
     Log("Result: " + VehicleScapeAPI.ResultToString(result));
 }