Esempio n. 1
0
        public void GetDriverTypes()
        {
            Console.WriteLine("GetDriverTypes");
            Console.WriteLine($"[Loader Device Types]");
            foreach (var v in DriverLoader.DriverTypes)
            {
                Assert.IsNotNull(v, "Check DriverType not null");
                Console.WriteLine($"Driver: {v.FullName}'");

                Console.WriteLine($"IsInterface: {v.IsInterface}'");
                Assert.IsFalse(v.IsInterface, "Check driver type is not interface");

                Type ifType = DriverLoader.InterfaceFor(v);
                Console.WriteLine($"Interface: {ifType?.FullName}'");
                Assert.IsNotNull(ifType, "Check InterfaceType");

                Type apiType = DriverLoader.ApiTypeFor(v);
                Console.WriteLine($"API Type: {apiType?.FullName}'");
                Assert.IsNotNull(apiType, "Validate APIType");

                AssemblyName aName = v.Assembly?.GetName();
                Assert.IsNotNull(aName, "Validate DriverType Assembly");
                Console.WriteLine($"Assembly: {aName.FullName}'");
                Console.WriteLine($"Codebase: {aName.CodeBase}'");
                Console.WriteLine($"--------------------------");
                Console.WriteLine();
            }
        }
        static void Main(string[] args)
        {
            //Change these to load correct driver and connect it to correct bus
            string   driver  = "can_usb_win32";
            string   bus     = "COM4";
            BUSSPEED bitrate = BUSSPEED.BUS_500Kbit;


            try
            {
                DriverLoader   loader   = new DriverLoader();
                DriverInstance instance = loader.loaddriver(driver);

                Console.WriteLine("Opening CAN device ");
                instance.open(bus, bitrate);

                instance.rxmessage += Instance_rxmessage;
                Console.WriteLine("listening for any traffic, press any key to exit ..");
                while (!Console.KeyAvailable)
                {
                }

                instance.close();
            }
            catch (Exception e)
            {
                Console.WriteLine("That did not work out, exception message was \n" + e.ToString());
            }

            Console.WriteLine("Press any key to exit");

            while (!Console.KeyAvailable)
            {
            }
        }
 public DeviceTemplateController(
     SystemHelper sysHelper,
     UserManager <RaciUser> userManager,
     SignInManager <RaciUser> signInManager,
     ILogger logger)
     : base(sysHelper, userManager, signInManager, logger)
 {
     ControllerId = Guid.NewGuid().ToString();
     DriverType   = DriverLoader.ApiTypeFor(typeof(TDriver)).Name;
 }
Esempio n. 4
0
 public void DriverImplementationInstanceTests()
 {
     Console.WriteLine("DriverImplementationInstanceTests");
     DriverLoaderInit();
     foreach (var dt in DriverLoader.DriverTypes)
     {
         Console.WriteLine($"Creating instance of '{dt.FullName}'");
         var iInst = DriverLoader.GetImplementation(dt);
         Assert.IsNotNull(iInst, "Validate IAscomDriver reference");
         var cInst = Convert.ChangeType(iInst, dt);
         Assert.IsNotNull(cInst, $"Validate converted reference ({cInst})");
     }
 }
Esempio n. 5
0
 public void DriverApiInstanceTests()
 {
     Console.WriteLine("DriverApiInstanceTests");
     DriverLoaderInit();
     foreach (var dt in DriverLoader.DriverTypes)
     {
         Type apiType = DriverLoader.ApiTypeFor(dt);
         Console.WriteLine($"Creating instance of '{apiType.FullName}'");
         var iInst = DriverLoader.GetApiDriver(dt);
         Assert.IsNotNull(iInst, "Validate IAscomDriver reference");
         var cInst = Convert.ChangeType(iInst, apiType);
         Assert.IsNotNull(cInst, $"Validate converted reference ({cInst})");
     }
 }
        protected TDriver createDevice(string devName)
        {
            TDriver result = null;

            lock (driverSync)
            {
                if (Drivers.ContainsKey(devName))
                {
                    result = Drivers[devName];
                }
                else
                {
                    result = DriverLoader.GetImplementation <TDriver>(devName);
                    if (result == null)
                    {
                        throw new DriverException($"Unable to create a driver instance for {devName} (DeviceType={DriverType})");
                    }
                    Drivers.Add(devName, result);
                }
            }
            return(result);
        }
Esempio n. 7
0
        public void Dispose()
        {
            if (this.V2DriverLoader != null)
            {
                if (this.V2DriverLoader.PortIsOpen)
                {
                    this.V2DriverLoader.ClosePort();
                }

                if (this.V2DriverLoader.DriverIsLoaded)
                {
                    this.V2DriverLoader.UnloadDriver();
                }

                this.V2DriverLoader = null;
            }

            if (this.ControlsAvailable != null)
            {
                this.ControlsAvailable = null;
            }
        }
 protected TDriver createDevice(string devName) => DriverLoader.GetImplementation <TDriver>(devName);
Esempio n. 9
0
 public void DriverLoaderInit()
 {
     Console.WriteLine("DriverLoaderInit");
     CleanDriverSection();
     DriverLoader.Init();
 }
