まず第一に、私はハードウェア プログラマー (HDL、uC プログラミング) で、数日前に上司から uC を制御するためのビジュアル C++ でインターフェイスを作成するように依頼されました。以前はビジュアル C++ を使用したことがなく、私のソフトウェア プログラミング スキルはせいぜい中級程度です。ただし、インターフェイスを機能させるには火曜日までしかありません。したがって、時間枠のために、例を探して同じことをしなければなりませんでした。ですから、明白でばかげた質問をした場合は、ご容赦ください。
私のコードでは、配列に格納されている値を CSV ファイルに移動する必要があります。そのため、カンマを使用して値を区切る必要があります...ただし、CSVファイルを作成するには、fstreamを使用する必要があります(これまで読んだことから理解した限り)。私が使うたびに
#include <fstream>
次のような大量のエラーが発生します。
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(244): error C3083: 'vc_attributes': the symbol to the left of a '::' must be a type
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(244): error C2039: 'YesNoMaybe' : is not a member of '`global namespace''
fstream に関連する残りのコードは次のとおりです。
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO::Ports;
#include <iostream>
#include <fstream>
std::ofstream myfile;
myfile.open("Data.txt");
//find available ports
private: void findports(void){
array<Object^>^ objectArray = SerialPort::GetPortNames();
this->comboBox4->Items->AddRange( objectArray );
array<String ^> ^ h = gcnew array<String ^>(24);
for(int i=0; i<=23; i++){
h[i]= String::Concat(i.ToString());
}
this->comboBox1->Items->AddRange( h );
array<String ^> ^ m = gcnew array<String ^>(60);
for(int i=0; i<=59; i++){
m[i]= String::Concat(i.ToString());
}
this->comboBox3->Items->AddRange( m );
array<String ^> ^ s = gcnew array<String ^>(24);
for(int i=0; i<=23; i++){
s[i]= String::Concat(i.ToString());
}
this->comboBox5->Items->AddRange( s );
array<String ^> ^ d = gcnew array<String ^>(366);
for(int i=0; i<=365; i++){
d[i]= String::Concat(i.ToString());
}
this->comboBox2->Items->AddRange( d);
}
private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label2_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label4_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label5_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label6_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if((this->comboBox4->Text == String::Empty)||(this->textBox1->Text == String::Empty)||(this->textBox2->Text == String::Empty)){
this->textBox1->Text="missing port settings";
this->textBox2->Text="missing port settings";
}
else{ // start assigning
try{ // first make sure port isn't busy/open
if(!this->serialPort1->IsOpen){
// select the port whose name is in comboBox4 (select port)
this->serialPort1->PortName=this->comboBox4->Text;
//open the port
this->serialPort1->Open();
// sending
String^ name_ = this->serialPort1->PortName;
String^ sampling_period_ = this->comboBox5->Text;
String^ days_ = this->comboBox2->Text;
String^ hours_ = this->comboBox3->Text;
String^ minutes_ = this->comboBox1->Text;
String^ start_ = this->textBox1->Text;
String^ end_ = this->textBox2->Text;
//send data to setup timer on the microcontroller
this->serialPort1->WriteLine(sampling_period_);
this->serialPort1->WriteLine(days_);
this->serialPort1->WriteLine(hours_);
this->serialPort1->WriteLine(minutes_);
// send slave addresses
this->serialPort1->WriteLine(start_);
this->serialPort1->WriteLine(end_);
// receiving
int rec[100][8];
for (int i=0;i<sizeof(rec[0]);i++){
for (int j=0;j<sizeof(rec);j++){
rec[i][j]=int::Parse(this->serialPort1->ReadLine());
}
}
myfile<<"ADC1"<<","<<"ADC2"<<","<<"ADC3"<<","<<"ADC4"<<","<<"ADC5"<<","<<"ADC6"<<","<<"ADC7"<<","<<"ADC8"<<endl;
for (int i=0;i<sizeof(rec[0]);i++){
for (int j=0;j<sizeof(rec);j++){
myfile<<rec[i][j]<<",";
}
myfile<<endl;
}
}
else{
this->textBox1->Text="Warning: port is busy or isn't open";
this->textBox2->Text="Warning: port is busy or isn't open";
}
}
catch(UnauthorizedAccessException^){
this->textBox1->Text="Unauthorized access";
this->textBox2->Text="Unauthorized access";
}
}
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label7_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label8_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}
ここで何らかの助け、または少なくとも有用な情報を得られることを願っています。
前もって感謝します。