Respected members
plz help, i am struck on it very badly , i have one string data (local variable) i want to convert it into class sytem,string (represent text as a series of unicode character ) how i can do that?
thanks in advance
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Jul 24, 2011, 5:48 PM
Guest UserPosted Jul 24, 2011, 2:54 PM
deepender singlaPosted Jul 24, 2011, 2:47 PM
Guest UserPosted Jul 24, 2011, 2:44 PM
You can pass either one to the _serialPort.Write method.
deepender singlaPosted Jul 24, 2011, 2:30 PM
The reason why there's a slight difference in intellisense is that 'data' is a string variable but "#3 P1546 \r" is a string literal.
Guest UserPosted Jul 24, 2011, 2:25 PM
port.Encoding = new System.Text.UnicodeEncoding();
deepender singlaPosted Jul 24, 2011, 2:23 PM
Respected member
when i use this Console.Writeline(data=="#3 P1500 \r");
i am getting false so how i convert data into that form
Guest UserPosted Jul 24, 2011, 2:20 PM
deepender singlaPosted Jul 24, 2011, 2:01 PM
initally i am getting data value serially from one hardware using this code and storing it in a text file:
#region Namespace Inclusions using System; using System.IO.Ports; using System.Windows.Forms; #endregion namespace SerialPortExample { class SerialPortProgram { // Create the serial port with basic settings private SerialPort port = new SerialPort("COM4", 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, SerialDataReceivedEventArgs e) { // Show all the incoming data in the port's buffer string data = port.ReadExisting(); Console.WriteLine(data); System.IO.File.WriteAllText("C://Users//intel//Documents//Visual Studio 2010//Projects//ConsoleApplication2//serialdata.txt", data); port.Close(); } } }then in my second application i am reading the data and using it in this application to trasfer it to other hardware serially for that i am using this codeusing System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO.Ports; using System.Threading; namespace cConsoleAppMonitorServoCompletion { class Program { static SerialPort _serialPort; static void Main(string[] args) { _serialPort = new SerialPort("COM1",115200,Parity.None,8,StopBits.One); _serialPort.Open(); string data = System.IO.File.ReadAllText("C://Users//intel//Documents//Visual Studio 2010//Projects//ConsoleApplication2//serialdata.txt"); Console.WriteLine(data); data.ToString(); Thread.Sleep(200); _serialPort.Write(data); Thread.Sleep(10); _serialPort.Close(); } } }now this is not working but if i write
_serialPort.Write("#3 P1200 \r");
my hardware is working i dont know what is the problem even though my data is this #3 P1200 \r
Guest UserPosted Jul 24, 2011, 1:55 PM
string myText;
is the same as
System.String myText;