private void buttonQuery_Click(object sender, EventArgs e) { object[] objs = stf.GetCheckedSensors(); //List<datas> result = new List<datas>(); DataSet newSet = new DataSet(); foreach (object[] obj in objs) { SENSOR_TYPE type = sites.GetType((uint)obj[0], (uint)obj[1]); newSet.Merge(DbClient.Query((uint)obj[0], (uint)obj[1], dateTimeFrom.Value, dateTimeTo.Value, timeUnit, (type == SENSOR_TYPE.GUANDAO || type == SENSOR_TYPE.MINGQU)) ); //result.AddRange(); } if (radioButtonGrid.Checked) { dataGridSensor.Show(); chartSensors.Hide(); FillGrid(newSet); } else { dataGridSensor.Hide(); chartSensors.Show(); FillChart(newSet); } }
private SENSOR_TYPE GetEV3Mode(ColorSensorMode mode) { SENSOR_TYPE ret = SENSOR_TYPE.EV3_COLOR_REFLECTED; //.EV3_COLOR_M0; switch (mode) { //question is about the various modes and if theyr are supported and how case ColorSensorMode.Color: ret = SENSOR_TYPE.EV3_COLOR_COLOR; //BrickSensorType.EV3_COLOR_M2; break; case ColorSensorMode.Reflection: ret = SENSOR_TYPE.EV3_COLOR_REFLECTED; //BrickSensorType.EV3_COLOR_M0; break; case ColorSensorMode.Green: ret = SENSOR_TYPE.EV3_COLOR_RAW_REFLECTED; //BrickSensorType.EV3_COLOR_M3; break; case ColorSensorMode.Blue: ret = SENSOR_TYPE.EV3_COLOR_COLOR_COMPONENTS; //BrickSensorType.EV3_COLOR_M4; break; case ColorSensorMode.Ambient: ret = SENSOR_TYPE.EV3_COLOR_AMBIENT; //BrickSensorType.EV3_COLOR_M1; break; } return(ret); }
private void buttonDefualtF_Click(object sender, EventArgs e) { SENSOR_TYPE t = (SENSOR_TYPE)comboBoxType.SelectedValue; switch (t) { case SENSOR_TYPE.GUANDAO: textBoxFormula.Text = "((data -770.0) / (3977.0-770.0)) * 5.0"; break; case SENSOR_TYPE.WENDU: textBoxFormula.Text = "((data - 820) / (4096 - 820)) * 100"; break; case SENSOR_TYPE.SHUIWEI: textBoxFormula.Text = "((data * 2.5) / 4096 - 0.76) * 2.5"; break; case SENSOR_TYPE.YALI: textBoxFormula.Text = "((data * 2.5) / 4096 - 0.76) * 5.0"; break; case SENSOR_TYPE.MINGQU: textBoxFormula.Text = "((data - 1170) / (3500 - 1170)) * 1"; break; case SENSOR_TYPE.WUWEI: textBoxFormula.Text = "((data - 820) / (4096 - 820)) * 100"; break; default: textBoxFormula.Text = ""; break; } }
public static string GetSymbol(SENSOR_TYPE type) { switch (type) { case SENSOR_TYPE.GUANDAO: return("㎥/h"); case SENSOR_TYPE.MINGQU: return("㎥/h"); case SENSOR_TYPE.SHUIWEI: return("m"); case SENSOR_TYPE.WUWEI: return("m"); case SENSOR_TYPE.WENDU: return("℃"); case SENSOR_TYPE.YALI: return("MPa"); case SENSOR_TYPE.DIANYA: return("V"); } return(""); }
public void RegisterSensorListener(SENSOR_TYPE type, SENSOR_LOCATION location) { if (nibiruSensorServiceObject != null) { if (nibiruSensorDataListenerCallback == null) { nibiruSensorDataListenerCallback = new NibiruSensorDataListenerCallback(); } // UI线程执行 RunOnUIThread(androidActivity, new AndroidJavaRunnable(() => { AndroidJavaClass locationClass = BaseAndroidDevice.GetClass("com.nibiru.service.NibiruSensorService$SENSOR_LOCATION"); AndroidJavaObject locationObj = locationClass.CallStatic <AndroidJavaObject>("valueOf", location.ToString()); AndroidJavaClass typeClass = BaseAndroidDevice.GetClass("com.nibiru.service.NibiruSensorService$SENSOR_TYPE"); AndroidJavaObject typeObj = typeClass.CallStatic <AndroidJavaObject>("valueOf", type.ToString()); nibiruSensorServiceObject.Call <bool>("registerSensorListener", typeObj, locationObj, nibiruSensorDataListenerCallback); Debug.Log("registerSensorListener=" + type.ToString() + "," + location.ToString()); } )); } else { Debug.LogError("RegisterControllerSensor failed, nibiruSensorServiceObject is null !"); } }
private void TypeChange(SENSOR_TYPE type) { if (type == SENSOR_TYPE.GUANDAO) { textBoxInterval.Enabled = true; textBoxSensorDeep.Enabled = false; comboBoxDaogui.Enabled = true; } else if (type == SENSOR_TYPE.WUWEI) { textBoxSensorDeep.Enabled = true; textBoxInterval.Enabled = false; comboBoxDaogui.Enabled = false; } else if (type == SENSOR_TYPE.MINGQU) { textBoxInterval.Enabled = true; textBoxSensorDeep.Enabled = false; comboBoxDaogui.Enabled = true; } else if (type == SENSOR_TYPE.SHUIWEI) { } else { textBoxSensorDeep.Enabled = false; textBoxInterval.Enabled = false; comboBoxDaogui.Enabled = false; } this.lblRopeDepth.Visible = type == SENSOR_TYPE.SHUIWEI; this.lblWellDepth.Visible = type == SENSOR_TYPE.SHUIWEI; this.txtRopeDepth.Visible = type == SENSOR_TYPE.SHUIWEI; this.txtWellDepth.Visible = type == SENSOR_TYPE.SHUIWEI; }
// public Sensor(uint num, string name, SENSOR_TYPE type, decimal alarmLow, decimal alarmHigh) { this.num = num; this.name = name; this.type = type; this.alarmLow = alarmLow; this.alarmHigh = alarmHigh; }
public NibiruSensorEvent(float x, float y, float z, long timestamp, SENSOR_TYPE sensorType, SENSOR_LOCATION sensorLocation) { this.x = x; this.y = y; this.z = z; this.timestamp = timestamp; this.sensorLocation = sensorLocation; this.sensorType = sensorType; }
public bool Add(uint num, string name, SENSOR_TYPE type, decimal alarmLow, decimal alarmHigh) { if (sensors.ContainsKey(num)) { return(false); } sensors.Add(num, new Sensor(num, name, type, alarmLow, alarmHigh)); return(true); }
public void onSensorDataChanged(AndroidJavaObject sensorEventObject) { float x = sensorEventObject.Get <float>("x"); float y = sensorEventObject.Get <float>("y"); float z = sensorEventObject.Get <float>("z"); long timestamp = sensorEventObject.Get <long>("timestamp"); AndroidJavaObject locationObject = sensorEventObject.Get <AndroidJavaObject>("sensorLocation"); AndroidJavaObject typeObject = sensorEventObject.Get <AndroidJavaObject>("sensorType"); SENSOR_LOCATION sensorLocation = (SENSOR_LOCATION)locationObject.Call <int>("ordinal"); SENSOR_TYPE sensorType = (SENSOR_TYPE)typeObject.Call <int>("ordinal"); NibiruSensorEvent sensorEvent = new NibiruSensorEvent(x, y, z, timestamp, sensorType, sensorLocation); // sensorEvent.printLog(); // 用Loom的方法在Unity主线程中调用Text组件 Loom.QueueOnMainThread((param) => { if (OnSensorDataChangedHandler != null) { OnSensorDataChangedHandler((NibiruSensorEvent)param); } }, sensorEvent); }
public static void Parse(List <byte> recvDatas, uint siteNum, Sites sites) { byte b = 0; STATUS s = STATUS.R_UNKOWN; int nEB = 0; int nParsed = 0; for (int i = 0; i < recvDatas.Count; ++i) { string sss = ByteToHexString(recvDatas.ToArray(), recvDatas.ToArray().Length); //System.IO.File.AppendAllText("c:/data.txt", sss + "\r\n"); //Console.WriteLine(sss); b = recvDatas[i]; switch (s) { case STATUS.R_UNKOWN: { if (b == 0xEB) { s = STATUS.R_EB; nEB = i; } } break; case STATUS.R_EB: { if (b == 0x90) { s = STATUS.R_90; } } break; case STATUS.R_90: { if (i - nEB == 9) { if (b == 0xAA) { siteNum = recvDatas[nEB + 2]; uint sensorNum = recvDatas[nEB + 3]; //recvDatas[nEB+8],recvDatas[nEB+7],recvDatas[nEB+6],recvDatas[nEB+5] //double d = (double)BitConverter.ToUInt16(new byte[]{recvDatas[nEB+6],recvDatas[nEB+5]},0); double?[] data = new double?[5]; //用来存放数据,长度可能还会更改 //double d = (double)BitConverter.ToUInt16(new byte[] { recvDatas[nEB + 8], recvDatas[nEB + 7], recvDatas[nEB + 6], recvDatas[nEB + 5] }, 0); SENSOR_TYPE type = sites.GetType(siteNum, sensorNum); switch (type) { case SENSOR_TYPE.SHUIWEI: case SENSOR_TYPE.YALI: case SENSOR_TYPE.WENDU: case SENSOR_TYPE.DIANYA: data[0] = (double)BitConverter.ToUInt16(new byte[] { recvDatas[nEB + 6], recvDatas[nEB + 5] }, 0); break; case SENSOR_TYPE.MINGQU: break; case SENSOR_TYPE.GUANDAO: data[0] = (double)BitConverter.ToUInt16(new byte[] { recvDatas[nEB + 6], recvDatas[nEB + 5] }, 0); data[1] = (double)BitConverter.ToUInt16(new byte[] { recvDatas[nEB + 8], recvDatas[nEB + 7] }, 0); break; default: break; } Sensor ss; Site site; do { sites.Get(siteNum, out site); site.Get(sensorNum, out ss); if (site == null || ss == null) { break; } //if (ss.formulaDelegate == null) //{ // Log.Write("传感器没有编译好的公式"); // break; //} //double saveData = ss.formulaDelegate.Invoke(d); double dataOrigion = data[0].Value; double saveData = 0; double sumData = 0; double liangcheng = 0; bool flag = double.TryParse(ss.formula, out liangcheng); //此处的"公式"废弃不用,使用"量程"替代 liangcheng = flag ? liangcheng : 1; switch (type) { case SENSOR_TYPE.YALI: case SENSOR_TYPE.WENDU: saveData = (data[0].Value - 819) / (4096 - 819) * liangcheng; break; case SENSOR_TYPE.SHUIWEI: double tempData = (data[0].Value - 819) / (4096 - 819) * liangcheng; saveData = ss.wellDepth - ss.ropeDepth + tempData; break; case SENSOR_TYPE.MINGQU: break; case SENSOR_TYPE.GUANDAO: saveData = data[0].Value / 100 * liangcheng; //DateTime? lastTime = DbServer.GetLastCreateTime(siteNum, sensorNum); //if (lastTime == null) //{ // sumData = 0; // File.AppendAllText("d:/log.txt","if lasttime=null sumData=" + sumData) ; //} //else //{ // double substractHours = DateTime.Now.Subtract(lastTime.Value).Seconds / 3600.0; // sumData = saveData * substractHours; // File.AppendAllText("d:/log.txt", "if lasttime=null else sumData=" + sumData); //} break; case SENSOR_TYPE.DIANYA: saveData = data[0].Value / 100; break; default: break; } DateTime?lastTime = DbServer.GetLastCreateTime(siteNum, sensorNum); if (lastTime == null) { sumData = 0; File.AppendAllText("d:/log.txt", "if lasttime=null sumData=" + sumData); } else { double substractHours = DateTime.Now.Subtract(lastTime.Value).Seconds / 3600.0; sumData = saveData * substractHours; File.AppendAllText("d:/log.txt", "if lasttime=null else sumData=" + sumData); } //if (type == SENSOR_TYPE.GUANDAO || type == SENSOR_TYPE.MINGQU) //{ // if (saveData <= 0.00005) // { // saveData = 0.0; // } //} saveData *= Balance.GetParam((int)siteNum, (int)sensorNum); File.AppendAllText("d:/log.txt", "sumData=" + sumData.ToString()); //double weight = GetWeight(siteNum, sensorNum); double weight = 1; if (weight <= 0.0) { break; } //weight = (type == SENSOR_TYPE.GUANDAO || type == SENSOR_TYPE.MINGQU) ? weight:1; saveData = Math.Round(saveData, 3); saveData = saveData <= 0 ? 0 : saveData; sumData = Math.Round(sumData, 3); DbServer.SaveAsync(siteNum, sensorNum, dataOrigion, saveData, sumData, weight, DateTime.Now); // if (siteNum == 1 && sensorNum == 2) // { // DbServer.SaveAsync(1, 3, saveData / 100, 1, DateTime.Now); // } } while (false); } else { //数据格式错误 } nParsed = i; s = STATUS.R_UNKOWN; nEB = 0; } } break; } } recvDatas.RemoveRange(0, nParsed); }
public static double GetShowData(SENSOR_TYPE type, double dataOrigion, double data, double dataAvg, double dataSum) { //return (type == SENSOR_TYPE.GUANDAO||type== SENSOR_TYPE.MINGQU)?dataSum:dataAvg; return((type == SENSOR_TYPE.GUANDAO || type == SENSOR_TYPE.MINGQU) ? dataSum : data); //return d <0.0?0.0:d; }
public void set_sensor_type(byte port, SENSOR_TYPE type, int[] param = null) { // Set the sensor type // Keyword arguments: // port-- The sensor port(s).PORT_1, PORT_2, PORT_3, and / or PORT_4. // type-- The sensor type // params = 0-- the parameters needed for some sensor types. // params is used for the following sensor types: //CUSTOM-- a 16 - bit integer used to configure the hardware. //I2C-- a list of settings: // params[0]-- Settings / flags // params[1] -- target Speed in microseconds(0-255). Realistically the speed will vary. // if SENSOR_I2C_SETTINGS_SAME flag set in I2C Settings: // params[2] -- Delay in microseconds between transactions. // params[3] -- Address // params[4] -- List of bytes to write // params[5] -- Number of bytes to read for (int p = 0; p < 4; p++) { if ((port & (1 << p)) > 0) { SensorType[p] = type; } } List <byte> outArray = new List <byte>(); if (type == SENSOR_TYPE.CUSTOM) { outArray.AddRange(new byte[] { SPI_Address, (byte)SPI_MESSAGE_TYPE.SET_SENSOR_TYPE, port, (byte)type, (byte)((param[0] >> 8) & 0xFF), (byte)(param[0] & 0xFF) }); } else if (type == SENSOR_TYPE.I2C) { if (param.Length >= 2) { outArray.AddRange(new byte[] { SPI_Address, (byte)SPI_MESSAGE_TYPE.SET_SENSOR_TYPE, port, (byte)type, (byte)param[0], (byte)param[1] }); //# Settings, SpeedUS if ((param[0] == (int)SENSOR_I2C_SETTINGS.SAME) && (param.Length >= 6)) { outArray.Add((byte)((param[2] >> 24) & 0xFF)); // # DelayUS outArray.Add((byte)((param[2] >> 16) & 0xFF)); outArray.Add((byte)((param[2] >> 8) & 0xFF)); outArray.Add((byte)(param[2] & 0xFF)); outArray.Add((byte)(param[3] & 0xFF)); // # Address outArray.Add((byte)(param[5] & 0xFF)); // # InBytes for (int p = 0; p < 4; p++) { if ((port & (1 << p)) > 0) { I2CInBytes[p] = (byte)(param[5] & 0xFF); } } //TODO: fix this part, not sure and no example of usage //outArray.append(len(params[4])) outArray.Add((byte)param[4]); // # OutBytes //outArray.extend(params[4]) outArray.Add((byte)param[4]); // # OutArray } } } else { outArray.AddRange(new byte[] { SPI_Address, (byte)SPI_MESSAGE_TYPE.SET_SENSOR_TYPE, port, (byte)type }); } spi_transfer_array(outArray.ToArray()); }
private void RecvProc() { while (bWork) { Thread.Sleep(10 * 1000); //Thread.Sleep(1000); try { smsRecvProc = new Process(); smsRecvProc.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "\\shuiwenSMS.exe"; smsRecvProc.StartInfo.UseShellExecute = false; // 是否使用外壳程序 smsRecvProc.StartInfo.CreateNoWindow = true; //是否在新窗口中启动该进程的值 smsRecvProc.StartInfo.RedirectStandardInput = true; // 重定向输入流 smsRecvProc.StartInfo.RedirectStandardOutput = true; //重定向输出流 smsRecvProc.StartInfo.RedirectStandardError = true; //重定向错误流 smsRecvProc.OutputDataReceived += new DataReceivedEventHandler(OutputDataReceived); smsRecvProc.EnableRaisingEvents = true; smsRecvProc.Start(); smsRecvProc.BeginOutputReadLine(); smsRecvProc.WaitForExit(); if (smsData.Length > 0) { string[] msgs = smsData.Split('|'); foreach (string msg in msgs) { msg.Trim(); msg.Trim('\r', '\n'); string[] contex = msg.Split(new String[] { "----" }, StringSplitOptions.None); if (contex.Length == 3 && contex[0] == "MSG") { string[] datas = contex[1].Split(';'); foreach (var data in datas) { Sensor ss; Site site; string[] d = data.Split(','); if (d.Length == 3) { uint siteNum = Convert.ToUInt32(d[0]); uint sensorNum = Convert.ToUInt32(d[1]); SENSOR_TYPE type = sites.GetType(siteNum, sensorNum); if (type == SENSOR_TYPE.UNKNOWN) { Log.Write("短信收到没有设置的分站和传感器号" + data); } sites.Get(siteNum, out site); site.Get(sensorNum, out ss); double rawData = Convert.ToDouble(d[2]); IFormatProvider ifp = new CultureInfo("zh-CN", true); DateTime time = DateTime.ParseExact(contex[2], "yyyyMMddHHmmss", ifp); int weight = (type == SENSOR_TYPE.GUANDAO || type == SENSOR_TYPE.MINGQU) ? ss.interval : 1; if (ss.formulaDelegate == null) { Log.Write("传感器没有编译好的公式"); continue; } double saveData = ss.formulaDelegate.Invoke(rawData); if (type == SENSOR_TYPE.GUANDAO || type == SENSOR_TYPE.MINGQU) { if (saveData <= 0.01) { saveData = 0.0; } } DbServer.SaveAsync(siteNum, sensorNum, saveData, saveData, saveData, weight, time); } } } else { if (msg.Length > 0) { Log.Write("无法解析的短信" + msg); } } } } } catch (System.Exception ex) { Log.Write(ex.Message); } finally { smsData = ""; } } }
public BaseSensor(SENSOR_TYPE type) { Type = type; Value = 0; }
public static string NumberFormat(SENSOR_TYPE sensorType, string unit, double value) { string valstr = "?"; switch (sensorType) { case SENSOR_TYPE.SENSOR_TYPE_VOLT: valstr = value.ToString("N3"); break; case SENSOR_TYPE.SENSOR_TYPE_CURRENT: valstr = value.ToString("N3"); break; case SENSOR_TYPE.SENSOR_TYPE_POWER: valstr = value.ToString("N3"); break; case SENSOR_TYPE.SENSOR_TYPE_CLOCK: valstr = value.ToString("N1"); break; case SENSOR_TYPE.SENSOR_TYPE_USAGE: valstr = value.ToString("N1"); break; case SENSOR_TYPE.SENSOR_TYPE_TEMP: valstr = value.ToString("N1"); break; case SENSOR_TYPE.SENSOR_TYPE_FAN: valstr = value.ToString("N0"); break; case SENSOR_TYPE.SENSOR_TYPE_OTHER: if (unit == "Yes/No") { return value == 0 ? "No" : "Yes"; } else if (unit.EndsWith("GT/s") || unit == "x" || unit == "%") { valstr = value.ToString("N1"); } else if (unit.EndsWith("/s")) { valstr = value.ToString("N3"); } else if (unit.EndsWith("MB") || unit.EndsWith("GB") || unit == "T" || unit == "FPS") { valstr = value.ToString("N0"); } else valstr = value.ToString(); break; case SENSOR_TYPE.SENSOR_TYPE_NONE: valstr = value.ToString(); break; } return (valstr + " " + unit).Trim(); }