示例#1
0
        /// <summary>
        /// 读取所有的线圈
        /// </summary>
        /// <param name="Length">在使用的线圈的总长度</param>
        private void ReadAllCoil(int Length = 10)
        {
            InputModule input = new InputModule();

            input.bySlaveID   = m_SlaveID;
            input.byFunction  = Modbus.byREAD_COIL;
            input.nStartAddr  = Coil.PLCStartAddr;
            input.nDataLength = Length;

            OutputModule rev = m_Modbus.SendMessage_Sync(input);

            if ((rev == null) || (rev.byFunction != input.byFunction))
            {
                throw new Exception("通信异常,读取所有所有线圈失败!");
            }

            int    rev_DataLength = rev.byRecvData[2];//读取到的数据长度
            string binary         = string.Empty;;

            for (int i = 0; i < rev_DataLength; i++)
            {
                int    Decimal = rev.byRecvData[3 + i];                        //已经为十进制
                string temp    = Convert.ToString(Decimal, 2).PadLeft(8, '0'); //十进制转二进制
                binary += myFunction.StrReverse(temp);
            }

            this.Coils.SetBitDatasValue(binary);//直接修改线圈的值
        }
        /// <summary>
        /// Start the capture process
        /// </summary>
        public void StartCapture()
        {
            //--Start Capture immediately
            //--create the processing pipeline
            this.capturePipeline = new BackgroundPipeline <CaptureFrame>(Settings.Default.WIIFrequencyHz);

            this.captureStartTime = DateTime.Now;

            this.incrementTrialNumber();

            this.captureFileName = Settings.Default.TrialName;

            this.CaptureTime = TimeSpan.Zero;

            this.dataOutputModule = new OutputModule {
                IsEnabled = true
            };
            this.capturePipeline.Modules.Add(this.dataOutputModule);

            // setup and start the capture
            this.waitingForCapturePipeline = false;

            this.QueueCount = 0;
            this.FrameCount = 0;
            this.capturePipeline.Timer.Tick += Timer_Tick;
            this.capturePipeline.Start();
            this.CaptureInProgress = true;

            Debug.WriteLine("Capture started.");
            SystemMessage.Send("Capture Started - " + Path.Combine(Properties.Settings.Default.SubjectName, this.captureFileName));
        }
示例#3
0
 public void AddModule(OutputModule key, IOutputModule value)
 {
     if (!Configuration.Logger.OutputModules.ContainsKey(key))
     {
         Configuration.Logger.OutputModules.Add(key, value);
     }
 }
示例#4
0
 public bool SendMsg(HoldingRegister register, int Value)
 {
     try
     {
         InputModule input = new InputModule();
         input.nStartAddr  = register.Addr;
         input.nDataLength = register.Size;
         if (register.Size > 1)
         {
             input.byFunction  = Modbus.byWRITE_MULTI_HOLDING_REG;
             input.byWriteData = ModbusTool.HostToNetOrder32(Value);
         }
         else
         {
             input.byFunction  = Modbus.byWRITE_SINGLE_HOLDING_REG;
             input.byWriteData = ModbusTool.HostToNetOrder16((short)Value);
         }
         OutputModule rev = null;
         rev = m_Modbus.SendMessage_Sync(input);
         if ((rev == null) || (rev.byFunction != input.byFunction))
         {
             throw new Exception("发送寄存器消息通信异常!");
         }
         else
         {
             return(true);
         }
     }
     catch (Exception ex)
     {
         log.AddERRORLOG("发送寄存器信息异常:" + ex.Message);
         return(false);
     }
 }
