示例#1
0
 public override bool Sync()
 {
     IsChanged = FAutoValidate ? FEnumIn.PinIsChanged : FEnumIn.Validate();
     if (IsChanged)
     {
         Length = FEnumIn.SliceCount;
         using (var writer = GetWriter())
         {
             for (int i = 0; i < Length; i++)
             {
                 string entry;
                 FEnumIn.GetString(i, out entry);
                 try
                 {
                     writer.Write((T)Enum.Parse(typeof(T), entry));
                 }
                 catch (Exception)
                 {
                     writer.Write(default(T));
                 }
             }
         }
     }
     return(base.Sync());
 }
示例#2
0
        /// <summary>
        /// The Mainloop
        /// </summary>
        public void Evaluate(int SpreadMax)
        {
            // Get Node Settings
            string        DirectoryPath         = "";
            double        IncludeSubdirectories = 0;
            List <string> Mask       = new List <string>();
            string        MaskRule   = "";
            string        CountOrder = "";
            bool          Update     = false;

            SetMessage("Please Update");
            double CountIn = 0;

            //Check if any pin is changed and setup a new search;
            if (FDirectory.PinIsChanged || FSubdirectories.PinIsChanged || FMask.PinIsChanged || FMaskRule.PinIsChanged || FCountIn.PinIsChanged || FShortFilenameIn.PinIsChanged || FCountOrder.PinIsChanged || FUpdate.PinIsChanged)
            {
                //Get the DirectoryPath String an check if it null, empty or exist. if not the function is returned
                FDirectory.GetString(0, out DirectoryPath);
                if (String.IsNullOrEmpty(DirectoryPath) || !Directory.Exists(DirectoryPath))
                {
                    FFiles.SliceCount            = 0;
                    FShortFilenameOut.SliceCount = 0;
                    FCountOut.SetValue(0, 0);

                    SetMessage("Please Enter a correct directory Path..");
                    return;
                }

                FSubdirectories.GetValue(0, out IncludeSubdirectories);
                FMaskRule.GetString(0, out MaskRule);;
                FCountIn.GetValue(0, out CountIn);
                FCountOrder.GetString(0, out CountOrder);

                //Get all Serach Masks
                for (int i = 0; i < FMask.SliceCount; i++)
                {
                    string MaskSlice;
                    FMask.GetString(i, out MaskSlice);

                    if (!String.IsNullOrEmpty(MaskSlice))
                    {
                        Mask.Add(MaskSlice);
                    }
                }

                //if there is no Mask create one, otherwise the Function getFiles crashes
                if (Mask.Count == 0)
                {
                    Mask.Add("*.*");
                }

                //Create a new Search with the given setup. If there exist a Search Object we are still Searching.
                if (FSearch == null)
                {
                    //Set if the Subdirectories are included or not and Create a new Search Process Object which handle all Files Searching and Sorting in a new Thread
                    if (IncludeSubdirectories <= 0)
                    {
                        FSearch = new SearchProcess(DirectoryPath, Mask.ToArray(), SearchOption.TopDirectoryOnly, MaskRule, CountIn, CountOrder);
                    }
                    else
                    {
                        FSearch = new SearchProcess(DirectoryPath, Mask.ToArray(), SearchOption.AllDirectories, MaskRule, CountIn, CountOrder);
                    }

                    if (FSearch != null)
                    {
                        //Start the Searching..
                        SetMessage(FSearch.Search());
                    }
                }
                else
                {
                    SetMessage("Still Searching... Please Wait...");
                }
            }

            //Read the Resulte of the SearchProcess
            if (FSearch != null)
            {
                string Message = FSearch.GetStatus();
                SetMessage(Message);

                string[] FullFilesNames = FSearch.GetFullFileNames();


                if (FullFilesNames != null)
                {
                    double IncludeShortFilename = 0;
                    FShortFilenameIn.GetValue(0, out IncludeShortFilename);

                    FFiles.SliceCount = FullFilesNames.Length;
                    FCountOut.SetValue(0, FullFilesNames.Length);

                    for (int i = 0; i < FullFilesNames.Length; i++)
                    {
                        string FilePath = FullFilesNames[i];
                        FFiles.SetString(i, FilePath);

                        if (IncludeShortFilename >= 0.5)
                        {
                            string[] ShortFilename = FSearch.GetShortFileNames();

                            FShortFilenameOut.SliceCount = ShortFilename.Length;
                            FShortFilenameOut.SetString(i, ShortFilename[i]);
                        }
                        else
                        {
                            FShortFilenameOut.SliceCount = 0;
                        }
                    }
                    FSearch = null;
                }
            }
        }
