Langsung ke konten utama

Postingan

Menampilkan postingan dari Juli, 2018

To Read and Write From Serial Port C#

using System ; using System . IO . Ports ; using System . Windows . Forms ; namespace SerialPortExample { class SerialPortProgram { // Create the serial port with basic settings private SerialPort port = new SerialPort ( "COM1" , 9600 , Parity . None , 8 , StopBits . One ); [ STAThread ] static void Main ( string [] args ) { // Instatiate this class new SerialPortProgram (); } private SerialPortProgram () { Console . WriteLine ( "Incoming Data:" ); // Attach a method to be called when there // is data waiting in the port's buffer port . DataReceived += new SerialDataReceivedEventHandler ( port_DataReceived ); // Begin communications port . Open (); // Enter an application loop to keep this thread alive Application . Run (); } private void port_DataReceived ( object sender , SerialDataR

String to hexadecimal and back C#

This is code to convert String to Hex and Back using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace hexTester {     public class Program     {         public static void Main(string[] args)         {             string a = "testing";             Console.WriteLine(a);             string hex = ConvertStringToHex(a);             Console.WriteLine(hex);             Console.WriteLine(ConvertHexToString(hex));         }                 public static string ConvertStringToHex(string asciiString)         {             string hex = "";             foreach (char c in asciiString)             {                 int tmp = c;                 hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString()));             }             return hex;         }             public static string ConvertHexToString(string HexValue)         {             string StrValue = &qu