Пример #1
0
        public bool Acquire()
        {
            // Create a byte array to hold the version information
            var version = new byte[80];

            // Get the version
            TMEX.Get_Version(version);

            // Decode the version
            var sVersion = System.Text.Encoding.Default.GetString(version, 0, version.Length);

            // Strip everything up to the first null character
            sVersion = sVersion.Substring(0, sVersion.IndexOf("\0", StringComparison.Ordinal));

            Tracer.WriteLine("Version: {0}", sVersion);

            Tracer.WriteLine("Starting Aquire");

            // Start a session on the port
            SessionHandle = TMEX.TMExtendedStartSession(PortNumber, PortType, IntPtr.Zero);

            Tracer.WriteLine("TMExtendedStartSession - Return: {0}", SessionHandle);

            // If we didn't get a session then throw an error
            if (SessionHandle <= 0)
            {
                return(false);
            }

            // Setup the port for the current session
            var result = TMEX.TMSetup(SessionHandle);

            Tracer.WriteLine("TMSetup - Return: {0}", result);

            // Check the result
            if (result != 1)
            {
                // Release the session
                Release();

                return(false);
            }

            // Create the network object and pass ourself as the session
            Network = new Network(this);

            // Initialize the network
            Network.Initialize();

            // Initialize the static adapter code with the session
            Adapter.Initialize(this);

            return(true);
        }
Пример #2
0
        public Session()
        {
            // Create the global state buffer
            StateBuffer = new byte[(int)TMEX.StateBufferSize.NoEpromWriting];

            short portNumber;
            short portType;

            // Get the default port number and type from the system
            var result = TMEX.TMReadDefaultPort(out portNumber, out portType);

            PortNumber = portNumber;
            PortType   = portType;

            Tracer.WriteLine("TMReadDefaultPort - Return: {0}, Port Number: {1}, Port Type: {2}", result, PortNumber, PortType);
        }
Пример #3
0
        public void Release()
        {
            Tracer.WriteLine("Starting Release");

            // Terminate the network
            if (Network != null)
            {
                Network.Terminate();
                Network = null;
            }

            // Close the session
            var result = TMEX.TMClose(SessionHandle);

            Tracer.WriteLine("TMClose - Return: {0}", result);

            // End the session
            result = TMEX.TMEndSession(SessionHandle);

            Tracer.WriteLine("TMEndSession - Return: {0}", result);

            // Clear the session variable
            SessionHandle = 0;
        }
Пример #4
0
        private void LoadDevices()
        {
            // Get the first device on the network
            var nResult = TMEX.TMFirst(_session.SessionHandle, _session.StateBuffer);

            // Keep looping while we get good device data
            while (nResult == 1)
            {
                // Create a new device ID buffer
                var id = new short[8];

                // Get the ROM from the device
                nResult = TMEX.TMRom(_session.SessionHandle, _session.StateBuffer, id);

                // If the ROM was read correctly then add the device to the list
                if (nResult == 1)
                {
                    // Get the deviceID
                    var deviceId = new Identifier(id);

                    // Create a new device object
                    Device device;

                    switch (deviceId.Family)
                    {
                    case 0x10:
                        device = new DeviceFamily10(_session, id);
                        break;

                    case 0x1D:
                        device = new DeviceFamily1D(_session, id);
                        break;

                    case 0x20:
                        device = new DeviceFamily20(_session, id);
                        break;

                    case 0x26:
                        device = new DeviceFamily26(_session, id);
                        break;

                    case 0x12:
                        device = new DeviceFamily12(_session, id);
                        break;

                    case 0xFF:
                        device = new DeviceFamilyFF(_session, id);
                        break;

                    default:
                        device = new Device(_session, id);
                        break;
                    }

                    // Check if we've seen this device before
                    if (!Devices.ContainsKey(device.Id.Name))
                    {
                        // Add the device to the device list
                        Devices[device.Id.Name] = device;

                        // Raise the device added event
                        if (DeviceAdded != null)
                        {
                            DeviceAdded(device);
                        }
                    }
                }

                // Try to get the next device
                nResult = TMEX.TMNext(_session.SessionHandle, _session.StateBuffer);
            }
        }