Bonjour,
Je m'adresse à vous car depuis hier j'ai du mal à trouver la solution :
Je m'explique, je reçois via une liaison série RS232 des caractères du type ("0r'r01jI+9F501") etc...
c'est caractère sont envoyés par un scanner de proximité (SICK).
Il me renvoie tout le temps les nouvelles détections de proximité (Valeur en float).
Comment puis-je décoder ces informations et les traduire en type float ?
Les caractères sont stockés dans une variable string puis affiché sur une Rich Text Box.
J'aimerai les affichés en float toujours dans la RTB
Je vous donne mon code "simplifié" pour récupérer les caractères en string :
En vous remerciant.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public partial class Form1 : Form { internal delegate void SerialDataReceivedEventHandlerDelagate(Object sender, SerialDataReceivedEventArgs e); SerialPort PortCom = new SerialPort(); string InputData = string.Empty; delegate void SetTextCallback(string text); public Form1() { PortCom.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived_1); } private void port_DataReceived_1(object sender, SerialDataReceivedEventArgs e) { InputData = PortCom.ReadExisting(); //Récupération des caractères if (InputData != String.Empty) { this.BeginInvoke(new SetTextCallback(SetText), new object[] { InputData }); } } private void SetText(string text) { this.RTB_Data.Text += text; //Envoie les caractères dans la RTB } }
Cordialement,
Steph
Partager