private void BtSend_Click(object sender, EventArgs e) { if (RbT1.Checked == true) { _data[0] = (byte)0x40; } else if (RbT2.Checked == true) { _data[0] = (byte)0x41; } else if (RbT3.Checked == true) { _data[0] = (byte)0x42; } else if (RbT4.Checked == true) { _data[0] = (byte)0x43; } else if (RbT5.Checked == true) { _data[0] = (byte)0x44; } else if (RbT6.Checked == true) { _data[0] = (byte)0x45; } else if (RbT7.Checked == true) { _data[0] = (byte)0x46; } else if (RbT8.Checked == true) { _data[0] = (byte)0x47; } else if (RbH.Checked == true) { _data[0] = (byte)0x70; } else if (RbADC1.Checked == true) { _data[0] = (byte)0x50; } else if (RbADC2.Checked == true) { _data[0] = (byte)0x51; } else if (RbADC3.Checked == true) { _data[0] = (byte)0x52; } else if (RbADC4.Checked == true) { _data[0] = (byte)0x53; } try { _serial.WriteBytes3964r(ref _data); //Thread.Sleep(500); _dataR[0] = 0; _dataR[1] = 0; _dataR[2] = 0; _serial.ReadBytes3964r(ref _dataR); } catch (Exception ex) { MessageBox.Show(ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.RchTxtReceive.AppendText("\r\n" + "Answer : " + Encoding.ASCII.GetString(_dataR, 0, _dataR.Length)); this.TxtBValeur.Text = _dataR[1].ToString() + "." + _dataR[2].ToString(); }
public string get_temperature1() { this._data[0] = (byte)0x40; try { _serial.WriteBytes3964r(ref this._data); int i = 0; while ((_serial.ReadBytes3964r(ref this._data) != 0) && (i < 10)) { i++; } } catch (Exception ex) { Console.WriteLine("Error transmission"); //throw ex; } return(this._data[1].ToString() + "." + this._data[2].ToString()); }
public void ThreadLoop() { while (Thread.CurrentThread.IsAlive) { if (_serial.ReadBytes3964r(ref _data) == 0) { switch (_data[0]) { case 0x40: this.getTemperature1(ref _data); break; case 0x41: this.getTemperature2(ref _data); break; case 0x42: this.getTemperature3(ref _data); break; case 0x43: this.getTemperature4(ref _data); break; case 0x44: this.getTemperature5(ref _data); break; case 0x45: this.getTemperature6(ref _data); break; case 0x46: this.getTemperature7(ref _data); break; case 0x47: this.getTemperature8(ref _data); break; case 0x50: this.getADC1(ref _data); break; case 0x51: this.getADC2(ref _data); break; case 0x52: this.getADC3(ref _data); break; case 0x53: this.getADC4(ref _data); break; case 0x60: this.getAccelerometer(ref _data); break; case 0x70: this.getHumidity1(ref _data); break; case 0x71: this.getHumidity2(ref _data); break; case 0x80: this.getImpulsion1(ref _data); break; case 0x81: this.getImpulsion2(ref _data); break; default: break; } _serial.WriteBytes3964r(ref _data); } } }