Exemplo n.º 1
0
        public SensorServer(string COM, SerialPort serial)
        {
            this.portName = COM;
            this.comPort  = serial;
            _instance     = this;

            this.comPortThread = new Thread(this.performCommandSend);
            this.comPortThread.Start();
        }
Exemplo n.º 2
0
        public SensorServer(string COM, string UUID, int FlashSize, ArrayList options)
        {
            this.portName  = COM;
            this.options   = options;
            this.UUID      = UUID;
            this.FlashSize = FlashSize;
            _instance      = this;

            this.comPortThread = new Thread(this.performCommandSend);
            this.comPortThread.Start();
        }
Exemplo n.º 3
0
        public Form2(SensorServer srv)
        {
            InitializeComponent();
            server = srv;

            comLabel.Text  = server.portName;
            UUIDLabel.Text = server.UUID;

            this.Text = "Manažment serveru " + server.portName;

            _instance = this;
        }
Exemplo n.º 4
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            runninSearch = true;
            int    progress;
            string comName = (string)e.Argument;

            server = new SensorServer(comName);
            Console.WriteLine(comName);


            _serialPort = new SerialPort(comName);

            _serialPort.RtsEnable = true;

            _serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

            _serialPort.WriteTimeout = 200;


            e.Result = "";
            try
            {
                _serialPort.Open();

                _serialPort.DiscardInBuffer();
                _serialPort.DiscardOutBuffer();
            } catch (Exception ee)
            {
                e.Result = "Port Nereaguje";
                return;
            }

            worker.ReportProgress(10);

            if (!_serialPort.IsOpen)
            {
                e.Result = "Port Nereaguje";
                return;
            }
            server.comPort = _serialPort;
            worker.ReportProgress(20);


            Thread.Sleep(100);
            server.flushInputBuffer();

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            worker.ReportProgress(30);

            server.sendCommand(new SerialCommand("hi", server.command_hi));
            //server.sendCommand("list;");

            worker.ReportProgress(40);
            progress = 40;


            Console.WriteLine("Probe");
            while (true)
            {
                if (!_serialPort.IsOpen)
                {
                    Console.WriteLine("CLOSED");
                    break;
                }
                if (server.deviceFound())
                {
                    Console.WriteLine("FOUND");
                    break;
                }
                if (stopWatch.ElapsedMilliseconds > 0 && (stopWatch.ElapsedMilliseconds % 100 == 0))
                {
                    worker.ReportProgress(40 + (int)(55 / ((serialTimeOut / stopWatch.ElapsedMilliseconds))));
                }
                if ((stopWatch.ElapsedMilliseconds >= serialTimeOut))
                {
                    Console.WriteLine("TIMEOUT");
                    break;
                }
                if (server.deviceWriteFailed())
                {
                    Console.WriteLine("WRITE TIMEOUT");
                    break;
                }
            }

            e.Result = comName;
            if (server.deviceFound())
            {
                Console.WriteLine("Najdene");
            }
            else
            {
                Console.WriteLine("TIMEOUT");
                _serialPort.Close();
            }

            stopWatch.Stop();

            worker.ReportProgress(100);
        }
Exemplo n.º 5
0
 public SensorServer()
 {
     _instance = this;
 }