Hello Respected members
i am working on an application in which i got an input value from com4 in my console application code for which is this:
#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
Console.WriteLine(port.ReadExisting());
port.Close();
}
}
}
now i want to send this value obtained to a new serial port com1 , how i can do that , in my view event hough i create another application i am sending data to com1 how i can use this console output as input to another application, plz help i will be very thankfull to you . i am struck on it badly.
Loading

VulpesRank #55 · 29.2K reputationPosted Jul 24, 2011, 3:30 AM EDT
deepender singla111 reputationPosted Jul 24, 2011, 5:51 AM EDT
thanks sir for a prompt reply , i am a beginner and will like to use your second method that is a Process.StartInfo.Arguments property than my next process will use it , but sir can you tell me how i can do that because i am a starter and don't know much about it , basically can you guide me where in my above code i can put that command of saving incoming value to read and than how i can use this text file to give write string command in my other program , i will be very thankfull to you if you can help a bit.
VulpesRank #55 · 29.2K reputationPosted Jul 24, 2011, 6:11 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 24, 2011, 6:36 AM EDT
deepender singla111 reputationPosted Jul 24, 2011, 8:06 AM EDT
_serialPort.Write("#3 P2345 /r"); it is basically represent text as a series of unicode character
and my data in serial text is also this "#3 P2345 /r" , then also the results are not coming , i am uisng this command -serialPort.write(data); where data is coming local variable string data
it is not working , i have put console.writeline(data);
which only show command required for output which is "#3 P2345 /r" , now what should i do. plz help.
VulpesRank #55 · 29.2K reputationPosted Jul 24, 2011, 8:39 AM EDT
This link I found (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1228366132) seems to bear that out.
deepender singla111 reputationPosted Jul 24, 2011, 9:03 AM EDT
basically it is a 32 servo controller in which we have to give string command like ("#(channel) P(position of servo) /r");
VulpesRank #55 · 29.2K reputationPosted Jul 24, 2011, 9:12 AM EDT
_serialPort.Write("#3 P1233 /r");
but when you store an identical string in the text file, read it into the 'data' variable and then do the following, then it doesn't work:
_serialPort.Write(data);
deepender singla111 reputationPosted Jul 24, 2011, 9:26 AM EDT
maybe this is an issue , how i can make data as a series of unicode character.
VulpesRank #55 · 29.2K reputationPosted Jul 24, 2011, 10:16 AM EDT
deepender singla111 reputationPosted Jul 24, 2011, 10:19 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 24, 2011, 10:55 AM EDT
deepender singla111 reputationPosted Jul 24, 2011, 11:06 AM EDT
my data in serial data txt is this #3 P1546 \r
but when i use data this "#3 P1546 \r" i get the same value you got for foreach(char c in "#3 P1546 \r") Console.Write("{0:X2} ", (int)c);
now but in console it is given false because it is taking "#3 P1546 \r" as a unicode string.
VulpesRank #55 · 29.2K reputationPosted Jul 24, 2011, 11:18 AM EDT
deepender singla111 reputationPosted Jul 24, 2011, 11:29 AM EDT
in my view the problem is that it is taking data as a local varaible (string) and "#3 P1546 \r"; as a text as a series of unicode character thats why at the console also it is showing false.
VulpesRank #55 · 29.2K reputationPosted Jul 24, 2011, 11:44 AM EDT
deepender singla111 reputationPosted Jul 24, 2011, 11:53 AM EDT
#3 P1546 \r and then ur program:
and it works i am really very much thankfull to you one last question then when i am getting value programtically what i need to do bring do i need to bring \r or not .
again sorry for wasting your time for so much long , basically i am a student from india working on a cost effective prosthetic arm for community with the help of intel technologies
VulpesRank #55 · 29.2K reputationPosted Jul 24, 2011, 12:09 PM EDT
However, the only way to find out is to try it and see. If it doesn't work, then you can always append "\r" to the string manually.