void sendThread() { log.addLog("http_get: Send Thread started"); Uri URI = new Uri("http://" + _sHost + "/homewatch/power/index.php" + "?"); System.Net.WebRequest req = null; System.Net.WebResponse resp = null; ec3k_data ec3k; try { while (bRunThread) { ec3k = new ec3k_data(""); try { lock (lockQueue) { if (sendQueue.Count > 0) { ec3k = sendQueue.Dequeue(); } //queue count>0 } //lock if (ec3k._bValid) { string sGet = ec3k.getPostString(); //make the request log.addLog("http_get: WEB GET=" + URI + sGet); req = System.Net.WebRequest.Create(URI + sGet); //req.Proxy = new System.Net.WebProxy(ProxyString, true); //true means no proxy req.Timeout = 5000; resp = req.GetResponse(); System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()); log.addLog("http_get: RESP=" + sr.ReadToEnd().Trim()); }//bValid Thread.Sleep(1000); } catch (WebException ex) { log.addLog("http_get: WebException in sendThread(): " + ex.Message); } catch (Exception ex) { log.addLog("http_get: web get exception: " + ex.Message); } } ; } catch (Exception ex) { log.addLog("http_get: Exception in sendThread(): " + ex.Message); } try{ resp.Close(); }catch (Exception) {} try{ req.Abort(); }catch (Exception) {} log.addLog("http_get: Send Thread ended"); }
void sendThread(){ log.addLog("http_get: Send Thread started"); Uri URI=new Uri( "http://" + _sHost + "/homewatch/power/index.php" + "?"); System.Net.WebRequest req=null; System.Net.WebResponse resp=null; ec3k_data ec3k; try { while (bRunThread) { ec3k = new ec3k_data(""); try { lock (lockQueue) { if (sendQueue.Count > 0) { ec3k = sendQueue.Dequeue(); }//queue count>0 }//lock if (ec3k._bValid) { string sGet = ec3k.getPostString(); //make the request log.addLog("http_get: WEB GET=" + URI + sGet); req = System.Net.WebRequest.Create(URI + sGet); //req.Proxy = new System.Net.WebProxy(ProxyString, true); //true means no proxy req.Timeout = 5000; resp = req.GetResponse(); System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()); log.addLog("http_get: RESP=" + sr.ReadToEnd().Trim()); }//bValid Thread.Sleep(1000); } catch (WebException ex) { log.addLog("http_get: WebException in sendThread(): " + ex.Message); } catch (Exception ex) { log.addLog("http_get: web get exception: " + ex.Message); } }; } catch (Exception ex) { log.addLog("http_get: Exception in sendThread(): " + ex.Message); } try{resp.Close();}catch(Exception){} try{req.Abort();}catch(Exception){} log.addLog("http_get: Send Thread ended"); }
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; }
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"); }
public void add(ec3k_data data) { lock (lockQueue){ sendQueue.Enqueue(data); } }
public void add(ec3k_data data){ lock(lockQueue){ sendQueue.Enqueue(data); } }