Esempio n. 10
0
        public void ScanSerialPortsForV2Overlay(OverlayControlClass v2OverlayControl)
        {
            if (v2OverlayControl == null ||
                v2OverlayControl.UsesV2DriverLoader == false ||
                File.Exists(@"C:\Program Files\InspectIT\Drivers\overlay.dll") == false)
            {
                return;
            }

            string[] validPorts = System.IO.Ports.SerialPort.GetPortNames();

            if (validPorts.Length == 0)
            {
                return;
            }

            if (this.V2DriverLoader == null)
            {
                this.V2DriverLoader = new DriverLoader();
                this.V2DriverLoader.DriverDirectory = @"C:\Program Files\InspectIT\Drivers";
                this.V2DriverLoader.ScanDriverDirectory();
            }

            try {
                this.V2DriverLoader.LoadDriver(v2OverlayControl.OverlayName);
            }
            catch (Exception ex) {
                MessageBox.Show("Error encountered loading driver: '" + v2OverlayControl.OverlayName + "'\n\nSpecific Error: " + ex.Message);
            }

            if (this.V2DriverLoader.DriverIsLoaded == true)
            {
                for (int i = 0; i < validPorts.Length; i++)
                {
                    string curPort = validPorts[i];

                    //Handle if it's an LPT (or otherwise non-COM) port:
                    if (curPort.Contains("COM") == false)
                    {
                        continue;
                    }

                    this.V2DriverLoader.PortId = int.Parse(curPort.Replace("COM", ""));

                    try {
                        if (this.V2DriverLoader.PortIsOpen)
                        {
                            this.V2DriverLoader.ClosePort();
                        }
                        this.V2DriverLoader.OpenPort();
                        float tempTestFloat = this.V2DriverLoader.GetCounter(1);
                        V2DriverLoader.ClosePort();

                        if (tempTestFloat.Equals(float.NaN) == false)
                        {
                            this.OverlayPort = V2DriverLoader.PortId;
                            this.LateralPort = V2DriverLoader.PortId + 1;

                            return;
                        }
                    }
                    catch (Exception ex) {
                        //This violates single-responsibility, but I'm allowing this to show a messagebox because the port may be locked by another process, or it may have a driver-level issue
                        //I've seen ports which claim they don't exist when I scan them, even though Windows says they exist. I'd rather these ports don't prevent scanning the other ports.
                        MessageBox.Show("Error encountered scanning port " + V2DriverLoader.PortId.ToString() + "\n\nSpecific Error: " + ex.Message);
                    }
                    finally {
                        this.V2DriverLoader.ClosePort();
                        this.V2DriverLoader.UnloadDriver();
                        this.V2DriverLoader.PortId = -1;
                    }
                }
            }
        }
Esempio n. 11
0
        public OverlaySettings(DataRow curSettingsRow, string itpipesDriversDirectory = @"C:\Program Files\InspectIT\Drivers")
        {
            this.ControlsAvailable = new ObservableCollection <OverlayControlClass>();

            string[] availableV2OverlayDrivers = null;

            if (File.Exists(Path.Combine(itpipesDriversDirectory, "overlay.dll")))
            {
                this.V2DriverLoader = new DriverLoader();
                this.V2DriverLoader.DriverDirectory = itpipesDriversDirectory;
                availableV2OverlayDrivers           = this.V2DriverLoader.ScanDriverDirectory();

                if (availableV2OverlayDrivers.Contains("PCI4E") == false)
                {
                    this.addOverlayToOverlayList("US Digital", false);
                }
                if (availableV2OverlayDrivers.Contains("QSB") == false)
                {
                    this.addOverlayToOverlayList("QSB", false);
                }
                if (availableV2OverlayDrivers.Contains("USB4") == false)
                {
                    this.addOverlayToOverlayList("USB4", false);
                }

                foreach (string curOverlay in availableV2OverlayDrivers)
                {
                    this.addOverlayToOverlayList(curOverlay);
                }
            }
            else
            {
                this.addOverlayToOverlayList("US Digital", false);
                this.addOverlayToOverlayList("QSB", false);
                this.addOverlayToOverlayList("USB4", false);
                this.addOverlayToOverlayList("Aries", false);
                this.addOverlayToOverlayList("Aries5000", false);
                this.addOverlayToOverlayList("IBAK", false);
                this.addOverlayToOverlayList("IPEK_DE03SW", false);
            }


            if ((bool)curSettingsRow["Counter_Enabled"] == true ||
                (curSettingsRow.Table.Columns.Contains("CounterV2_Enabled") && (bool)curSettingsRow["CounterV2_Enabled"] == true))
            {
                this.IsOverlayEnabled = true;
            }

            //Ports:
            if (curSettingsRow.Table.Columns.Contains("CounterV2_Enabled") &&
                (bool)curSettingsRow["CounterV2_Enabled"] == true &&
                curSettingsRow.Table.Columns.Contains("CounterV2_Port") &&
                curSettingsRow["CounterV2_Port"] != DBNull.Value)
            {
                this.OverlayPort = int.Parse((string)curSettingsRow["CounterV2_Port"]); //no idea why this is a string in the database.
            }
            else
            {
                this.OverlayPort = (curSettingsRow["Counter_Port"] == DBNull.Value) ? (int?)null : int.Parse((string)curSettingsRow["Counter_Port"]); //no idea why this is a string in setup.mdb either. *shrug*
            }

            this.LateralPort = (curSettingsRow["Counter_Lateral_Port"] == DBNull.Value) ? (int?)null : (int?)curSettingsRow["Counter_Lateral_Port"];

            if (curSettingsRow.Table.Columns.Contains("RST_Inclinometer_Port"))
            {
                this.InclinometerPort = (curSettingsRow["RST_Inclinometer_Port"] == DBNull.Value) ? (int?)null : (int)curSettingsRow["RST_Inclinometer_Port"];
            }

            //Calibrations:
            this.MainlineCalibration = (curSettingsRow["Counter_Calibration"] == DBNull.Value) ? (float?)null : (float)curSettingsRow["Counter_Calibration"];
            this.LateralCalibration  = (curSettingsRow["Counter_Lateral_Calibration"] == DBNull.Value) ? (float?)null : (float)curSettingsRow["Counter_Lateral_Calibration"];
        }