1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

1. はじめに

ControlDeskの計測からCSVのエクスポートまでの一連の流れをPythonでやってしまいましょう.

2. 記述

今回はPushボタンを押したらそこから10秒分のデータをRecordingしてCSVにエクスポートするプログラムを説明します.

# -- coding: utf-8 --
# 日本語対応
import serial
import time
import sys
import datetime
from win32com.client import Dispatch, DispatchWithEvents
from dspace.com.threads import STAThread

# プラットフォームオブジェクト
MyPlatform = Application.ActiveExperiment.Platforms["Platform"]
# Experiment実行ファイル(.DSE)のパス
dspaceDir = Application.ActiveExperiment.DirectoryName

# Pushボタンのイベント駆動プログラム
def On_Application_LayoutManagement_LoadCell_Push0020Button_150_210_ButtonClicked(Sender, Button):
    """
    Syntax : On_Application_LayoutManagement_LoadCell_Push0020Button_150_210_ButtonClicked
    Purpose: 
    Parameters: Sender, Button
    """

    # Create file name.
    date = datetime.datetime.now()
    dateStr = str(date.year) + '{0:02d}'.format(date.month) + '{0:02d}'.format(date.day)
    timeStr = '{0:02d}'.format(date.hour) + '{0:02d}'.format(date.minute) +'{0:02d}'.format(date.second)
    # ex) 20211116-120350_test_030[A].idf
    fileBaseName = dateStr + "-" + timeStr + "_" + "test" + "_" + '{0:01f}'.format(current) + "[A]"
    fileName = fileBaseName + ".idf"
    print "fileName: ", fileName
    csvPath = dspaceDir + "\\Measurement Data" + "\\" + fileBaseName + ".csv"
    print("csvPath: ", csvPath)

    recThread = STAThread(RecordingThread, "RecordingThread", (fileName, csvPath, Application,))
    recThread.start()

# レコーディング用のスレッド関数
def RecordingThread(fileName, csvPath, LocalApplication):
    # Recording Settings.
    # Get recorder object.
    # 自作のRecoderを選択する場合はMainRecoder->Recorders["レコーダ名"]に置き換える
    MainRecorder = LocalApplication.MeasurementDataManagement.MainRecorder

    # Set to automatic file naming.
    MainRecorder.AutomaticNamingEnabled = False

    # Add measurement to experiment.
    MainRecorder.AddToExperimentEnabled = True

    # Set number to start automatic naming.
    #MainRecorder.AutomaticNamingStartIndex = 10
    
    # Set number of digits for automatic naming.
    #MainRecorder.AutomaticNamingMinimumDigits = 3

    # Add record to measurement data pool.
    MainRecorder.OpenInMeasurementDataPoolEnabled = True

    # Get f_Ki_1 signal.
    #FKiSignal = LocalApplication.MeasurementDataManagement.MeasurementConfiguration.Signals.Item(
    #    FKiVariableConnectionString % (self.DemoPlatform.Name, OnChangeRasterName))
    #EncoderLIn1Signal = LocalApplication.MeasurementDataManagement.MeasurementConfiguration.Signals.Item(3)

    print("Recorder state: ", LocalApplication.MeasurementDataManagement.MainRecorder.State)

    # Remove signal f_Ki_1 from main recorder.
    #MainRecorder.Signals.Remove(EncoderLIn1Signal)
    
    # Base File Name of Recorder.
    MainRecorder.BaseFileName = fileName
    
    time.sleep(0.5)
    # Immediate Recording.
    MainRecorder.Start()
    time.sleep(10)
        
    print("Recorder state: ", LocalApplication.MeasurementDataManagement.MainRecorder.State)

    # Stop Recording.
    LocalApplication.MeasurementDataManagement.Stop()

    # Get Measurement object.
    Measurement = LocalApplication.MeasurementDataManagement.Measurements.Item(fileName)
    # Export.
    Measurement.Export(csvPath, True)
    print ("Main recording is finished.")
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?