示例#3
0
文件: RS232.cs 项目: vnmone/vvvv-sdk
        /// <summary>
        /// The Mainloop
        /// </summary>
        public void Evaluate(int SpreadMax)
        {
            try
            {
                FDataOut.SliceCount      = SpreadMax;
                FOnDataOut.SliceCount    = SpreadMax;
                FConnectedOut.SliceCount = SpreadMax;

                for (int i = 0; i < _AvailablePorts.Length; i++)
                {
                    FPortsOut.SetValue(i, Convert.ToDouble(_AvailablePorts[i].Substring(3)));
                }



                string currentSliceData;
                double currentSliceDoSend;
                double currentSliceEnabled;
                double currentSliceKeepLastData;
                double currentSlicePortNumber;
                double currentSliceBaudrate;
                string currentSliceParity;
                string currentSliceDatabits = "";
                string currentSliceStopbits;
                string currentSliceHandShake;
                double currentReadBufferSize;



                //loop for all slices
                for (int i = 0; i < SpreadMax; i++)
                {
                    FDoSendIn.GetValue(i, out currentSliceDoSend);
                    FEnableIn.GetValue(i, out currentSliceEnabled);
                    FKeepLastDataIn.GetValue(i, out currentSliceKeepLastData);
                    FPortNumberIn.GetValue(i, out currentSlicePortNumber);
                    FBaudrateIn.GetValue(i, out currentSliceBaudrate);
                    FParityIn.GetString(i, out currentSliceParity);
                    FDatabitsIn.GetString(i, out currentSliceDatabits);
                    FStopbitsIn.GetString(i, out currentSliceStopbits);
                    FHandShakeIn.GetString(i, out currentSliceHandShake);
                    FReadBufferIn.GetValue(i, out currentReadBufferSize);

                    Port tPort;

                    if (Convert.ToBoolean(currentSliceEnabled))
                    {
                        tPort = this.GetPort((int)currentSlicePortNumber);

                        if (tPort == null)
                        {
                            if ((new List <string>(SerialPort.GetPortNames())).Contains(String.Format("COM{0}", currentSlicePortNumber)))
                            {
                                tPort = new Port((int)currentSlicePortNumber, (int)currentSliceBaudrate,
                                                 currentSliceParity, Convert.ToInt32(currentSliceDatabits.Replace("Bits", "")), currentSliceStopbits.Replace("Bits", ""), (int)currentReadBufferSize);

                                _Ports.Add(tPort);

                                currentReadBufferSize = (double)tPort.BufferSize;
                                FReadBufferOut.SetValue(i, currentReadBufferSize);
                            }
                        }
                        else
                        {
                            //read data from inputs
                            FDataIn.GetString(i, out currentSliceData);
                            FOnDataOut.SetValue(i, Convert.ToDouble(tPort.OnData));
                            FConnectedOut.SetValue(i, Convert.ToDouble(tPort.Connected));

                            // write data to comport
                            if (currentSliceDoSend == 1.0 && !String.IsNullOrEmpty(currentSliceData))
                            {
                                tPort.Write(currentSliceData);
                            }

                            //read data from comport
                            if (tPort.OnData)
                            {
                                FDataOut.SetString(i, tPort.Read());
                            }
                            else
                            {
                                if (Convert.ToBoolean(currentSliceKeepLastData))
                                {
                                    FDataOut.SetString(i, tPort.Data);
                                }
                                else
                                {
                                    FDataOut.SetString(i, "");
                                }
                            }


                            if (FBaudrateIn.PinIsChanged)
                            {
                                tPort.Baudrate = (int)currentSliceBaudrate;
                            }

                            if (FParityIn.PinIsChanged)
                            {
                                tPort.Parity = currentSliceParity;
                            }

                            if (FDatabitsIn.PinIsChanged)
                            {
                                tPort.DataBits = Convert.ToInt32(currentSliceDatabits);
                            }

                            if (FStopbitsIn.PinIsChanged)
                            {
                                tPort.StopBits = currentSliceStopbits;
                            }

                            if (FHandShakeIn.PinIsChanged)
                            {
                                tPort.HandShake = currentSliceHandShake;
                            }
                            if (FReadBufferIn.PinIsChanged)
                            {
                                tPort.Dispose();
                                _Ports.Remove(tPort);
                            }
                        }
                    }
                    else
                    {
                        tPort = this.GetPort((int)currentSlicePortNumber);

                        if (tPort != null)
                        {
                            tPort.Dispose();
                            _Ports.Remove(tPort);
                        }

                        FOnDataOut.SetValue(i, Convert.ToDouble(0));
                        FConnectedOut.SetValue(i, Convert.ToDouble(0));
                        FDataOut.SetString(i, "");
                    }
                }
            }
            catch (Exception ex)
            {
                FHost.Log(TLogType.Error, ex.Message);
            }
        }