Jump to content

Custom Drivers

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
Ok, First I'm normally a VB Programmer, so please take it easy :)

I've got some Custom Hardware (DAQ Cards, GPIB Cards & External Hardware) that makes a "Package" of Hardware for a Tester.

Right now The Customer Interfaces with it via an Application & the GPIB Card.

Well they wish to reduce it down to 1 computer & talk directly with the "Package"

So I'm thinking that a "Driver" would be the best way.

So....

I've got a basic "DLL" written in C# that can control the system, and this works, but I don't Trust the End user to load it in time, send the Startup Commands in Order ect...

So What I'm wondering is How to make this DLL a "Driver" that will
1) Load when Windows First Starts (XP/Vista & Maybe Windows 7)
2) Call my Initialization code when Windows Starts
3) Allow them to Access the Public Commands.

Super Simple Example
My Start up Code right now for the Public portion of the DLL is

using System;

using System.Collections.Generic;

using System.Text;

using System.IO;

namespace Main

{

    /// <summary>

    /// This project will allow for an easy interface between the Main software and Hardware

    /// </summary>

    public class Package

    {

        /// <summary>

        /// Returns String of Systems Status or what the Last Recorded Error was

        /// </summary>

        public static string System_Status { set { Global.SStatus = value; } get { return Global.SStatus; } }


        /// <summary>

        /// Enable or Disable System Debugging, if Enabled no GPIB Commands are used, and the DAQ Card is ignored.

        /// All Data returned will either be 0 or ransom noise data

        /// </summary>

        public bool Enable_Debug { set { Global.DebuggingSystem = value; } get { return Global.DebuggingSystem; } }


        /// <summary>

        /// Opens Configuration File, Sets up Inital Log File

        /// </summary>

        /// <returns>

        /// Returns True if Files Processed Correctly or Returns Error in Global.SYSTEM_ERROR

        /// </returns>

        public bool Setup()

        {

            Global.SStatus = "Starting Up";

            Global.Logfile = new FileStream("Log.txt", FileMode.Append, FileAccess.Write);

            Global.LogWriter = new StreamWriter(Global.Logfile);

            Global.System_Abort = false;


            if (Global.DebuggingSystem == true) { }

            else

            {

                if (Master.OpenConfigFile("QSTConfig.cfg") == true)

                {

                    Global.SStatus = "Config File Loaded";

                    Global.System_Level = 1;

                }

                else

                {

                    Global.SStatus = "Configuration File Error";

                    Global.Add_Log(Global.SStatus);

                    Global.SYSTEM_ERROR = Global.SStatus;

                    Global.System_Abort = true;

                }

            }

            if (Global.System_Abort == true)

            { return false; }

            else

            { return true; }

        }


        /// <summary>

        /// Initilize the Tester Hardware, Sensors, And Digital System

        /// </summary>

        /// <returns>True if No Error, otherwise their's an error that can be checked with Global.SYSTEM_ERROR </returns>

        public bool Initilize()

        {

            SetupDAQ.SetupDAQ();


            if (Global.DebuggingSystem == true)

            {

                Global.System_Level = 3;

                return true;

            }

            else

            {

                if (Global.System_Level == 2)

                {

                    Global.Add_Log("Setting Up HALL Sensor");

                    Hal.InitilizeSensor(Global.Hal1Address, Global.Hal2Address);

                    if (Global.System_Abort == true) { System_Status = Global.SYSTEM_ERROR; }

                    if (Global.System_Abort == false)

                    {

                        Global.Add_Log("Setting Up Keithley");

                        if (Global.System_Abort == true) { System_Status = Global.SYSTEM_ERROR; }

                        QSTDriver.TurnOnHardware();

                    }

                    if (Global.System_Abort == false)

                    {

                        Global.System_Level = 3;

                        return true;

                    }

                    else

                    {

                        return false;

                    }

                }

                else

                {

                    Global.SYSTEM_ERROR = "ERROR GPIB NOT SET";

                    System_Status = Global.SYSTEM_ERROR;

                    return false;

                }

            }

        }


        /// <summary>

        /// Main Function to Run Hardware

        /// </summary>

        /// <param name="Command">RUNTEST RSTATUS</param>

        /// <param name="Parameters">Test Settings for Requested Test</param>

        /// <param name="ZMAT">True or False as to if we Hold the Magnet at the last Poing or return the Magnet to 0 Oe</param>

        /// <returns>Returns String Sequence Containg Either Test Results or Error Discription</returns>

        public string[] MainFunction(string Command, string Parameters, bool ZMAT)

        {

            string[] TestSequence;

            string[] MainReturn; MainReturn = "No Data".Split(',');

            Global.Zero_Magnet_After_Test = ZMAT;       // ZMAT = Zero Magnet After Test.

            if (Command.Length > 10) { Command = Command.Substring(0, 10); }

            Command = Command.ToUpper();

            if (Global.System_Level == 3)

            {

                switch (Command)

                {

                    case "RUNTEST":

                        Global.Abort_Test = false;

                        TestSequence = Parameters.Split(',');

                        if (Master.Test_Site(TestSequence) == true)

                        { MainReturn = DataParsing.Send_Data(); }

                        else

                        { MainReturn = "Test Aborted".Split(','); }

                        break;

                    case "RSTATUS":

                        // This will have to become its own command as RSTATUS wouldnt get the "configuration" or the "ZMAT" data :)

                        MainReturn = System_Status.Split(',');

                        break;

                    default:

                        if (Command.Length > 0)

                        {

                            Global.Add_Log("Unknown Command = " + Command);

                            Global.SYSTEM_ERROR = "Unknown Command = " + Command;

                            System_Status = "Unknown Command = " + Command;

                            MainReturn = System_Status.Split(',');

                        }

                        else

                        {

                            Global.Add_Log("Command Missing");

                            Global.SYSTEM_ERROR = "Command Missing";

                            System_Status = "Command Missing";

                            MainReturn = System_Status.Split(',');

                        }

                        break;

                }

            }

            else

            {

                string ReturnError = "Unknown Error";

                if (Global.System_Level == 0) { ReturnError = "SYSTEM NOT STARTED"; }

                if (Global.System_Level == 1) { ReturnError = "GPIB / DAQ CARDS NOT SET"; }

                if (Global.System_Level == 2) { ReturnError = "SYSTEM NOT INITILIZED"; }

                MainReturn = ReturnError.Split(',');

            }

            return MainReturn;

        }


    }

}



#2
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
Ok, the more I think about it, a "Driver" may be overkill.

Is their a tutorial on creating a Service that loads when Windows Starts, and allows a DLL to interface with it.

Something like

<MyService> <--> <DLL Interface> <--> <User Application>

This will allow them to restart their Application as much as they want without having my Service Restart the Hardware Everytime.