#pragma once #define SAMPLE_NUM 11490 #define OFFSET_X0G 12596512 //kxr94*1 ads1247 外部ref #define OFFSET_X1G 14233474 #define OFFSET_Y0G 12569137 #define OFFSET_Y1G 14233474 #define OFFSET_Z0G 12596512 #define OFFSET_Z1G 14233474 #define TIMER_INTERVAL 4000 #include #include #include #include "time.h" #include "fft.h" namespace vc232 { using namespace System; using namespace System::Windows::Forms; using namespace System::Drawing; using namespace System::Diagnostics; using namespace System::Collections::Generic; using namespace System::IO; using namespace std; public ref class Form1 : public System::Windows::Forms::Form { //受信スレッドから文字を取り込みテキストボックス textboxにデータを //書き込むデリゲート関数を宣言する。 delegate void mySetTextCallback(String^ text); public: Form1(void) { InitializeComponent(); listBox1->Items->Clear(); array^ serialPorts = nullptr; serialPorts = System::IO::Ports::SerialPort::GetPortNames(); for each(String^ port in serialPorts) { listBox1->Items->Add(port); } comboBox1->Items->Clear(); comboBox1->Items->Insert(0,"r"+(SAMPLE_NUM.ToString("X"))); comboBox1->Items->Insert(1,"e"); comboBox1->Items->Insert(2,"c080001"); comboBox1->Items->Insert(3,"c100080"); comboBox1->SelectedIndex = 0; setref(); serialPort1->BaudRate = 9600; //9600bps serialPort1->Parity = System::IO::Ports::Parity::None; //パリティなし serialPort1->DataBits = 8; //データ長 8ビット serialPort1->StopBits = System::IO::Ports::StopBits::One; //ストップビット 1 serialPort1->NewLine = "\r\n";//ReadLine(),WriteLine()が末尾と判断する値の設定 //\r\n:defalut Windows \n: Unix Graphics^ graphics = Graphics::FromImage(pictureBox1->InitialImage); Image^ image = gcnew Bitmap(pictureBox1->Size.Width, pictureBox1->Size.Height, graphics); Graphics^ graphics2 = Graphics::FromImage(image); graphics2->Clear(Color::White); pictureBox1->Image = image; pen = gcnew Pen(Color::Blue); white = gcnew Pen(Color::White); red = gcnew Pen(Color::Red); imgrefresh=0; refreshbusy=false; imgrefreshlist=gcnew array(20, 5); timer1->Interval = TIMER_INTERVAL; this->timertmpx = gcnew List(); this->timertmpy = gcnew List(); this->timertmpz = gcnew List(); } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) //開始 { if(serialPort1->IsOpen==false){return;} String^ strSend = comboBox1->Text; if (!strSend->EndsWith("\r")) strSend += "\r"; //改行が無かったら \rを追加する cleartmp(); this->runflag=1; timerproc=false; timer1->Enabled = true; #if !defined(NO_USB_SEND) serialPort1->Write(strSend); #endif } private: System:: Void serialPort1_DataReceived(System::Object^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e) { SetText(serialPort1->ReadExisting()); } void setref(void) { bool err=false; String^ fileName = "vc232.conf"; try { StreamReader^ din = File::OpenText(fileName); String^ str; int count = 0; str = din->ReadLine(); if(str != nullptr) { String^ delimStr = ","; array^ delimiter = delimStr->ToCharArray( ); array^ words; str=str->Replace("\r",""); str=str->Replace("\n",""); words = str->Split( delimiter ); xref=Convert::ToDouble(words[0]); yref=Convert::ToDouble(words[1]); zref=Convert::ToDouble(words[2]); }else{ err=true; } } catch (Exception^ e) { if (dynamic_cast(e)){ Debug::WriteLine("file '{0}' not found", fileName); }else{ Debug::WriteLine("problem reading file '{0}'", fileName); } err=true; } if(err){ xref=OFFSET_X0G; yref=OFFSET_Y0G; zref=OFFSET_Z1G; } textBox19->Text=xref.ToString("F0"); textBox18->Text=yref.ToString("F0"); textBox17->Text=zref.ToString("F0"); } void SetText(String^ text) { if (this->textBox1->InvokeRequired) //invoke メソッドを呼び出す必要があるなら //別スレッドからの呼び出しであるなら { mySetTextCallback^ d = gcnew mySetTextCallback(this,&vc232::Form1::SetText); //デリゲート関数へのインスタンスを生成し、SetText()関数へ割り当てる。 this->BeginInvoke(d,gcnew String(text)); //BeginInvokeにしないとserialPort1->Close()のときフリーズする // this->Invoke(d,gcnew String(text)); //デリゲートの非同期実行機能により、メインスレッドの //textBox1テキストボックスへ、受信時刻とは時間差をもって書き込む } else { if(this->runflag==0){return;} array^ sep = gcnew array{'\n'}; array^ TextArr = text->Split(sep,StringSplitOptions::RemoveEmptyEntries); for each(String^ resline in TextArr) { int a; resline=resline->Replace("\r",""); resline=resline->Replace("\n",""); if(resline->Length==6||resline->Length==7){ this->countrec++; String^ vect = resline->Substring(resline->Length-1,1); a=Convert::ToInt32(resline->Substring(0,6),16); ///加速度計算 double gal=a; if(vect=="0"){ #if !defined(FORCE_OFFSET) gal=(gal-xref)*980/(zref-xref); #else gal=(gal-OFFSET_X0G)*980/(OFFSET_X1G-OFFSET_X0G); #endif if(xmin>gal){ xmin=gal; } if(xmaxText=gal.ToString("F3"); textBox4->Text=(xave/xcnt).ToString("F3"); textBox8->Text=(xraw/xcnt).ToString("F0"); textBox14->Text=sqrt((xvar/xcnt-(xave/xcnt)*(xave/xcnt))).ToString("F3"); textBox7->Text=(xmax-xmin).ToString("F3"); if(!timerproc){timertmpx->Add(gal);} } if(vect=="1"){ #if !defined(FORCE_OFFSET) gal=(gal-yref)*980/(zref-yref); #else gal=(gal-OFFSET_Y0G)*980/(OFFSET_Y1G-OFFSET_Y0G); #endif if(ymin>gal){ ymin=gal; } if(ymaxText=gal.ToString("F3"); textBox9->Text=(yave/ycnt).ToString("F3"); textBox3->Text=(yraw/ycnt).ToString("F0"); textBox12->Text=sqrt((yvar/ycnt-(yave/ycnt)*(yave/ycnt))).ToString("F3"); textBox11->Text=(ymax-ymin).ToString("F3"); if(!timerproc){timertmpy->Add(gal);} } if(vect=="2"){ #if !defined(FORCE_OFFSET) gal=(gal-(xref+yref)/2)*980/(zref-(xref+yref)/2)-980; #else gal=(gal-OFFSET_Z0G)*980/(OFFSET_Z1G-OFFSET_Z0G)-980; #endif if(zmin>gal){ zmin=gal; } if(zmaxText=gal.ToString("F3"); textBox13->Text=(zave/zcnt).ToString("F3"); textBox2->Text=(zraw/zcnt).ToString("F0"); textBox10->Text=sqrt((zvar/zcnt-(zave/zcnt)*(zave/zcnt))).ToString("F3"); textBox15->Text=(zmax-zmin).ToString("F3"); if(!timerproc){timertmpz->Add(gal);} } ////画像処理 int T=countrec*1000/SAMPLE_NUM; addline(1,T+1,124,T+1,132); //graphics->DrawLine(red,T+1,124,T+1,132); if(T>=1000){ addline(0,0,0,0,256); //graphics->DrawLine(white,0,0,0,256); } switch(Convert::ToInt32(vect)){ case 0: textBox1->Clear(); textBox1->AppendText(a.ToString()); a=(int)((gal-(xave/xcnt))*10+50); if(lasttx!=T){ addline(0,T,0,T,99); //graphics->DrawLine(white,T,0,T,99); } addline(2,this->lasttx,this->lastx,T,a);//graphics->DrawLine(pen,this->lasttx,this->lastx,T,a); this->lastx=a; this->lasttx=T; break; case 1: textBox5->Clear(); textBox5->AppendText(a.ToString()); a=(int)((gal-(yave/ycnt))*10+150); if(lastty!=T){ addline(0,T,100,T,199); //graphics->DrawLine(white,T,100,T,199); } addline(2,this->lastty,this->lasty,T,a);//graphics->DrawLine(pen,this->lastty,this->lasty,T,a); this->lasty=a; this->lastty=T; break; case 2: textBox6->Clear(); textBox6->AppendText(a.ToString()); a=(int)((gal-(zave/zcnt))*10+250); if(lasttz!=T){ addline(0,T,200,T,299); //graphics->DrawLine(white,T,200,T,299); } addline(2,this->lasttz,this->lastz,T,a);//graphics->DrawLine(pen,this->lasttz,this->lastz,T,a); this->lastz=a; this->lasttz=T; break; } Graphics^ graphics3 = Graphics::FromImage(pictureBox2->InitialImage); Image^ image3 = gcnew Bitmap(pictureBox2->Size.Width, pictureBox2->Size.Height, graphics3); Graphics^ graphics4 = Graphics::FromImage(image3); graphics4->Clear(Color::White); SolidBrush^ xyBrush = gcnew SolidBrush( Color::Blue ); graphics4->FillEllipse(xyBrush,lastx-50+34-2,lasty-150+34-2,5,5); pictureBox2->Image = image3; if(imgrefresh>10 && !refreshbusy){ refreshbusy=true; if(imgrefresh>98){refreshbusy=false;imgrefresh=0;return;} int refreshlocal=0; Image^ image = (Image^)pictureBox1->Image->Clone(); Graphics^ graphics = Graphics::FromImage(image); do{ //graphics->DrawLine()の本体を書く int col=imgrefreshlist[refreshlocal,0]; int xfm=imgrefreshlist[refreshlocal,1]; int yfm=imgrefreshlist[refreshlocal,2]; int xto=imgrefreshlist[refreshlocal,3]; int yto=imgrefreshlist[refreshlocal,4]; if(col==0){graphics->DrawLine(white,xfm,yfm,xto,yto);} if(col==1){graphics->DrawLine(red,xfm,yfm,xto,yto);} if(col==2){graphics->DrawLine(pen,xfm,yfm,xto,yto);} if(col==3){ String^ drawString = ((double)xto/10).ToString("F1"); System::Drawing::Font^ drawFont = gcnew System::Drawing::Font( "Arial",7 ); SolidBrush^ drawBrush = gcnew SolidBrush( Color::Black ); PointF drawPoint = PointF((float)T-15,290.0F); graphics->DrawString( drawString, drawFont, drawBrush, drawPoint ); } refreshlocal++; }while(imgrefresh>refreshlocal); imgrefresh=0; pictureBox1->Image = image; refreshbusy=false; } ////画像処理おわり }else{ textBox16->AppendText(resline+"\r\n"); } } if(this->countrec>=SAMPLE_NUM){ if(this->runflag==1){ if(max_kshindo>0){ // ymax-ymin>2.5 DateTime dtToday = DateTime::Now::get(); pictureBox1->Image->Save(dtToday.ToString("yyMMdd-HHmmss")+".png"); } #if !defined(NO_USB_SEND) serialPort1->Write("r"+(SAMPLE_NUM.ToString("X"))+"\r"); #endif cleartmp(); } this->countrec=0; } } } void addline(int col,int xfm,int yfm,int xto,int yto){ if(imgrefresh<99){ imgrefreshlist[imgrefresh,0]=col; imgrefreshlist[imgrefresh,1]=xfm; imgrefreshlist[imgrefresh,2]=yfm; imgrefreshlist[imgrefresh,3]=xto; imgrefreshlist[imgrefresh,4]=yto; imgrefresh++; } } void cleartmp(void){ this->lasttx=0; this->lastty=0; this->lasttz=0; this->xmax=-99999999; this->xmin=99999999; this->xave=0; this->xraw=0; this->xvar=0; this->xcnt=0; this->ymax=-99999999; this->ymin=99999999; this->yave=0; this->yraw=0; this->yvar=0; this->ycnt=0; this->zmax=-99999999; this->zmin=99999999; this->zave=0; this->zraw=0; this->zvar=0; this->zcnt=0; this->max_kshindo=-999999; } private: System:: Void Form1_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e) { if(serialPort1->IsOpen==false){return;} this->runflag=0; #if !defined(NO_USB_SEND) serialPort1->Write("+\r"); #endif this->serialPort1->DataReceived -= gcnew System::IO::Ports::SerialDataReceivedEventHandler(this, &Form1::serialPort1_DataReceived); //Sleep(300); serialPort1->Close(); } protected: /// /// 使用中のリソースをすべてクリーンアップします。 /// ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::Button^ button1; protected: private: System::Windows::Forms::ComboBox^ comboBox1; private: System::Windows::Forms::TextBox^ textBox1; private: System::IO::Ports::SerialPort^ serialPort1; private: System::Windows::Forms::Button^ button2; Pen^ pen; Pen^ white; Pen^ red; private: int countrec; private: int lasttx; private: int lastty; private: int lasttz; private: int runflag; private: int lastx; private: int lasty; private: int lastz; private: double xref; private: double yref; private: double zref; private: double xmax; private: double ymax; private: double zmax; private: double xmin; private: double ymin; private: double zmin; private: double xave; private: double yave; private: double zave; private: double xraw; private: double yraw; private: double zraw; private: double xvar; private: double yvar; private: double zvar; private: double xcnt; private: double ycnt; private: double zcnt; private: double max_kshindo; private: List^ timertmpx; private: List^ timertmpy; private: List^ timertmpz; private: bool timerproc; private: bool refreshbusy; private: int imgrefresh; private: array^ imgrefreshlist; private: System::Windows::Forms::ListBox^ listBox1; private: System::Windows::Forms::Button^ button3; private: System::Windows::Forms::PictureBox^ pictureBox1; private: System::Windows::Forms::Button^ button4; private: System::Windows::Forms::TextBox^ textBox4; private: System::Windows::Forms::Label^ label3; private: System::Windows::Forms::TextBox^ textBox5; private: System::Windows::Forms::Label^ label4; private: System::Windows::Forms::Label^ label5; private: System::Windows::Forms::Label^ label6; private: System::Windows::Forms::TextBox^ textBox6; private: System::Windows::Forms::TextBox^ textBox7; private: System::Windows::Forms::Label^ label7; private: System::Windows::Forms::TextBox^ textBox9; private: System::Windows::Forms::TextBox^ textBox11; private: System::Windows::Forms::TextBox^ textBox13; private: System::Windows::Forms::TextBox^ textBox15; private: System::Windows::Forms::Timer^ timer1; private: System::Windows::Forms::TextBox^ textBox16; private: System::Windows::Forms::PictureBox^ pictureBox2; private: System::Windows::Forms::Label^ label8; private: System::Windows::Forms::TextBox^ textBox2; private: System::Windows::Forms::TextBox^ textBox3; private: System::Windows::Forms::TextBox^ textBox8; private: System::Windows::Forms::Label^ label13; private: System::Windows::Forms::TextBox^ textBox10; private: System::Windows::Forms::TextBox^ textBox12; private: System::Windows::Forms::TextBox^ textBox14; private: System::Windows::Forms::Label^ label18; private: System::Windows::Forms::TextBox^ textBox17; private: System::Windows::Forms::TextBox^ textBox18; private: System::Windows::Forms::TextBox^ textBox19; private: System::Windows::Forms::Button^ button5; private: System::Windows::Forms::Label^ label19; private: System::Windows::Forms::Label^ label1; private: System::Windows::Forms::TextBox^ textBox20; private: System::Windows::Forms::TextBox^ textBox21; private: System::Windows::Forms::TextBox^ textBox22; private: System::ComponentModel::IContainer^ components; private: /// /// デザイナ サポートに必要なメソッドです。このメソッドの内容を /// コード エディタで変更しないでください。 /// void InitializeComponent(void) { this->components = (gcnew System::ComponentModel::Container()); System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); this->button1 = (gcnew System::Windows::Forms::Button()); this->comboBox1 = (gcnew System::Windows::Forms::ComboBox()); this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->serialPort1 = (gcnew System::IO::Ports::SerialPort(this->components)); this->button2 = (gcnew System::Windows::Forms::Button()); this->listBox1 = (gcnew System::Windows::Forms::ListBox()); this->button3 = (gcnew System::Windows::Forms::Button()); this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); this->button4 = (gcnew System::Windows::Forms::Button()); this->textBox4 = (gcnew System::Windows::Forms::TextBox()); this->label3 = (gcnew System::Windows::Forms::Label()); this->textBox5 = (gcnew System::Windows::Forms::TextBox()); this->label4 = (gcnew System::Windows::Forms::Label()); this->label5 = (gcnew System::Windows::Forms::Label()); this->label6 = (gcnew System::Windows::Forms::Label()); this->textBox6 = (gcnew System::Windows::Forms::TextBox()); this->textBox7 = (gcnew System::Windows::Forms::TextBox()); this->label7 = (gcnew System::Windows::Forms::Label()); this->textBox9 = (gcnew System::Windows::Forms::TextBox()); this->textBox11 = (gcnew System::Windows::Forms::TextBox()); this->textBox13 = (gcnew System::Windows::Forms::TextBox()); this->textBox15 = (gcnew System::Windows::Forms::TextBox()); this->timer1 = (gcnew System::Windows::Forms::Timer(this->components)); this->textBox16 = (gcnew System::Windows::Forms::TextBox()); this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox()); this->label8 = (gcnew System::Windows::Forms::Label()); this->textBox2 = (gcnew System::Windows::Forms::TextBox()); this->textBox3 = (gcnew System::Windows::Forms::TextBox()); this->textBox8 = (gcnew System::Windows::Forms::TextBox()); this->label13 = (gcnew System::Windows::Forms::Label()); this->textBox10 = (gcnew System::Windows::Forms::TextBox()); this->textBox12 = (gcnew System::Windows::Forms::TextBox()); this->textBox14 = (gcnew System::Windows::Forms::TextBox()); this->label18 = (gcnew System::Windows::Forms::Label()); this->textBox17 = (gcnew System::Windows::Forms::TextBox()); this->textBox18 = (gcnew System::Windows::Forms::TextBox()); this->textBox19 = (gcnew System::Windows::Forms::TextBox()); this->button5 = (gcnew System::Windows::Forms::Button()); this->label19 = (gcnew System::Windows::Forms::Label()); this->label1 = (gcnew System::Windows::Forms::Label()); this->textBox20 = (gcnew System::Windows::Forms::TextBox()); this->textBox21 = (gcnew System::Windows::Forms::TextBox()); this->textBox22 = (gcnew System::Windows::Forms::TextBox()); (cli::safe_cast(this->pictureBox1))->BeginInit(); (cli::safe_cast(this->pictureBox2))->BeginInit(); this->SuspendLayout(); // // button1 // this->button1->Location = System::Drawing::Point(577, 60); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(65, 27); this->button1->TabIndex = 0; this->button1->Text = L"開始"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); // // comboBox1 // this->comboBox1->FormattingEnabled = true; this->comboBox1->Location = System::Drawing::Point(503, 68); this->comboBox1->Name = L"comboBox1"; this->comboBox1->Size = System::Drawing::Size(64, 20); this->comboBox1->TabIndex = 1; // // textBox1 // this->textBox1->Location = System::Drawing::Point(30, 18); this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(63, 19); this->textBox1->TabIndex = 2; // // serialPort1 // this->serialPort1->DataReceived += gcnew System::IO::Ports::SerialDataReceivedEventHandler(this, &Form1::serialPort1_DataReceived); // // button2 // this->button2->Location = System::Drawing::Point(577, 18); this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size(65, 27); this->button2->TabIndex = 4; this->button2->Text = L"接続"; this->button2->UseVisualStyleBackColor = true; this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); // // listBox1 // this->listBox1->FormattingEnabled = true; this->listBox1->ItemHeight = 12; this->listBox1->Location = System::Drawing::Point(503, 18); this->listBox1->Name = L"listBox1"; this->listBox1->Size = System::Drawing::Size(64, 40); this->listBox1->TabIndex = 5; // // button3 // this->button3->Location = System::Drawing::Point(655, 60); this->button3->Name = L"button3"; this->button3->Size = System::Drawing::Size(65, 27); this->button3->TabIndex = 6; this->button3->Text = L"停止"; this->button3->UseVisualStyleBackColor = true; this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click); // // pictureBox1 // this->pictureBox1->Location = System::Drawing::Point(12, 92); this->pictureBox1->Name = L"pictureBox1"; this->pictureBox1->Size = System::Drawing::Size(1000, 300); this->pictureBox1->TabIndex = 7; this->pictureBox1->TabStop = false; // // button4 // this->button4->Location = System::Drawing::Point(655, 18); this->button4->Name = L"button4"; this->button4->Size = System::Drawing::Size(65, 27); this->button4->TabIndex = 8; this->button4->Text = L"画像保存"; this->button4->UseVisualStyleBackColor = true; this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click); // // textBox4 // this->textBox4->Location = System::Drawing::Point(319, 18); this->textBox4->Name = L"textBox4"; this->textBox4->Size = System::Drawing::Size(52, 19); this->textBox4->TabIndex = 9; this->textBox4->TextAlign = System::Windows::Forms::HorizontalAlignment::Right; // // label3 // this->label3->AutoSize = true; this->label3->Location = System::Drawing::Point(322, 3); this->label3->Name = L"label3"; this->label3->Size = System::Drawing::Size(44, 12); this->label3->TabIndex = 10; this->label3->Text = L"平均gal"; // // textBox5 // this->textBox5->Location = System::Drawing::Point(30, 43); this->textBox5->Name = L"textBox5"; this->textBox5->Size = System::Drawing::Size(64, 19); this->textBox5->TabIndex = 2; // // label4 // this->label4->AutoSize = true; this->label4->Location = System::Drawing::Point(12, 22); this->label4->Name = L"label4"; this->label4->Size = System::Drawing::Size(12, 12); this->label4->TabIndex = 11; this->label4->Text = L"X"; // // label5 // this->label5->AutoSize = true; this->label5->Location = System::Drawing::Point(12, 46); this->label5->Name = L"label5"; this->label5->Size = System::Drawing::Size(12, 12); this->label5->TabIndex = 12; this->label5->Text = L"Y"; // // label6 // this->label6->AutoSize = true; this->label6->Location = System::Drawing::Point(12, 71); this->label6->Name = L"label6"; this->label6->Size = System::Drawing::Size(12, 12); this->label6->TabIndex = 13; this->label6->Text = L"Z"; // // textBox6 // this->textBox6->Location = System::Drawing::Point(30, 68); this->textBox6->Name = L"textBox6"; this->textBox6->Size = System::Drawing::Size(64, 19); this->textBox6->TabIndex = 2; // // textBox7 // this->textBox7->Location = System::Drawing::Point(439, 18); this->textBox7->Name = L"textBox7"; this->textBox7->Size = System::Drawing::Size(52, 19); this->textBox7->TabIndex = 9; this->textBox7->TextAlign = System::Windows::Forms::HorizontalAlignment::Right; // // label7 // this->label7->AutoSize = true; this->label7->Location = System::Drawing::Point(456, 3); this->label7->Name = L"label7"; this->label7->Size = System::Drawing::Size(17, 12); this->label7->TabIndex = 14; this->label7->Text = L"差"; // // textBox9 // this->textBox9->Location = System::Drawing::Point(319, 43); this->textBox9->Name = L"textBox9"; this->textBox9->Size = System::Drawing::Size(52, 19); this->textBox9->TabIndex = 9; this->textBox9->TextAlign = System::Windows::Forms::HorizontalAlignment::Right; // // textBox11 // this->textBox11->Location = System::Drawing::Point(439, 43); this->textBox11->Name = L"textBox11"; this->textBox11->Size = System::Drawing::Size(52, 19); this->textBox11->TabIndex = 9; this->textBox11->TextAlign = System::Windows::Forms::HorizontalAlignment::Right; // // textBox13 // this->textBox13->Location = System::Drawing::Point(319, 68); this->textBox13->Name = L"textBox13"; this->textBox13->Size = System::Drawing::Size(52, 19); this->textBox13->TabIndex = 9; this->textBox13->TextAlign = System::Windows::Forms::HorizontalAlignment::Right; // // textBox15 // this->textBox15->Location = System::Drawing::Point(439, 68); this->textBox15->Name = L"textBox15"; this->textBox15->Size = System::Drawing::Size(52, 19); this->textBox15->TabIndex = 9; this->textBox15->TextAlign = System::Windows::Forms::HorizontalAlignment::Right; // // timer1 // this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick); // // textBox16 // this->textBox16->Location = System::Drawing::Point(884, 18); this->textBox16->Multiline = true; this->textBox16->Name = L"textBox16"; this->textBox16->Size = System::Drawing::Size(128, 69); this->textBox16->TabIndex = 15; // // pictureBox2 // this->pictureBox2->Location = System::Drawing::Point(804, 18); this->pictureBox2->Name = L"pictureBox2"; this->pictureBox2->Size = System::Drawing::Size(68, 68); this->pictureBox2->TabIndex = 16; this->pictureBox2->TabStop = false; // // label8 // this->label8->AutoSize = true; this->label8->Location = System::Drawing::Point(123, 3); this->label8->Name = L"label8"; this->label8->Size = System::Drawing::Size(29, 12); this->label8->TabIndex = 20; this->label8->Text = L"平均"; // // textBox2 // this->textBox2->Location = System::Drawing::Point(106, 68); this->textBox2->Name = L"textBox2"; this->textBox2->Size = System::Drawing::Size(64, 19); this->textBox2->TabIndex = 17; // // textBox3 // this->textBox3->Location = System::Drawing::Point(106, 43); this->textBox3->Name = L"textBox3"; this->textBox3->Size = System::Drawing::Size(64, 19); this->textBox3->TabIndex = 18; // // textBox8 // this->textBox8->Location = System::Drawing::Point(106, 18); this->textBox8->Name = L"textBox8"; this->textBox8->Size = System::Drawing::Size(63, 19); this->textBox8->TabIndex = 19; // // label13 // this->label13->AutoSize = true; this->label13->Location = System::Drawing::Point(379, 3); this->label13->Name = L"label13"; this->label13->Size = System::Drawing::Size(53, 12); this->label13->TabIndex = 26; this->label13->Text = L"標準偏差"; // // textBox10 // this->textBox10->Location = System::Drawing::Point(379, 68); this->textBox10->Name = L"textBox10"; this->textBox10->Size = System::Drawing::Size(52, 19); this->textBox10->TabIndex = 23; this->textBox10->TextAlign = System::Windows::Forms::HorizontalAlignment::Right; // // textBox12 // this->textBox12->Location = System::Drawing::Point(379, 43); this->textBox12->Name = L"textBox12"; this->textBox12->Size = System::Drawing::Size(52, 19); this->textBox12->TabIndex = 24; this->textBox12->TextAlign = System::Windows::Forms::HorizontalAlignment::Right; // // textBox14 // this->textBox14->Location = System::Drawing::Point(379, 18); this->textBox14->Name = L"textBox14"; this->textBox14->Size = System::Drawing::Size(52, 19); this->textBox14->TabIndex = 25; this->textBox14->TextAlign = System::Windows::Forms::HorizontalAlignment::Right; // // label18 // this->label18->AutoSize = true; this->label18->Location = System::Drawing::Point(196, 3); this->label18->Name = L"label18"; this->label18->Size = System::Drawing::Size(29, 12); this->label18->TabIndex = 32; this->label18->Text = L"基準"; // // textBox17 // this->textBox17->Location = System::Drawing::Point(179, 68); this->textBox17->Name = L"textBox17"; this->textBox17->Size = System::Drawing::Size(64, 19); this->textBox17->TabIndex = 29; // // textBox18 // this->textBox18->Location = System::Drawing::Point(179, 43); this->textBox18->Name = L"textBox18"; this->textBox18->Size = System::Drawing::Size(64, 19); this->textBox18->TabIndex = 30; // // textBox19 // this->textBox19->Location = System::Drawing::Point(179, 18); this->textBox19->Name = L"textBox19"; this->textBox19->Size = System::Drawing::Size(63, 19); this->textBox19->TabIndex = 31; // // button5 // this->button5->Location = System::Drawing::Point(733, 18); this->button5->Name = L"button5"; this->button5->Size = System::Drawing::Size(65, 27); this->button5->TabIndex = 35; this->button5->Text = L"基準保存"; this->button5->UseVisualStyleBackColor = true; this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click); // // label19 // this->label19->AutoSize = true; this->label19->Location = System::Drawing::Point(41, 3); this->label19->Name = L"label19"; this->label19->Size = System::Drawing::Size(41, 12); this->label19->TabIndex = 36; this->label19->Text = L"測定値"; // // label1 // this->label1->AutoSize = true; this->label1->Location = System::Drawing::Point(275, 3); this->label1->Name = L"label1"; this->label1->Size = System::Drawing::Size(20, 12); this->label1->TabIndex = 40; this->label1->Text = L"gal"; // // textBox20 // this->textBox20->Location = System::Drawing::Point(259, 68); this->textBox20->Name = L"textBox20"; this->textBox20->Size = System::Drawing::Size(52, 19); this->textBox20->TabIndex = 39; this->textBox20->TextAlign = System::Windows::Forms::HorizontalAlignment::Right; // // textBox21 // this->textBox21->Location = System::Drawing::Point(259, 43); this->textBox21->Name = L"textBox21"; this->textBox21->Size = System::Drawing::Size(52, 19); this->textBox21->TabIndex = 37; this->textBox21->TextAlign = System::Windows::Forms::HorizontalAlignment::Right; // // textBox22 // this->textBox22->Location = System::Drawing::Point(259, 18); this->textBox22->Name = L"textBox22"; this->textBox22->Size = System::Drawing::Size(52, 19); this->textBox22->TabIndex = 38; this->textBox22->TextAlign = System::Windows::Forms::HorizontalAlignment::Right; // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 12); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(1024, 399); this->Controls->Add(this->label1); this->Controls->Add(this->textBox20); this->Controls->Add(this->textBox21); this->Controls->Add(this->textBox22); this->Controls->Add(this->label19); this->Controls->Add(this->button5); this->Controls->Add(this->label18); this->Controls->Add(this->textBox17); this->Controls->Add(this->textBox18); this->Controls->Add(this->textBox19); this->Controls->Add(this->label13); this->Controls->Add(this->textBox10); this->Controls->Add(this->textBox12); this->Controls->Add(this->textBox14); this->Controls->Add(this->label8); this->Controls->Add(this->textBox2); this->Controls->Add(this->textBox3); this->Controls->Add(this->textBox8); this->Controls->Add(this->pictureBox2); this->Controls->Add(this->textBox16); this->Controls->Add(this->label7); this->Controls->Add(this->label6); this->Controls->Add(this->label5); this->Controls->Add(this->label4); this->Controls->Add(this->label3); this->Controls->Add(this->textBox15); this->Controls->Add(this->textBox11); this->Controls->Add(this->textBox7); this->Controls->Add(this->textBox13); this->Controls->Add(this->textBox9); this->Controls->Add(this->textBox4); this->Controls->Add(this->button4); this->Controls->Add(this->pictureBox1); this->Controls->Add(this->button3); this->Controls->Add(this->listBox1); this->Controls->Add(this->button2); this->Controls->Add(this->textBox6); this->Controls->Add(this->textBox5); this->Controls->Add(this->textBox1); this->Controls->Add(this->comboBox1); this->Controls->Add(this->button1); this->Icon = (cli::safe_cast(resources->GetObject(L"$this.Icon"))); this->Name = L"Form1"; this->Text = L"Form1"; this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); this->FormClosed += gcnew System::Windows::Forms::FormClosedEventHandler(this, &Form1::Form1_FormClosed); (cli::safe_cast(this->pictureBox1))->EndInit(); (cli::safe_cast(this->pictureBox2))->EndInit(); this->ResumeLayout(false); this->PerformLayout(); } private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { //接続 if(serialPort1->IsOpen==true){return;} if(listBox1->SelectedIndex==-1){return;} String^ cs=listBox1->SelectedItem->ToString(); serialPort1->PortName = cs; this->countrec=0; this->lastx=50; this->lasty=150; this->lastz=250; cleartmp(); serialPort1->Open(); serialPort1->DtrEnable = true; //DTR(Data Terminal Ready) データ端末レディ serialPort1->RtsEnable = true; //RTS(Request To Send) 送信要求 serialPort1->ReadTimeout = 500; //500mse 読み込みタイムアウト時間 serialPort1->WriteTimeout = 500; //500msec書き込みタイムアウト時間 #if !defined(NO_USB_SEND) serialPort1->Write("c080001\r"); serialPort1->Write("c100080\r"); #endif } private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) { //停止 if(serialPort1->IsOpen==false){return;} this->runflag=0; #if !defined(NO_USB_SEND) serialPort1->Write("+\r"); #endif this->countrec=0; this->lastx=50; this->lasty=150; this->lastz=250; timertmpx->Clear(); timertmpy->Clear(); timertmpz->Clear(); timer1->Enabled = false; } private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {//画像保存 DateTime dtToday = DateTime::Now::get(); pictureBox1->Image->Save(dtToday.ToString("yyMMdd-HHmmss")+".png"); } private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {//基準保存 if(xcnt!=0 && xcnt!=0 && xcnt!=0) { xref=xraw/xcnt; yref=yraw/ycnt; zref=zraw/zcnt; textBox19->Text=xref.ToString("F0"); textBox18->Text=yref.ToString("F0"); textBox17->Text=zref.ToString("F0"); String^ fileName = "vc232.conf"; StreamWriter^ sw = gcnew StreamWriter(fileName); sw->WriteLine(xref.ToString("F0")+","+yref.ToString("F0")+","+zref.ToString("F0")); sw->Close(); } } private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) { //タイマー割り込み if(timerproc){return;} timerproc=true; int nx=timertmpx->Count; int ny=timertmpy->Count; int nz=timertmpz->Count; int nmin=min(nx,min(ny,nz)); if(nmin<1 || nmin<10){timerproc=false;return;} List^ localtmpx=gcnew List(); List^ localtmpy=gcnew List(); List^ localtmpz=gcnew List(); for(int i = 0; i < nx; i++){localtmpx->Add(timertmpx[i]);} timertmpx->Clear(); for(int i = 0; i < ny; i++){localtmpy->Add(timertmpy[i]);} timertmpy->Clear(); for(int i = 0; i < nz; i++){localtmpz->Add(timertmpz[i]);} timertmpz->Clear(); String^ tmp=""; double ave,f,y,real,imag,filter,a,kshindo; double hz_i=1000.0/TIMER_INTERVAL; String^ shindo=""; FftBox box(nmin); ///////X軸 ave=0; for(int i = nx-nmin; i < nx; i++){ ave+=localtmpx[i]; } ave=ave/nx; for(int i = nx-nmin; i < nx; i++){box[i]=Complex(localtmpx[i]-ave, 0);} box.fft(); for(int i = nx-nmin,j=0; i < nx; i++,j++){ if(nmin/2^ synthe = gcnew array(nmin); for(int x=nx-nmin,y=ny-nmin,z=nz-nmin,j=0; j < nmin; x++,y++,z++,j++){ synthe[j]=fabs(sqrt(pow(box[x].real(),2)+pow(boy[y].real(),2)+pow(boz[z].real(),2))); } Array::Sort(synthe); Array::Reverse(synthe); a=synthe[300*nmin/TIMER_INTERVAL]; kshindo=Math::Floor(Math::Round(2*log10(a)+0.94,2)*10)/10; if(max_kshindo=0.5 && 1.5>kshindo){shindo="1";} if(kshindo>=1.5 && 2.5>kshindo){shindo="2";} if(kshindo>=2.5 && 3.5>kshindo){shindo="3";} if(kshindo>=3.5 && 4.5>kshindo){shindo="4";} if(kshindo>=4.5 && 5.0>kshindo){shindo=L"5弱";} if(kshindo>=5.0 && 5.5>kshindo){shindo=L"5強";} if(kshindo>=5.5 && 6.0>kshindo){shindo=L"6弱";} if(kshindo>=6.0 && 6.5>kshindo){shindo=L"6強";} if(kshindo>=6.5){shindo="7";} tmp+=L"震度階級="+shindo+"\r\n"; tmp+=L"最大計測震度="+max_kshindo.ToString("F1")+"\r\n"; if(kshindo>0){ addline(3,0,0,(int)(kshindo*10),0); } textBox16->Text=tmp; timerproc=false; } private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { } }; }