Esempio n. 1
0
        void readThread(object param)
        {
            log.addLog("read thread start...");
            byte     b;
            TimeSpan timeSpan;

            lastSend = DateTime.Now;
            do
            {
                try {
                    if (_serialport != null && _serialport.IsOpen)
                    {
                        string sRead = "";
                        do
                        {
                            sRead = _serialport.ReadLine();
                            log.addLog(sRead);
                        }while(_serialport.BytesToRead > 0);
                        //##################################
                        ec3k_data _ec3k = new ec3k_data(sRead);
                        _ec3kdata.Add(_ec3k);

                        log.addLog(sRead);
                        if (_ec3k._bValid)
                        {
                            if (_ec3k._sID.Equals("1B67"))
                            {
                                _ec3k_1 = _ec3k;
                            }
                            else if (_ec3k._sID.Equals("22F0"))
                            {
                                _ec3k_2 = _ec3k;
                            }
                            else if (_ec3k._sID.Equals("1E0E"))
                            {
                                _ec3k_3 = _ec3k;
                            }
                            timeSpan = DateTime.Now - lastSend;
                            if (timeSpan >= timespanMin)
                            {
                                if (_ec3k_1._bValid)
                                {
                                    _httpget.add(_ec3k_1);
                                    _ec3k_1 = new ec3k_data();
                                }
                                if (_ec3k_2._bValid)
                                {
                                    _httpget.add(_ec3k_2);
                                    _ec3k_2 = new ec3k_data();
                                }
                                if (_ec3k_3._bValid)
                                {
                                    _httpget.add(_ec3k_3);
                                    _ec3k_3 = new ec3k_data();
                                }
                                lastSend = DateTime.Now;
                            }                    //if timespan
                        }                        //if bValid
                        //sleep some time
                        Thread.Sleep(1000 * 10); //10 seconds
                        log.addLog(_ec3k.dump());

/*
 *                                              b=(byte)_serialport.ReadByte(); //blocks
 *                                              lock(myLock){
 *                                                      byteQueue.Enqueue(b);
 *                                                      if(b==0x0A || b==0x0d){
 *                                                              //fire event
 *                                                              byte[] buf=byteQueue.ToArray();
 *                                                              string s=Encoding.UTF8.GetString(buf);
 *                                                              log.addLog("read='"+s+"'");
 *                                                      }
 *                                              }//lock
 */
                    }                    //if
                }
                catch (ThreadAbortException) {
                    log.addLog("Thread aborting");
                }
                catch (Exception ex) {
                    log.addLog("Exception in ReadThread: " + ex.Message);
                }
            }while(_serialport != null && bRunThread);
            log.addLog("Thread ended");
            return;
        }
Esempio n. 2
0
        void _threadRead()
        {
            addLog("_threadRead start");
            TimeSpan timeSpan;

            lastSend = DateTime.Now;
            while (bRunThread)
            {
                try {
                    //blocking read
                    string sRead = "";
                    sRead = _reader.ReadLine();

                    //##################################
                    ec3k_data _ec3k = new ec3k_data(sRead);
                    _ec3kdata.Add(_ec3k);

                    addLog(sRead);
                    if (_ec3k._bValid)
                    {
                        if (_ec3k._sID.Equals("1B67"))
                        {
                            _ec3k_1 = _ec3k;
                        }
                        else if (_ec3k._sID.Equals("22F0"))
                        {
                            _ec3k_2 = _ec3k;
                        }
                        else if (_ec3k._sID.Equals("1E0E"))
                        {
                            _ec3k_3 = _ec3k;
                        }
                        timeSpan = DateTime.Now - lastSend;
                        if (timeSpan >= timespanMin)
                        {
                            if (_ec3k_1._bValid)
                            {
                                _httpget.add(_ec3k_1);
                                _ec3k_1 = new ec3k_data();
                            }
                            if (_ec3k_2._bValid)
                            {
                                _httpget.add(_ec3k_2);
                                _ec3k_2 = new ec3k_data();
                            }
                            if (_ec3k_3._bValid)
                            {
                                _httpget.add(_ec3k_3);
                                _ec3k_3 = new ec3k_data();
                            }
                            lastSend = DateTime.Now;
                        }
                    }
                    //sleep some time
                    Thread.Sleep(1000 * 10);                  //10 seconds
                    addLog(_ec3k.dump());
                } catch (Exception ex) {
                    addLog("_threadRead: " + ex.Message);
                }
            }
            ;
            _reader.Dispose();
            addLog("_threadRead stopped");
        }