示例#5
0
        /// <summary>
        /// 读取所有的线圈
        /// </summary>
        /// <param name="mode">位状态读取 1:位状态输出;2:位状态读写</param>
        /// <param name="startAddr">线圈起始位置</param>
        /// <param name="Length">在使用的线圈的总长度</param>
        private void ReadAllCoil(int mode, int startAddr, int Length = 10)
        {
            InputModule input = new InputModule();

            input.bySlaveID = m_SlaveID;
            if (mode == 1)
            {
                input.byFunction = Modbus.byREAD_DISCRETE_INPUTS;
            }
            if (mode == 2)
            {
                input.byFunction = Modbus.byREAD_COIL;
            }

            input.nStartAddr  = startAddr;
            input.nDataLength = Length;

            OutputModule rev = m_Modbus.SendMessage_Sync(input);

            if ((rev == null) || (rev.byFunction != input.byFunction))
            {
                throw new Exception("通信异常,读取所有所有线圈失败!");
            }
            this.Coils.AllowRun.Value = rev.byRecvData[9] == 0;
        }
示例#6
0
        private bool SendListMsg(InputModule input)
        {
            OutputModule rev = m_Modbus.SendMessage_Sync(input);

            if ((rev == null) || (rev.byFunction != input.byFunction))
            {
                throw new Exception("发送消息队列 通信异常!");
            }
            else
            {
                return(true);
            }
        }
示例#7
0
        private bool SendListMsg(InputModule input)
        {
            OutputModule rev = m_Modbus.SendMessage_Sync(input);

            if ((rev == null) || (rev.byFunction != input.byFunction))
            {
                throw new Exception("发送消息队列 通信异常!");
            }
            else
            {
                //  log.AddERRORLOG("发送数据成功:" + input.byWriteData.ToString());
                return(true);
            }
        }
        public CaptureViewModel(ViewModelLocator locator)
        {
            this.CaptureInProgress = false;

            this.WIILeftViewModel  = locator.WIIViewModelLeft;
            this.WIIRightViewModel = locator.WIIViewModelRight;

            this.CaptureCommand    = new RelayCommand(this.StartCapture, () => this.CanCapture);
            this.EndCaptureCommand = new RelayCommand(this.EndCapture, () => this.CanEndCapture);

            this.ConnectWIICommand    = new RelayCommand(() => this.ConnectWII());
            this.CaptureWeightCommand = new RelayCommand(() => this.CaptureWeight());

            this.dataOutputModule = new OutputModule();
        }
示例#9
0
 public void ReadCoil()
 {
     try
     {
         InputModule input = new InputModule();
         input.bySlaveID   = m_SlaveID;
         input.byFunction  = Modbus.byREAD_COIL;
         input.nStartAddr  = 0;
         input.nDataLength = 30;
         OutputModule rev   = m_Modbus.SendMessage_Sync(input);
         int          count = 0;
         for (; ;)
         {
             if (count > 3)
             {
                 throw new Exception("通信异常,读取自动运行线圈失败!");
             }
             if ((rev == null) || (rev.byFunction != input.byFunction))
             {
                 rev = m_Modbus.SendMessage_Sync(input);
                 count++;
                 Thread.Sleep(200);
             }
             else
             {
                 break;
             }
         }
         int    dataLength = rev.byRecvData[8];//读取到的数据长度
         string binary     = string.Empty;
         for (int i = 0; i < dataLength; i++)
         {
             int    Decimal = rev.byRecvData[9 + i];                        //已经为十进制  --数据开始位置为第9个
             string temp    = Convert.ToString(Decimal, 2).PadLeft(8, '0'); //十进制转二进制
             binary += MyFunction.StrReverse(temp);
         }
         this.Coils.SetBitDatasValue(binary);//直接修改线圈的值
     }
     catch (Exception ex)
     {
         log.AddERRORLOG("单次读取线圈失败:" + ex.Message);
     }
 }
