private void listView1_SelectedIndexChanged(object sender, EventArgs e) { this.panel5.Visible = !this.panel5.Visible; ListView.SelectedListViewItemCollection it = listView1.SelectedItems; for (int i = 0; i < it.Count; i++) { ListViewItem.ListViewSubItemCollection itc = listView1.Items[listView1.SelectedIndices[i]].SubItems; label12.Text = itc[0].Text; label11.Text = itc[1].Text; decodificaion_mensajes_j1939DataSet.SPNDataTable dtSPN = spnTableAdapter1.GetSPNBy(itc[1].Text); textBox5.Text = dtSPN[0].OFFSET.ToString(); textBox4.Text = dtSPN[0].RESOLUTION; decodificaion_mensajes_j1939DataSet.PARAMETERSDataTable dt = parametersTableAdapter1.GetDataParametersBy(label16.Text); //textBox2.Text = dt[listView1.SelectedIndices[0]].START_POSITION; //textBox3.Text = dt[listView1.SelectedIndices[0]].LENGTH.ToString(); DataRow[] dr = dt.Select("SPN = '" + itc[1].Text + "'"); textBox2.Text = dr[0].ItemArray[2].ToString(); textBox3.Text = dr[0].ItemArray[3].ToString(); } }
private void parametros(string pgn, CIdenti men) { BitArray ba = new BitArray(stringDatosTobyte(men.datos)); string cadena = men.datos; int subdivision = cadena.Length / 14; string[] datos = new string[subdivision]; datos = cargaDatos(cadena, subdivision); for (int v = 0; v < datos.Length; v++) { decodificaion_mensajes_j1939DataSet.PARAMETERSDataTable dt = parametersTableAdapter1.GetDataParametersBy(pgn); for (int i = 0; i < dt.Count; i++) { string tipo = dt[i].TIPO_DATO_LENGTH; if (tipo.Equals("BIT")) { int tam = dt[i].LENGTH; String s = dt[i].START_POSITION; double x = Double.Parse(s); string spn = dt[i].SPN; int bytes = Int32.Parse(s.Substring(0, 1)); int bit = Int32.Parse(s.Substring(2, 1)); decodificaion_mensajes_j1939DataSet.SPNDataTable dtSPN = spnTableAdapter1.GetSPNBy(spn); byte[] datosInvertidos = invierteDatos(datos[v]); string nombre = dtSPN[0].NOMBRE; string offset = dtSPN[0].OFFSET.ToString(); string opprangelow = dtSPN[0].OPERATIONAL_RANGE_LOW.ToString(); string opprangehigh = dtSPN[0].OPERATIONAL_RANGE_HIGH.ToString(); string unidad = dtSPN[0].UNIDAD; string resolution = dtSPN[0].RESOLUTION; string tiempo = men.tiempo; string addLista = " " + nombre + " " + offset.ToString() + " " + spn + " " + offset.ToString() + " " + opprangelow.ToString() + " " + opprangehigh.ToString() + " " + unidad; int cont = 0; int tam2; byte[] aux = new byte[0]; if (tam <= 8) { double rest1 = ((double)(tam + x)) / (double)8;//Operacion //rest += 1; int rest = (int)rest1; //rest = Math.Round(rest); tam2 = (int)rest; if (tam2 == 0) { aux = new byte[1]; } else { aux = new byte[tam2]; } for (int j = bytes - 1; j < datosInvertidos.Length && cont < rest; j++) { aux[cont] += datosInvertidos[j]; cont++; } } else if (tam > 8) { double rest = ((double)(tam + x)) / (double)8;//Operacion //rest += 1; rest = Math.Round(rest); tam2 = (int)rest; aux = new byte[tam2]; for (int j = bytes - 1; j < datosInvertidos.Length && cont < rest; j++) { aux[cont] += datosInvertidos[j]; cont++; } } string bits = String.Empty; int numero; for (int j = aux.Length - 1; j >= 0; j--) { BitArray baux = new BitArray(new byte[] { aux[j] }); if (j == aux.Length - 1) { string bitsAux = Reverse(BitArrayToString(baux)); if (tam <= 8) { numero = tam; bits += bitsAux.Substring(bitsAux.Length - numero, numero); } else { numero = (aux.Length * 8) - tam; bits += bitsAux.Substring(0, 8 - numero); } } else { bits += Reverse(BitArrayToString(baux)); } } bool[] arrayBoolean = new bool[bits.Length]; for (int j = 0; j < bits.Length; j++) { if (bits.Substring(j, 1) == "0") { arrayBoolean[j] = false; } else if (bits.Substring(j, 1) == "1") { arrayBoolean[j] = true; } } bool[] array2 = new bool[tam]; Array.Copy(arrayBoolean, (int)0, array2, (int)0, tam); Array.Reverse(array2);//Da la vuelta long result = 0; for (int j = 0; j < array2.Length; j++) { result += (long)(Math.Pow(2, j) * Convert.ToInt16(array2[j])); } resolution = resolution.Replace(",", "."); double res = double.Parse(resolution); double off = double.Parse(offset); double valor = result + off; this.listView1.Items.Add(new ListViewItem(new string[] { nombre, spn, valor.ToString(), opprangelow + " / " + opprangehigh, unidad, tiempo })); } else if (tipo.Equals("BYTE")) { int numBytes = dt[i].LENGTH; int posIni = Int32.Parse(dt[i].START_POSITION); string spn = dt[i].SPN; decodificaion_mensajes_j1939DataSet.SPNDataTable dtSPN = spnTableAdapter1.GetSPNBy(spn); byte[] datosInvertidos = invierteDatos(men.datos); string nombre = dtSPN[0].NOMBRE; string offset = dtSPN[0].OFFSET.ToString(); string opprangelow = dtSPN[0].OPERATIONAL_RANGE_LOW.ToString(); string opprangehigh = dtSPN[0].OPERATIONAL_RANGE_HIGH.ToString(); string unidad = dtSPN[0].UNIDAD; string resolution = dtSPN[0].RESOLUTION; string tiempo = men.tiempo; string addLista = " " + nombre + " " + offset.ToString() + " " + spn + " " + offset.ToString() + " " + opprangelow.ToString() + " " + opprangehigh.ToString() + " " + unidad; int cont = 0; byte[] aux = new byte[numBytes]; for (int j = posIni - 1; j < datosInvertidos.Length && cont < numBytes; j++) { aux[cont] += datosInvertidos[j]; cont++; } int val = 0; val = byteToInt(aux); resolution = resolution.Replace(".", ","); double res = double.Parse(resolution); double off = double.Parse(offset); double valor = val * res + off; this.listView1.Items.Add(new ListViewItem(new string[] { nombre, spn, valor.ToString(), opprangelow + " / " + opprangehigh, unidad, tiempo })); } } } }
private void parametrosAuxiliar(string pgn, CIdenti men) { BitArray ba = new BitArray(stringDatosTobyte(men.datos)); decodificaion_mensajes_j1939DataSet.PARAMETERSDataTable dt = parametersTableAdapter1.GetDataParametersBy(pgn); for (int i = 0; i < dt.Count; i++) { string tipo = dt[i].TIPO_DATO_LENGTH; if (tipo.Equals("BIT")) { int tam = dt[i].LENGTH; String s = dt[i].START_POSITION; double x = Double.Parse(s); int bytes = Int32.Parse(s.Substring(0, 1)); int bit = Int32.Parse(s.Substring(2, 1)); string spn = dt[i].SPN; decodificaion_mensajes_j1939DataSet.SPNDataTable dtSPN = spnTableAdapter1.GetSPNBy(spn); byte[] datosInvertidos = invierteDatos(men.datos); string nombre = dtSPN[0].NOMBRE; string offset = dtSPN[0].OFFSET.ToString(); string opprangelow = dtSPN[0].OPERATIONAL_RANGE_LOW.ToString(); string opprangehigh = dtSPN[0].OPERATIONAL_RANGE_HIGH.ToString(); string unidad = dtSPN[0].UNIDAD; string resolution = dtSPN[0].RESOLUTION; string tiempo = men.tiempo; string addLista = " " + nombre + " " + offset.ToString() + " " + spn + " " + offset.ToString() + " " + opprangelow.ToString() + " " + opprangehigh.ToString() + " " + unidad; int cont = 0; byte[] aux = new byte[tam]; double rest = ((double)(tam + x)) / (double)8;//Operacion rest += 1; rest = Math.Round(rest); for (int j = bytes - 1; j < datosInvertidos.Length && cont < rest; j++) { aux[cont] += datosInvertidos[j]; cont++; } //Pasar los bytes a bit y contar apartir del bit indicado, el tamaño que especifica el length de la base de datos BitArray ba2 = new BitArray(aux); bool[] array = new bool[ba2.Count];//ba.length ba2.CopyTo(array, 0); bool[] auxiliar = new bool[tam]; Array.Copy(array, (long)5, auxiliar, (long)0, (long)auxiliar.Length); BitArray util = new BitArray(auxiliar); long result = 0; for (int j = 0; j < util.Count; j++) { result += (long)(Math.Pow(2, j) * Convert.ToInt16(util[j])); } resolution = resolution.Replace(",", "."); double res = double.Parse(resolution); double off = double.Parse(offset); double valor = result * res + off; this.general.Add(new ListViewItem(new string[] { nombre, spn, valor.ToString(), opprangelow + " / " + opprangehigh, unidad, tiempo })); } else if (tipo.Equals("BYTE")) { int numBytes = dt[i].LENGTH; int posIni = Int32.Parse(dt[i].START_POSITION); string spn = dt[i].SPN; decodificaion_mensajes_j1939DataSet.SPNDataTable dtSPN = spnTableAdapter1.GetSPNBy(spn); byte[] datosInvertidos = invierteDatos(men.datos); string nombre = dtSPN[0].NOMBRE; string offset = dtSPN[0].OFFSET.ToString(); string opprangelow = dtSPN[0].OPERATIONAL_RANGE_LOW.ToString(); string opprangehigh = dtSPN[0].OPERATIONAL_RANGE_HIGH.ToString(); string unidad = dtSPN[0].UNIDAD; string resolution = dtSPN[0].RESOLUTION; string tiempo = men.tiempo; string addLista = " " + nombre + " " + offset.ToString() + " " + spn + " " + offset.ToString() + " " + opprangelow.ToString() + " " + opprangehigh.ToString() + " " + unidad; int cont = 0; byte[] aux = new byte[numBytes]; for (int j = posIni - 1; j < datosInvertidos.Length && cont < numBytes; j++) { aux[cont] += datosInvertidos[j]; cont++; } int val = 0; val = byteToInt(aux); resolution = resolution.Replace(".", ","); double res = double.Parse(resolution); double off = double.Parse(offset); double valor = val * res + off; this.general.Add(new ListViewItem(new string[] { nombre, spn, valor.ToString(), opprangelow + " / " + opprangehigh, unidad, tiempo })); } } }