我有一个问题,我必须将大量数据保存到一个 txt 文件中,问题是我每 100ns 从一个串口接收它们。我能怎么做?我试图将数据放在 RichTextBox 上,但收到线程错误。对不起我的英语不好。
我正在使用 Windows 7 64 位
private: void FindPorts(void)
{
array<Object^>^ ListaPorte = SerialPort::GetPortNames();
this->cmbPort->Items->AddRange(ListaPorte);
}
private: System::Void btnOpenPort_Click(System::Object^ sender, System::EventArgs^ e)
{
if(this->cmbPort->Text==String::Empty || this->cmbBaudRate->Text==String::Empty)
this->rtbLog->Text="cmbError";
else
{
try{
if(!this->serialPort->IsOpen)
{
this->serialPort->PortName = this->cmbPort->Text;
this->serialPort->BaudRate = Int32::Parse(this->cmbBaudRate->Text);
this->serialPort->Open();
this->rtbLog->Text+="Porta aperta\r\n";
this->btnOpenPort->Text="Close Port";
}
else
{
this->serialPort->Close();
this->rtbLog->Text+="Porta chiusa\r\n";
this->btnOpenPort->Text="Open Port";
}
}
catch(UnauthorizedAccessException^)
{
this->rtbLog->Text+="UnauthorizedAccessException\r\n";
}
}
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
if(!lettura)
{
lettura = true;
this->button1->Text="sto leggendo";
}
else
if(lettura)
{
lettura=false;
//rtbLog->Text += letturaBuffer;
this->button1->Text="sono ferma";
}
//serialPort->
}
private: System::Void serialPort_DataReceived(System::Object^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e)
{
if(lettura){
//letturaBuffer += serialPort->ReadExisting() + "\r\n";
rtbLog->Text += serialPort->ReadExisting() + "\r\n";
}
}