示例#10
0
 /// <summary>
 /// 读取Modbus地址信息
 /// </summary>
 /// <param name="StartAdress">地址</param>
 /// <returns></returns>
 public string ModbusRead(int StartAdress)
 {
     ReadMutex.WaitOne();
     try
     {
         string      str   = string.Empty;
         InputModule input = new InputModule();
         if (GlobalVar.gl_Portcon == null)
         {
             ReadMutex.ReleaseMutex(); myfunction.writelog("读取异常,Modbus为空,未打开"); return("");
         }
         input.bySlaveID   = 1;
         input.byFunction  = GlobalVar.g_ReadCoil;
         input.nStartAddr  = StartAdress;
         input.nDataLength = GlobalVar.gl_WordLength;
         OutputModule rev = GlobalVar.gl_Portcon.SendMessage_Sync(input);
         Thread.Sleep(100);
         if ((rev == null) || (rev.byFunction != input.byFunction))
         {
             return("");
         }
         else
         {
             if (rev.byFunction == 1)
             {
                 str = rev.byRecvData[9].ToString();
             }
         }
         ReadMutex.ReleaseMutex();
         return(str);
     }
     catch (Exception ex)
     {
         myfunction.writelog("读取Modbus异常,Modbus地址:" + StartAdress.ToString() + "异常原因" + ex.ToString());
         ReadMutex.ReleaseMutex();
         return("Error");
     }
 }
示例#11
0
        public void First()
        {
            TextInputModule    consoleIn            = new TextInputModule("shaggly");
            InputModule <long> numberGenerator      = new InputModule <long>(() => 1);
            InputModule <long> numberGenerator2     = new InputModule <long>(() => 2);
            Module <Tuple <long, long>, long> adder = new Module <Tuple <long, long>, long>(a => { return(a.Item1 + a.Item2); });
            OutputModule <long>   output            = new OutputModule <long>((l) => { });
            OutputModule <string> stringOutput      = new OutputModule <string>((l) => { });

            FlowGraph g = new FlowGraph();

            g.Connect(numberGenerator, 0, adder, 0);
            g.Connect(numberGenerator2, 0, adder, 1);
            g.Connect(adder, 0, output, 0);
            g.Connect(consoleIn, 0, stringOutput, 0);
            System.Diagnostics.Stopwatch w = new Stopwatch();
            w.Start();
            for (int i = 0; i < 10000; i++)
            {
                g.Process();
            }
            w.Stop();
            Console.Out.Write(w.Elapsed.TotalSeconds);
        }
示例#12
0
        /// <summary>
        /// 读取所有的保持寄存器
        /// </summary>
        /// <param name="Length">在使用的保持寄存器的总长度</param>
        /// <param name="Plusddr">起始地址加上的地址</param>
        private void ReadALlHoldingRegister(int Length = 10, int Plusddr = 0)
        {
            if (Length < 1 || Length > HoldingRegister.MAXLength)
            {
                throw new Exception("读取保持寄存器寄存器 长度超出范围");
            }

            InputModule input = new InputModule();

            input.bySlaveID   = m_SlaveID;
            input.byFunction  = Modbus.byREAD_HOLDING_REG;
            input.nStartAddr  = HoldingRegister.PLCStartAddr + Plusddr;
            input.nDataLength = Length;;

            OutputModule rev = m_Modbus.SendMessage_Sync(input);

            if ((rev == null) || (rev.byFunction != input.byFunction))
            {
                throw new Exception("通讯异常,读取所有保持寄存器失败!" + Plusddr);
            }

            //本软件 保持寄存器的数组,读取时转换
            this.HoldingRegisters.SetRegisterArray(rev.byRecvData, Plusddr);
        }
