Mario me pregunta :
<Espero me puedas ayudar necesito escribir una cadena en un cuadro de texto en valores hexadecimales y enviarlos por un puerto serial y capturar la respuesta y convertirla en hexadecimal ejemplo: enviar 7E000408014E4464 (son valores hexadecimales) capturar la respuesta (también es una cadena)y convertirla a hexadecimal mostrándola en un texbox ya convertida. estoy utilizando C# con sharpdevelop.>
Respuesta : (C# Visual Studio) 🙂
using System; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { System.IO.Ports.SerialPort port = new System.IO.Ports.SerialPort(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string toSend = "454647484950"; for (int ndx = 0; ndx <= toSend.Length-1; ndx+=2) { byte asc = Convert.ToByte(toSend.Substring(ndx, 2), 16); char sendChar = Convert.ToChar(asc); port.Write(sendChar.ToString()); } // // No olvideis que 'E' es '69' en decimal y '45' en Hex byte[] Recibidos = { 69,70,71,72,73}; string hexInString = ""; foreach (int val in Recibidos) { hexInString+=String.Format("{0:x2}",val); } } } }
Saludos,
PepLluis,
Gracias por el aporte.