/// <summary> /// 获取生产线的所有设备集合 /// </summary> /// <param name="strAssemblyLineId"></param> /// <returns></returns> public DeviceInfoCollection GetAssemblyLineDevices(string strAssemblyLineId) { try { DeviceInfoCollection infos = new DeviceInfoCollection(); string strSQL = "select *from v_assemblylinedevices where AssemblyLineId=?AssemblyLineId"; List <MySqlParameter> sqlParameters = new List <MySqlParameter> { new MySqlParameter("?AssemblyLineId", strAssemblyLineId) }; DeviceInfo info = new DeviceInfo(); CreateDataList <DeviceInfo>(infos, strSQL, sqlParameters, info, null); //按设备获取对应的传感器集合 foreach (DeviceInfo item in infos) { string strDeviceId = item.DeviceId; SensorInfoCollection sensors = GetSensorInfos(strDeviceId); item.Sensors = sensors; } return(infos); } catch (Exception ex) { throw ex; } }
private void ProcessDeviceData(string deviceinfo) { string[] devices = deviceinfo.Split( new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries); List <SDBDeviceInfo> deviceInfoList = new List <SDBDeviceInfo>(); DeviceInfoCollection.Clear(); foreach (string item in devices) { string[] onedevice = item.Split(DeviceToken, StringSplitOptions.RemoveEmptyEntries); SDBDeviceInfo devinfo = new SDBDeviceInfo(onedevice[0].TrimEnd(), onedevice[1].TrimEnd(), onedevice[2].TrimEnd()); deviceInfoList.Add(devinfo); DeviceInfoCollection.Add(devinfo.Serial, devinfo); } lock (this.lockDeviceInfoList) { this.deviceInfoList = deviceInfoList; } }
/// <summary> /// Creates an instance of the virtual machine /// </summary> /// <param name="modelKey">The model key of the virtual machine</param> /// <param name="editionKey">The edition key of the virtual machine</param> /// <param name="devices">Devices to create the machine</param> private SpectrumMachine(string modelKey, string editionKey, DeviceInfoCollection devices) { // --- Store model information ModelKey = modelKey; EditionKey = editionKey; // --- Create the engine and set up properties SpectrumVm = new SpectrumEngine(devices); Cpu = new CpuZ80(SpectrumVm.Cpu); var roms = new List <ReadOnlyMemorySlice>(); for (var i = 0; i < SpectrumVm.RomConfiguration.NumberOfRoms; i++) { roms.Add(new ReadOnlyMemorySlice(SpectrumVm.RomDevice.GetRomBytes(i))); } Roms = new ReadOnlyCollection <ReadOnlyMemorySlice>(roms); PagingInfo = new MemoryPagingInfo(SpectrumVm.MemoryDevice); Memory = new SpectrumMemoryContents(SpectrumVm.MemoryDevice, SpectrumVm.Cpu); var ramBanks = new List <MemorySlice>(); if (SpectrumVm.MemoryConfiguration.RamBanks != null) { for (var i = 0; i < SpectrumVm.MemoryConfiguration.RamBanks; i++) { ramBanks.Add(new MemorySlice(SpectrumVm.MemoryDevice.GetRamBank(i))); } } RamBanks = new ReadOnlyCollection <MemorySlice>(ramBanks); Keyboard = new KeyboardEmulator(SpectrumVm); ScreenConfiguration = SpectrumVm.ScreenConfiguration; ScreenRenderingTable = new ScreenRenderingTable(SpectrumVm.ScreenDevice); ScreenBitmap = new ScreenBitmap(SpectrumVm.ScreenDevice); ScreenRenderingStatus = new ScreenRenderingStatus(SpectrumVm); BeeperConfiguration = SpectrumVm.AudioConfiguration; BeeperSamples = new AudioSamples(SpectrumVm.BeeperDevice); BeeperProvider = SpectrumVm.BeeperProvider; SoundConfiguration = SpectrumVm.SoundConfiguration; SoundProvider = SpectrumVm.SoundProvider; AudioSamples = new AudioSamples(SpectrumVm.SoundDevice); Breakpoints = new CodeBreakpoints(SpectrumVm.DebugInfoProvider); // --- Hook device events SpectrumVm.TapeLoadDevice.LoadCompleted += (s, e) => FastLoadCompleted?.Invoke(s, e); SpectrumVm.TapeSaveDevice.LeftSaveMode += (s, e) => LeftSaveMode?.Invoke(s, e); // --- Initialize machine state _clockProvider = GetProvider <IClockProvider>(); _physicalFrameClockCount = _clockProvider.GetFrequency() / (double)SpectrumVm.BaseClockFrequency * ScreenConfiguration.ScreenRenderingFrameTactCount; MachineState = VmState.None; ExecutionCompletionReason = ExecutionCompletionReason.None; }
/// <summary> /// 获取工厂所有生产线上设备集合(简单数据) /// </summary> /// <param name="strAssemblyLineId"></param> /// <returns></returns> public DeviceInfoCollection GetSmallFactoryDevices(string strFactoryId) { try { DeviceInfoCollection infos = new DeviceInfoCollection(); if (!string.IsNullOrEmpty(strFactoryId)) { string strSQL = "select *from v_assemblylinedevices where FactoryId=?FactoryId"; List <MySqlParameter> sqlParameters = new List <MySqlParameter> { new MySqlParameter("?FactoryId", strFactoryId) }; DeviceInfo info = new DeviceInfo(); CreateDataList <DeviceInfo>(infos, strSQL, sqlParameters, info, null); } return(infos); } catch (Exception ex) { throw ex; } }
/// <summary> /// Initializes a class instance using a collection of devices /// </summary> public SpectrumEngine(DeviceInfoCollection deviceData) { DeviceData = deviceData ?? throw new ArgumentNullException(nameof(deviceData)); // --- Check for Spectrum Next var nextInfo = GetDeviceInfo <INextFeatureSetDevice>(); NextDevice = nextInfo?.Device; // --- Prepare the memory device var memoryInfo = GetDeviceInfo <IMemoryDevice>(); MemoryDevice = memoryInfo?.Device ?? new Spectrum48MemoryDevice(); MemoryConfiguration = (IMemoryConfiguration)memoryInfo?.ConfigurationData; // --- Prepare the port device var portInfo = GetDeviceInfo <IPortDevice>(); PortDevice = portInfo?.Device ?? new Spectrum48PortDevice(); // --- Init the CPU var cpuConfig = GetDeviceConfiguration <IZ80Cpu, ICpuConfiguration>(); var mult = 1; if (cpuConfig != null) { BaseClockFrequency = cpuConfig.BaseClockFrequency; mult = cpuConfig.ClockMultiplier; if (mult < 1) { mult = 1; } else if (mult >= 2 && mult <= 3) { mult = 2; } else if (mult >= 4 && mult <= 7) { mult = 4; } else if (mult > 8) { mult = 8; } } ClockMultiplier = mult; Cpu = new Z80Cpu(MemoryDevice, PortDevice, cpuConfig?.SupportsNextOperations ?? false, NextDevice) { UseGateArrayContention = MemoryConfiguration.ContentionType == MemoryContentionType.GateArray }; // --- Init the ROM var romInfo = GetDeviceInfo <IRomDevice>(); RomProvider = (IRomProvider)romInfo.Provider; RomDevice = romInfo.Device ?? new SpectrumRomDevice(); RomConfiguration = (IRomConfiguration)romInfo.ConfigurationData; // --- Init the clock var clockInfo = GetDeviceInfo <IClockDevice>(); Clock = (IClockProvider)clockInfo.Provider ?? throw new InvalidOperationException("The virtual machine needs a clock provider!"); // --- Init the screen device var screenInfo = GetDeviceInfo <IScreenDevice>(); var pixelRenderer = (IScreenFrameProvider)screenInfo.Provider; ScreenConfiguration = new ScreenConfiguration((IScreenConfiguration)screenInfo.ConfigurationData); ScreenDevice = screenInfo.Device ?? new Spectrum48ScreenDevice(); // --- Init the beeper device var beeperInfo = GetDeviceInfo <IBeeperDevice>(); AudioConfiguration = (IAudioConfiguration)beeperInfo?.ConfigurationData; BeeperProvider = (IBeeperProvider)beeperInfo?.Provider; BeeperDevice = beeperInfo?.Device ?? new BeeperDevice(); // --- Init the keyboard device var keyboardInfo = GetDeviceInfo <IKeyboardDevice>(); KeyboardProvider = (IKeyboardProvider)keyboardInfo?.Provider; KeyboardDevice = keyboardInfo?.Device ?? new KeyboardDevice(); // --- Init the interrupt device InterruptDevice = new InterruptDevice(InterruptTact); // --- Init the tape device var tapeInfo = GetDeviceInfo <ITapeDevice>(); TapeProvider = (ITapeProvider)tapeInfo?.Provider; TapeDevice = tapeInfo?.Device ?? new TapeDevice(TapeProvider); // === Init optional devices // --- Init the sound device var soundInfo = GetDeviceInfo <ISoundDevice>(); SoundConfiguration = (IAudioConfiguration)soundInfo?.ConfigurationData; SoundProvider = (ISoundProvider)soundInfo?.Provider; SoundDevice = soundInfo == null ? null : soundInfo.Device ?? new SoundDevice(); // --- Init the DivIDE device var divIdeInfo = GetDeviceInfo <IDivIdeDevice>(); DivIdeDevice = divIdeInfo?.Device; // --- Carry out frame calculations ResetUlaTact(); _frameTacts = ScreenConfiguration.ScreenRenderingFrameTactCount; PhysicalFrameClockCount = Clock.GetFrequency() / (double)BaseClockFrequency * _frameTacts; FrameCount = 0; Overflow = 0; _frameCompleted = true; _lastBreakpoint = null; RunsInMaskableInterrupt = false; // --- Attach providers AttachProvider(RomProvider); AttachProvider(Clock); AttachProvider(pixelRenderer); AttachProvider(BeeperProvider); AttachProvider(KeyboardProvider); AttachProvider(TapeProvider); AttachProvider(DebugInfoProvider); // --- Attach optional providers if (SoundProvider != null) { AttachProvider(SoundProvider); } // --- Collect Spectrum devices _spectrumDevices.Add(RomDevice); _spectrumDevices.Add(MemoryDevice); _spectrumDevices.Add(PortDevice); _spectrumDevices.Add(ScreenDevice); _spectrumDevices.Add(BeeperDevice); _spectrumDevices.Add(KeyboardDevice); _spectrumDevices.Add(InterruptDevice); _spectrumDevices.Add(TapeDevice); // --- Collect optional devices if (SoundDevice != null) { _spectrumDevices.Add(SoundDevice); } if (NextDevice != null) { _spectrumDevices.Add(NextDevice); } if (DivIdeDevice != null) { _spectrumDevices.Add(DivIdeDevice); } // --- Now, prepare devices to find each other foreach (var device in _spectrumDevices) { device.OnAttachedToVm(this); } // --- Prepare bound devices _frameBoundDevices = _spectrumDevices .OfType <IFrameBoundDevice>() .ToList(); _cpuBoundDevices = _spectrumDevices .OfType <ICpuOperationBoundDevice>() .ToList(); DebugInfoProvider = new SpectrumDebugInfoProvider(); // --- Init the ROM InitRom(RomDevice, RomConfiguration); }
/// <summary> /// Initializes a class instance using a collection of devices /// </summary> public SpectrumEngine(DeviceInfoCollection deviceData, string ulaIssue = "3") { DeviceData = deviceData ?? throw new ArgumentNullException(nameof(deviceData)); UlaIssue = ulaIssue == "3" ? "3" : "2"; // --- Prepare the memory device var memoryInfo = GetDeviceInfo <IMemoryDevice>(); MemoryDevice = memoryInfo?.Device ?? new Spectrum48MemoryDevice(); MemoryConfiguration = (IMemoryConfiguration)memoryInfo?.ConfigurationData; // --- Prepare the port device var portInfo = GetDeviceInfo <IPortDevice>(); PortDevice = portInfo?.Device ?? new Spectrum48PortDevice(); // --- Init the CPU var cpuConfig = GetDeviceConfiguration <IZ80Cpu, ICpuConfiguration>(); var mult = 1; if (cpuConfig != null) { BaseClockFrequency = cpuConfig.BaseClockFrequency; mult = cpuConfig.ClockMultiplier; if (mult < 1) { mult = 1; } else if (mult >= 2 && mult <= 3) { mult = 2; } else if (mult >= 4 && mult <= 7) { mult = 4; } else if (mult > 8) { mult = 8; } } ClockMultiplier = mult; Cpu = new Z80Cpu(MemoryDevice, PortDevice, cpuConfig?.SupportsNextOperations ?? false) { UseGateArrayContention = MemoryConfiguration.ContentionType == MemoryContentionType.GateArray }; // --- Init the ROM var romInfo = GetDeviceInfo <IRomDevice>(); RomProvider = (IRomProvider)romInfo.Provider; RomDevice = romInfo.Device ?? new SpectrumRomDevice(); RomConfiguration = (IRomConfiguration)romInfo.ConfigurationData; // --- Init the screen device var screenInfo = GetDeviceInfo <IScreenDevice>(); var pixelRenderer = (IScreenFrameProvider)screenInfo.Provider; ScreenConfiguration = new ScreenConfiguration((IScreenConfiguration)screenInfo.ConfigurationData); ScreenDevice = screenInfo.Device ?? new Spectrum48ScreenDevice(); ShadowScreenDevice = new Spectrum48ScreenDevice(); // --- Init the beeper device var beeperInfo = GetDeviceInfo <IBeeperDevice>(); AudioConfiguration = (IAudioConfiguration)beeperInfo?.ConfigurationData; BeeperProvider = (IBeeperProvider)beeperInfo?.Provider; BeeperDevice = beeperInfo?.Device ?? new BeeperDevice(); // --- Init the keyboard device var keyboardInfo = GetDeviceInfo <IKeyboardDevice>(); KeyboardProvider = (IKeyboardProvider)keyboardInfo?.Provider; KeyboardDevice = keyboardInfo?.Device ?? new KeyboardDevice(); // --- Init the Kempston device var kempstonInfo = GetDeviceInfo <IKempstonDevice>(); KempstonProvider = (IKempstonProvider)kempstonInfo?.Provider; KempstonDevice = kempstonInfo?.Device ?? new KempstonDevice(); // --- Init the interrupt device InterruptDevice = new InterruptDevice(InterruptTact); // --- Init the tape device var tapeSaveInfo = GetDeviceInfo <ITapeSaveDevice>(); TapeSaveProvider = (ITapeSaveProvider)tapeSaveInfo?.Provider; var tapeLoadInfo = GetDeviceInfo <ITapeLoadDevice>(); TapeLoadProvider = (ITapeLoadProvider)tapeLoadInfo?.Provider; var tapeDevice = new TapeDevice(TapeLoadProvider, TapeSaveProvider); TapeLoadDevice = tapeDevice; TapeSaveDevice = tapeDevice; // === Init optional devices // --- Init the sound device var soundInfo = GetDeviceInfo <ISoundDevice>(); SoundConfiguration = (IAudioConfiguration)soundInfo?.ConfigurationData; SoundProvider = (ISoundProvider)soundInfo?.Provider; SoundDevice = soundInfo == null ? null : soundInfo.Device ?? new SoundDevice(); // --- Init the floppy device var floppyInfo = GetDeviceInfo <IFloppyDevice>(); if (floppyInfo != null) { FloppyDevice = floppyInfo.Device; FloppyConfiguration = (IFloppyConfiguration)floppyInfo.ConfigurationData ?? new FloppyConfiguration(); } // --- Carry out frame calculations ResetUlaTact(); FrameTacts = ScreenConfiguration.ScreenRenderingFrameTactCount; FrameCount = 0; Overflow = 0; HasFrameCompleted = true; _lastBreakpoint = null; // --- Attach providers AttachProvider(RomProvider); AttachProvider(pixelRenderer); AttachProvider(BeeperProvider); AttachProvider(KeyboardProvider); AttachProvider(KempstonProvider); AttachProvider(TapeLoadProvider); AttachProvider(DebugInfoProvider); // --- Attach optional providers if (SoundProvider != null) { AttachProvider(SoundProvider); } // --- Collect Spectrum devices _spectrumDevices.Add(RomDevice); _spectrumDevices.Add(MemoryDevice); _spectrumDevices.Add(PortDevice); _spectrumDevices.Add(ScreenDevice); _spectrumDevices.Add(ShadowScreenDevice); _spectrumDevices.Add(BeeperDevice); _spectrumDevices.Add(KeyboardDevice); _spectrumDevices.Add(KempstonDevice); _spectrumDevices.Add(InterruptDevice); _spectrumDevices.Add(TapeLoadDevice); // --- Collect optional devices if (SoundDevice != null) { _spectrumDevices.Add(SoundDevice); } if (FloppyDevice != null) { _spectrumDevices.Add(FloppyDevice); } // --- Now, prepare devices to find each other foreach (var device in _spectrumDevices) { device.OnAttachedToVm(this); } // --- Prepare bound devices _frameBoundDevices = _spectrumDevices .OfType <IRenderFrameBoundDevice>() .ToList(); _cpuBoundDevices = _spectrumDevices .OfType <ICpuOperationBoundDevice>() .ToList(); DebugInfoProvider = new SpectrumDebugInfoProvider(); // --- Init the ROM InitRom(RomDevice, RomConfiguration); }
/// <summary> /// 生产线启动生产流程 /// </summary> /// <param name="strAssemblyLineId"></param> public void StartProcess(string strAssemblyLineId, string strCreateUser, DeviceAction deviceAction) { try { //读取生产线数据 DataHelper dataHelper = new DataHelper(); DataLogHelper logHelper = new DataLogHelper(); AssemblyLineInfo assembly = dataHelper.GetAssemblyLine(strAssemblyLineId); //线程休眠的基础单位 int iSleepUnit = 1000; if (assembly != null) { //获取生产线的所有设备信息 DeviceInfoCollection devices = dataHelper.GetAssemblyLineDevices(strAssemblyLineId); //获取相应的工艺流程信息 TechnologicalProcess process = dataHelper.GetTechnologicalProcess(assembly.ProcessId); DateTime dtMainStart = DateTime.Now; #region 主工艺流程日志记录 ProcessLog proLog = new ProcessLog() { AssemblyLineId = strAssemblyLineId, ProcessId = process.ProcessId, Created = DateTime.Now, CreateUser = strCreateUser, ProcessStatus = SysHelper.Enums.ProcessStatusType.Start, ProduceMaterialType = SysHelper.Enums.MaterialTypeEnum.Z, Production = decimal.Zero, TakeTime = 0 }; logHelper.AddMainProcessLog(proLog); #endregion //子工艺流程步骤数量 int iExProcessNum = 3; #region 工艺子流程循环 for (int iExIndex = 1; iExIndex <= iExProcessNum; iExIndex++) { //提取子工艺流程审批环节 TeExProcess exProcess = dataHelper.GetTeExProcess(process.ProcessId, iExIndex); if (exProcess != null) { //子工艺开始时间 DateTime dtExStart = DateTime.Now; #region 子工艺流程日志记录 ExProcessLog exLog = new ExProcessLog() { ProcessLogId = proLog.ProcessLogId, ExProcessId = exProcess.ExProcessId, Created = DateTime.Now, CreateUser = strCreateUser, ProcessStatus = SysHelper.Enums.ProcessStatusType.Start, ProduceMaterialType = SysHelper.Enums.MaterialTypeEnum.Z, Production = decimal.Zero, TakeTime = 0 }; //先记录数据 logHelper.AddExProcessLog(exLog); #endregion //是否达到启动条件 bool isStartExProcess = false; #region 判断启动的设备参数是否达到启动条件 DeviceProduceLog deviceLog = logHelper.GetDeviceProduceLog(exProcess.StartDeviceId, exProcess.ParType); if (deviceLog != null) { if (deviceLog.ParValue.Value >= exProcess.ParValue) { isStartExProcess = true; } } //循环等待达到启动条件 while (!isStartExProcess) { //每个循环先暂停10秒 int iStartSleep = iSleepUnit * 10; System.Threading.Thread.Sleep(iStartSleep); deviceLog = logHelper.GetDeviceProduceLog(exProcess.StartDeviceId, exProcess.ParType); if (deviceLog != null) { if (deviceLog.ParValue.Value >= exProcess.ParValue) { isStartExProcess = true; } } } #endregion if (isStartExProcess) { #region 循环启动设备 foreach (ExProcessStep step in exProcess.Steps) { //先找到需要操作的设备 foreach (DeviceInfo device in devices) { if (device.ProcessDeviceId == step.ProcessDeviceId) { string strDeviceId = device.DeviceId; //定义设备的操作类型 //提取步骤的参数控制数 foreach (ExProcessStepPars par in step.StepPars) { #region 记录操作的日志 DeviceActionLog actionLog = new DeviceActionLog() { DeviceId = strDeviceId, Created = DateTime.Now, CreateUser = strCreateUser, SensorId = par.SensorId, ActionType = par.ActionType, ParType = par.ParType, ParUnit = par.ParUnit, ParValue = par.ParValue, ToDeviceId = string.Empty, ToSensorId = string.Empty }; logHelper.AddDeviceActionLog(actionLog); #endregion //将操作放入委托里面进行执行(步骤执行完成才执行后续步骤) if (deviceAction(strDeviceId, par.SensorId, par.ActionType, par.ParType, par.ParValue)) { //判断是否需要等待 if (par.ParTime > 0) { int iSleepSet = par.ParTime * 60 * iSleepUnit; System.Threading.Thread.Sleep(iSleepSet); } //判断是否是完成参数 if (par.IsFinish) { } } } break; } } } #endregion } //子工艺完成时间 DateTime dtExEnd = DateTime.Now; TimeSpan tSpan = dtExEnd - dtExStart; //得到子工艺完成花费的分钟 exLog.TakeTime = Convert.ToInt32(tSpan.TotalMinutes); exLog.FinishTime = dtExEnd; exLog.ProcessStatus = SysHelper.Enums.ProcessStatusType.End; //exLog.ProduceMaterialType = SysHelper.Enums.MaterialTypeEnum. logHelper.UpdateExProcessLog(exLog); } } #endregion DateTime dtMainEnd = DateTime.Now; TimeSpan mSpan = dtMainEnd - dtMainStart; proLog.TakeTime = Convert.ToInt32(mSpan.TotalMinutes); proLog.FinishTime = dtMainEnd; proLog.ProcessStatus = SysHelper.Enums.ProcessStatusType.End; logHelper.UpdateMainProcessLog(proLog); } } catch (Exception ex) { throw ex; } }