-
November 25th, 2015, 11:02 AM
#1
redirecting serial port output into a text file
windows 7, 64 bit, MSVS 2010, SP1
I am trying to get data from a serial port and store in a file. So far I have been able to get the data sent from my serial device onto a text box of the PC application written in **Windows Form application with C++**. The segment of the relevant code is show below:
**Code #1**
// Read button --------------------------------------
//this will start the asyn for backgroundwork
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
// check if port is ready for reading
if(this->_serialPort->IsOpen){
// Reset the text in the result label.
this->textBox2->Text = String::Empty;
// this will read manually
try{
this->textBox2->Text=this->_serialPort->ReadLine();
}
catch(TimeoutException^){
this->textBox2->Text="Timeout Exception";
}
// Disable the init button
// the asynchronous operation is done.
this->button2->Enabled = false;
this->ovalShape1->FillColor= Color::Green;
}
else
// give error warning
this->textBox2->Text="Port Not Opened";
}
The data is coming in textbox2 (in above code) and this the data I want to save in a text file.
Though I know how to write strings from structures or arrays into a file:
**Code #2**
string[] names = new string[] { "Ravi", "Kumar","sharma" };
using (StreamWriter sw = new StreamWriter("names.txt"))
{
foreach (string s in names)
{
sw.WriteLine(s);
}
}
But I am unable to write the data coming from **serial port** in to a file instead of on textbox as my present **code #1** shows.
Please tell me what modifications in **Code# 1** will be required in order to save the data into a text file.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|