示例#13
0
 public bool SendMsg(Coil coil, bool Press)
 {
     try
     {
         InputModule input = new InputModule();
         input.byFunction  = Modbus.byWRITE_SINGLE_COIL;
         input.nStartAddr  = coil.Addr;
         input.nDataLength = Coil.Size;
         input.byWriteData = new byte[] { Press ? (byte)0 : (byte)255, 0x00 };
         OutputModule rev = null;
         rev = m_Modbus.SendMessage_Sync(input);
         int count = 0;
         for (; ;)
         {
             if (rev != null)
             {
                 return(true);
             }
             if ((rev == null) || (rev.byFunction != input.byFunction))
             {
                 rev = m_Modbus.SendMessage_Sync(input);
                 count++;
             }
             if (count > 3)
             {
                 throw new Exception("发送线圈消息通信异常!");
             }
             Thread.Sleep(200);
         }
     }
     catch (Exception ex)
     {
         log.AddERRORLOG("发送线圈信息异常:" + ex.Message);
         return(false);
     }
 }
示例#14
0
        public IList <long> Run()
        {
            if (_memory == null)
            {
                throw new Exception($"You must load a program first using {nameof(Computer)}.{nameof(Load)}");
            }

            Running = true;

            while (Running && _instructionPointer < _memory.Count)
            {
                var instruction     = new Instruction(_memory[(int)_instructionPointer]);
                var parameterValues = GetParameterValues(instruction);

                long index;
                var  jmp = false;
                switch (instruction.Op)
                {
                case OpCode.Add:
                    index = GetIndex(parameterValues[2]);
                    ExtendMemoryIfRequired(index);
                    _memory[(int)index] = GetValue(parameterValues[0]) + GetValue(parameterValues[1]);
                    break;

                case OpCode.Multiply:
                    index = GetIndex(parameterValues[2]);
                    ExtendMemoryIfRequired(index);
                    _memory[(int)index] = GetValue(parameterValues[0]) * GetValue(parameterValues[1]);
                    break;

                case OpCode.Save:
                    index = GetIndex(parameterValues[0]);
                    ExtendMemoryIfRequired(index);
                    var input = InputModule.InputCallback();
                    _memory[(int)index] = input;
                    break;

                case OpCode.Output:
                    var outputValue = GetValue(parameterValues[0]);
                    OutputModule.OutputCallback(outputValue);
                    break;

                case OpCode.JmpT:
                    jmp = GetValue(parameterValues[0]) > 0;
                    if (jmp)
                    {
                        _instructionPointer = GetValue(parameterValues[1]);
                    }
                    break;

                case OpCode.JmpF:
                    jmp = GetValue(parameterValues[0]) == 0;
                    if (jmp)
                    {
                        _instructionPointer = GetValue(parameterValues[1]);
                    }
                    break;

                case OpCode.LessThan:
                    var lt = GetValue(parameterValues[0]) < GetValue(parameterValues[1]);
                    index = GetIndex(parameterValues[2]);
                    ExtendMemoryIfRequired(index);
                    _memory[(int)index] = lt ? 1 : 0;;
                    break;

                case OpCode.Eql:
                    var eql = GetValue(parameterValues[0]) == GetValue(parameterValues[1]);
                    index = GetIndex(parameterValues[2]);
                    ExtendMemoryIfRequired(index);
                    var toStore = eql ? 1 : 0;
                    _memory[(int)index] = toStore;
                    break;

                case OpCode.Halt:
                    Halted = true;
                    return(_memory);

                case OpCode.SetRbo:
                    _rbo += GetValue(parameterValues[0]);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (!jmp)
                {
                    _instructionPointer += instruction.ParameterModes.Count + 1;
                }
            }

            return(_memory);
        }
示例#15
0
        public void Initialize()
        {
            _eventAggregator.GetEvent <SplashScreenUpdateEvent>().Publish(new SplashScreenUpdateEvent {
                Text = "Loading Components..."
            });

            _container.RegisterType <IThemeSettings, ThemeSettings>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IRecentViewSettings, RecentViewSettings>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IWindowPositionSettings, WindowPositionSettings>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IToolbarPositionSettings, ToolbarPositionSettings>(new ContainerControlledLifetimeManager());
            _container.RegisterType <ICommandManager, Mjolnir.IDE.Core.Services.CommandManager>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IContentHandlerRegistry, ContentHandlerRegistry>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IStatusbarService, MjolnirStatusbarViewModel>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IThemeManager, ThemeManager>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IShellToolbarService, ShellToolbarService>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IMenuService, MenuItemViewModel>(new ContainerControlledLifetimeManager(),
                                                                      new InjectionConstructor(
                                                                          new InjectionParameter(typeof(string),
                                                                                                 "$MAIN$"),
                                                                          new InjectionParameter(typeof(string),
                                                                                                 "$MAIN$"),
                                                                          new InjectionParameter(typeof(int), 1),
                                                                          new InjectionParameter(
                                                                              typeof(ImageSource), null),
                                                                          new InjectionParameter(typeof(ICommand),
                                                                                                 null),
                                                                          new InjectionParameter(
                                                                              typeof(KeyGesture), null),
                                                                          new InjectionParameter(typeof(bool), false),
                                                                          new InjectionParameter(typeof(bool), false),
                                                                          new InjectionParameter(
                                                                              typeof(IUnityContainer), _container),
                                                                          new InjectionParameter(typeof(bool), false),
                                                                          new InjectionParameter(typeof(bool), false)));
            _container.RegisterType <ToolbarViewModel>(
                new InjectionConstructor(new InjectionParameter(typeof(string), "$MAIN$"),
                                         new InjectionParameter(typeof(string), "$MAIN$"),
                                         new InjectionParameter(typeof(int), 1),
                                         new InjectionParameter(typeof(ImageSource), null),
                                         new InjectionParameter(typeof(ICommand), null),
                                         new InjectionParameter(typeof(bool), false),
                                         new InjectionParameter(typeof(IUnityContainer), _container)));

            _container.RegisterType <ISettingsManager, SettingsManager>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IOpenDocumentService, OpenDocumentService>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IMessageDialogService, DefaultMessageDialogService>(new TransientLifetimeManager());
            _container.RegisterType <IFileDialogService, DefaultFileDialogService>(new TransientLifetimeManager());



            AppCommands();
            LoadSettings();


            // Try resolving an output service - if not found, then register the NLog service
            var isDefaultOutputService = false;

            try
            {
                this._outputService = _container.Resolve <IOutputService>();
            }
            catch
            {
                _container.RegisterType <IOutputService, DefaultLogService>(new ContainerControlledLifetimeManager());
                this._outputService    = _container.Resolve <IOutputService>();
                isDefaultOutputService = true;
            }


            var app = _container.Resolve <MjolnirApp>();

            if (app != null)
            {
                app.RegisterTypes();
            }


            //Output
            OutputModule outputModule = _container.Resolve <OutputModule>();

            outputModule.Initialize();

            if (isDefaultOutputService)
            {
                _outputService.LogOutput(new LogOutputItem("DefaultLogService applied", OutputCategory.Info, OutputPriority.None));
            }



            if (app != null)
            {
                app.InitalizeIDE();
            }

            //Below ones can be loaded with solution, does not require immediate load
            //TODO : Console

            PropertiesModule propertiesModule = _container.Resolve <PropertiesModule>();

            propertiesModule.Initialize();


            if (app != null)
            {
                _eventAggregator.GetEvent <SplashScreenUpdateEvent>().Publish(new SplashScreenUpdateEvent {
                    Text = "Loading Application UI..."
                });

                app.LoadCommands();
                app.LoadModules();
                app.LoadTheme();
                app.LoadMenus();
                app.LoadToolbar();
                app.LoadSettings();
            }

            var shell = _container.Resolve <IShellView>();

            shell.LoadLayout();

            _eventAggregator.GetEvent <IDELoadedEvent>().Publish();
        }
示例#16
0
 public void SetStartTarget <T>(OutputModule <T> outputModule)
 {
     startTarget             = outputModule.transform;
     lineRenderer.startColor = outputModule.nodeColor;
 }