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
VulpesPosted Jul 24, 2011, 4:09 PM
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.
deepender singlaPosted Jul 24, 2011, 3:53 PM
#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
VulpesPosted Jul 24, 2011, 3:44 PM
deepender singlaPosted Jul 24, 2011, 3:29 PM
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.
VulpesPosted Jul 24, 2011, 3:18 PM
deepender singlaPosted Jul 24, 2011, 3:06 PM
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.
VulpesPosted Jul 24, 2011, 2:55 PM
deepender singlaPosted Jul 24, 2011, 2:19 PM
VulpesPosted Jul 24, 2011, 2:16 PM
deepender singlaPosted Jul 24, 2011, 1:26 PM
maybe this is an issue , how i can make data as a series of unicode character.
VulpesPosted Jul 24, 2011, 1:12 PM
_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 singlaPosted Jul 24, 2011, 1:03 PM
basically it is a 32 servo controller in which we have to give string command like ("#(channel) P(position of servo) /r");
VulpesPosted Jul 24, 2011, 12:39 PM
This link I found (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1228366132) seems to bear that out.
deepender singlaPosted Jul 24, 2011, 12:06 PM
_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.
VulpesPosted Jul 24, 2011, 10:36 AM
VulpesPosted Jul 24, 2011, 10:11 AM
deepender singlaPosted Jul 24, 2011, 9:51 AM
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.
VulpesPosted Jul 24, 2011, 7:30 AM