Beispiel #1
0
        public override void Connect(string portName, BalanceConfig config)
        {
            try
            {
                Config = config;

                SerialPort1 = new SerialPort
                {
                    PortName  = portName,
                    BaudRate  = Config.BaudRate,
                    DataBits  = Config.DataBits,
                    Parity    = Config.Parity,
                    StopBits  = Config.StopBits,
                    Handshake = Config.Handshake
                };

                SerialPort1.PinChanged    += SerialPort1_PinChanged;
                SerialPort1.ErrorReceived += SerialPort1_ErrorReceived;

                SerialPort1.Open();

                if (ReadMode == BalanceReadMode.Automatic)
                {
                    StartReading();
                }
            }
            catch {
            }
        }
Beispiel #2
0
        public override void Connect(string portName)
        {
            var config = new BalanceConfig();

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["BaudRate"]))
            {
                config.BaudRate = Convert.ToInt32(ConfigurationManager.AppSettings["BaudRate"]);
            }

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["DataBits"]))
            {
                config.DataBits = Convert.ToInt32(ConfigurationManager.AppSettings["DataBits"]);
            }

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["Parity"]))
            {
                config.Parity =
                    (Parity)Enum.Parse(typeof(Parity), ConfigurationManager.AppSettings["Parity"]);
            }

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["StopBits"]))
            {
                config.StopBits =
                    (StopBits)Enum.Parse(typeof(StopBits), ConfigurationManager.AppSettings["StopBits"]);
            }

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["Handshake"]))
            {
                config.Handshake =
                    (Handshake)Enum.Parse(typeof(Handshake), ConfigurationManager.AppSettings["Handshake"]);
            }


            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["EmptyWeigth"]))
            {
                config.EmptyWeigth = Convert.ToInt64(ConfigurationManager.AppSettings["EmptyWeigth"]);
            }

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["StabilityTime"]))
            {
                config.StabilityTime = Convert.ToInt64(ConfigurationManager.AppSettings["StabilityTime"]);
            }

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["AccommodateTime"]))
            {
                config.AccommodateTime = Convert.ToInt64(ConfigurationManager.AppSettings["AccommodateTime"]);
            }

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["AccommodateWeigthMin"]))
            {
                config.AccommodateWeigthMin = Convert.ToInt64(ConfigurationManager.AppSettings["AccommodateWeigthMin"]);
            }

            Connect(portName, config);
        }
Beispiel #3
0
        public override void Connect(string portName, BalanceConfig config)
        {
            Config = config;

            //return;
            thread = new Thread(() =>
            {
                while (true)
                {
                    Thread.Sleep(3000);
                    Peso = 0;

                    Thread.Sleep(2000);
                    var peso = new Random().Next(0, 100);
                    max      = peso + 3;
                    min      = peso - 3;

                    var thread2 = new Thread(() =>
                    {
                        Thread.Sleep(200);

                        var time = DateTime.Now;
                        while (true)
                        {
                            Peso = new Random().Next(min, max);

                            var time2  = DateTime.Now;
                            var lapsed = time2 - time;

                            if (lapsed.TotalMilliseconds > 500)
                            {
                                break;
                            }
                        }
                    })
                    {
                        IsBackground = true
                    };
                    thread2.Start();
                }
            })
            {
                IsBackground = true
            };
            thread.Start();

            if (ReadMode == BalanceReadMode.Automatic)
            {
                StartReading();
            }
        }
Beispiel #4
0
 public abstract void Connect(string portName, BalanceConfig config);