Esempio n. 1
0
        private bool RunDevice(DeviceRunContext context)
        {
            string path = GetDeviceConfigPath(context.DeviceName, context.Version);

            if (Directory.Exists(path))
            {
                string deviceCfgFile = string.Format("{0}\\{1}", path, DeviceConfigFile);
                // TODO: Config file reading
                if (deviceCfgFile != null)
                {
                    DeviceEntry entry = DeviceEntry.GetDeviceEntry(context.DeviceName, deviceCfgFile);
                    this.CheckVirtualDevice(entry, deviceCfgFile);
                    Device device = Load(entry);
                    if (device != null)
                    {
                        context.Device = device;

                        // Set thread-sync-context
                        device.SynchronizationContext = context.SynchronizationContext;
                        // Set data-received callback
                        device.DataReceived += context.Callback;

                        string address         = this.GetCOMPort(entry);
                        string deviceLoadedStr = string.Format("Device: '{0}' Loaded @ '{1}'", entry[DeviceEntry.Identity], address);
                        RecordManager.DoSystemEventRecord(device, deviceLoadedStr);

                        device.Start(address);
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 2
0
        public bool Run(SynchronizationContext syncCtx, SendOrPostCallback callback)
        {
            foreach (string deviceName in selectedDevices.Keys)
            {
                DeviceRunContext context = this.selectedDevices[deviceName];
                context.SynchronizationContext = syncCtx;
                context.Callback = callback;

                this.RunDevice(context);
            }
            RecordManager.DoSystemEventRecord(Device.Main, "Devices are running now.", RecordType.Event);
            return(true);
        }
Esempio n. 3
0
        private void RescueDevice(string deviceKey)
        {
            DeviceRunContext context = this.selectedDevices[deviceKey];

            if (context != null)
            {
                Device       badDevice         = context.Device;
                const string DeviceWillRestart = "The device will restart now.";
                RecordManager.DoSystemEventRecord(badDevice, DeviceWillRestart);
                if (badDevice != null)
                {
                    badDevice.Stop();
                }
                this.RunDevice(context);
            }
        }
Esempio n. 4
0
        public void CloseAllDevices()
        {
            // Running Devices...
            foreach (string deviceName in selectedDevices.Keys)
            {
                DeviceRunContext context = this.selectedDevices[deviceName];
                if (context != null)
                {
                    Device device = context.Device;
                    if (device != null)
                    {
                        device.Stop();
                    }
                }
            }

            this.selectedDevices.Clear();
        }
Esempio n. 5
0
        public void SendDeviceCode(string deviceKey, string code)
        {
            deviceKey = deviceKey.ToLower();
            if (!this.selectedDevices.ContainsKey(deviceKey))
            {
                MessageBox.Show(string.Format("Not contains device-key = {0}", deviceKey));
                return;
            }

            DeviceRunContext context = this.selectedDevices[deviceKey];

            if (context != null)
            {
                Device device = context.Device;
                device.Send(Encoding.UTF8.GetBytes(code), DateTime.Now);
            }
            else
            {
                MessageBox.Show("Not Found the Running device");
            }
        }
Esempio n. 6
0
        private bool RunDevice(DeviceRunContext context)
        {
            string path = GetDeviceConfigPath(context.DeviceName, context.Version);
            if (Directory.Exists(path))
            {
                string deviceCfgFile = string.Format("{0}\\{1}", path, DeviceConfigFile);
                // TODO: Config file reading
                if (deviceCfgFile != null)
                {
                    DeviceEntry entry = DeviceEntry.GetDeviceEntry(context.DeviceName, deviceCfgFile);
                    this.CheckVirtualDevice(entry, deviceCfgFile);
                    Device device = Load(entry);
                    if (device != null)
                    {
                        context.Device = device;

                        // Set thread-sync-context
                        device.SynchronizationContext = context.SynchronizationContext;
                        // Set data-received callback
                        device.DataReceived += context.Callback;

                        string address = this.GetCOMPort(entry);
                        string deviceLoadedStr = string.Format("Device: '{0}' Loaded @ '{1}'", entry[DeviceEntry.Identity], address);
                        RecordManager.DoSystemEventRecord(device, deviceLoadedStr);

                        device.Start(address);
                        return true;
                    }
                }
            }

            return false;
        }