IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

Afficher des informations dans une ListView


Sujet :

Windows Forms

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Inscrit en
    Avril 2007
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 2
    Par défaut Afficher des informations dans une ListView
    j ai fais un programme pour un appareil qui permet de calculer la quantite d oxigene ds le corps et fréquence cardiaque et j aimerai montrer ces valeur ds la listview ou sur label et ca ce que j arrive pas a le realiser .
    avec laide de messagebox.show je peux voir tout mes resultas quand j essaye a ecrire les resultat ds label je recois um mess d exception:Cross-thread operation not valid: Control 'label_HR' accessed from a thread other than the thread it was created on. y a t il qlq qui peut m aide a resoudre ce problem


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    using System.Threading;
    using System.Globalization;
    using System.IO;

    namespace spo2
    {
    public partial class Form1 : Form
    {/*++++++++++++++++++++++++++++++++++++++++++++*
    CSPO2Sensor
    *+++++++++++++++++++++++++++++++++++++++++*/

    [DllImport("kernel32.dll")]
    public static extern bool Beep(int Frequenz, int Dauer);
    byte[] buffer = new Byte[5] { 0, 0, 0, 0, 0 };
    byte msbHR = 0; // Heartrate high Byte
    byte lsbHR = 0; // Heartrate low Byte
    byte SB = 0;
    public int nHR = 0; // Heartrate
    public int nSpO2 = 0; // Oxygensaturation

    public Form1()
    {
    InitializeComponent();


    }

    public void Init_SerialPort()
    {
    Debug.WriteLine("In Init_SerialPort method.");
    serialPort1.BaudRate = 9600;
    serialPort1.DataBits = 8;
    serialPort1.PortName = "COM1";
    serialPort1.ReceivedBytesThreshold = 1;
    serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort1_DataReceived);
    Debug.WriteLine("Out Init_SerialPort method.");

    }



    public void holeDaten()
    {
    try
    {
    Debug.WriteLine("In holeDaten");

    serialPort1.Read(buffer, 0, 1);

    if (buffer[0] == 0x01)
    {
    serialPort1.Read(buffer, 1, 4);

    if ((buffer[1] & 0x81) == 0x81)
    {
    Analyse();

    }

    }

    }
    catch( Exception exception)
    {
    Debug.Write(exception.Message);
    }


    }





    public void Analyse()
    {
    try
    {

    SB = buffer[1];
    msbHR = buffer[(3 & 0x03)];
    serialPort1.Read(buffer, 0, 5);
    lsbHR = buffer[3 & 0x7f];
    serialPort1.Read(buffer, 0, 5);
    nSpO2 = buffer[3];
    nHR = (msbHR * 128) + lsbHR;



    /* if (nSpO2 == 127)
    {
    nSpO2 = 0;
    String sSPO2 = "nSpO2 =127 ,bad data :" + nSpO2.ToString();
    label_SPO2.Text = sSPO2;


    }
    if (nHR == 511)
    {
    String sHR = "nHR=511 ,bad data :" + nHR.ToString();
    nHR = 0;

    label_HR.Text = sHR;

    //listView_HR.Items.Add("nHR=511 ,bad data :" + nHR);


    }



    if ((SB & 0x02) == 0x02)
    {
    // MessageBox.Show(" Green Perfusion " + SB);
    //list.Items.Add("Green Perfusion :" + SB+" ,nSpO2: " + nSpO2);
    //listBox2.Items.Add("Green Perfusion :" + SB +" ,nHR: "+ nHR);

    }
    if ((SB & 0x04) == 0x04)
    {
    // MessageBox.Show(" Red Perfusion " + SB);

    //listBox1.Items.Add("Red Perfusion :" + SB + " ,nSpO2: " + nSpO2);
    //listBox2.Items.Add("Red Perfusion :" + SB + " ,nHR: " + nHR);


    }
    if ((SB & 0x08) == 0x08)
    {
    // MessageBox.Show(" Sensor Alarm " + SB);
    //listBox1.Items.Add("Sensor Alarm :" + SB + " ,nSpO2: " + nSpO2);
    //listBox2.Items.Add("Sensor Alarm:" + SB + " ,nHR: " + nHR);


    // Alarm();
    }
    if ((SB & 0x10) == 0x10)
    {
    //listBox1.Items.Add(nSpO2);
    // MessageBox.Show(" Out of Track " + SB);
    //listBox1.Items.Add("Out of Track :" + SB + " ,nSpO2: " + nSpO2);
    //listBox2.Items.Add("Out of Track :" + SB + " ,nHR: " + nHR);

    }
    if ((SB & 0x20) == 0x20)
    {
    // MessageBox.Show(" Bad Pulse " + SB);
    //listBox1.Items.Add("Bad Pulse:" + SB + " ,nSpO2: " + nSpO2);
    //listBox2.Items.Add("Bad Pulse :" + SB + " ,nHR: " + nHR);


    }
    if ((SB & 0x40) == 0x40)
    {
    // MessageBox.Show(" Sensor disconnected " + SB);
    //listBox1.Items.Add("Sensor disconnected :" + SB + " ,nSpO2: " + nSpO2);
    //listBox2.Items.Add("Sensor disconnected :" + SB + " ,nHR: " + nHR);
    }*/

    Application.DoEvents();
    Debug.WriteLine("out holeDaten");

    }
    catch( Exception exception)

    {
    Debug.WriteLine(exception.Message);
    }

    label_HR.Text = nHR.ToString();
    label_SPO2.Text = nSpO2.ToString();
    MessageBox.Show(" nspo2=" + nSpO2 + " nhr= " + nHR);
    }



    /* ++++++++++++++++ Daten von serieller Schnittstelle lesen ++++++++++++++++ */


    public void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
    {
    Debug.WriteLine("IN serialport1_Dtareceived"); ;
    try
    {

    holeDaten();


    Debug.WriteLine("erste Byte suchen ");
    }

    catch( Exception exception)
    {
    Debug.WriteLine(exception.Message);
    }

    Debug.WriteLine("OUT serialport1_datareceived");


    }
    private void Alarm()
    {

    Beep(1500, 1300);
    }


    private void button1_Click(object sender, EventArgs e)
    {
    try
    {


    Init_SerialPort();
    serialPort1.Open();





    }
    catch (Exception ex)
    {
    Debug.WriteLine(ex.Message);
    }
    }

    private void label_SPO2_Click(object sender, EventArgs e)
    {

    }



    private void listView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {
    Alarm();
    }



    }

    }
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. Récupérer des informations dans une ListView (par exemple un ID)
    Par Berlo56 dans le forum Composants graphiques
    Réponses: 7
    Dernier message: 06/06/2014, 08h46
  2. Afficher des images dans une listView de manière asynchrone
    Par badaboo dans le forum Composants graphiques
    Réponses: 0
    Dernier message: 23/02/2010, 09h47
  3. [AC-2003] Afficher des information dans une infobulle
    Par Rikou31 dans le forum VBA Access
    Réponses: 0
    Dernier message: 07/05/2009, 14h31
  4. Afficher des informations dans une bulle au survol d'une partie d'une carte
    Par JackBeauregard dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 10/06/2008, 08h43
  5. Afficher des informations dans une liste déroulante
    Par onlytime dans le forum Langage
    Réponses: 1
    Dernier message: 08/03/2008, 18h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo