주요 콘텐츠

이 페이지는 기계 번역을 사용하여 번역되었습니다. 영어 원문을 보려면 여기를 클릭하십시오.

OPC Historical Data Access 서버로부터 데이터 수집

이 예제는 OPC HDA(Historical Data Access) 서버에서 데이터를 가져오는 방법을 보여줍니다.

선행 조건:

OPC HDA Client 객체 만들기

참고: 프로덕션 서버를 사용하거나 과거 데이터가 있는 HDA 서버를 사용하십시오.

opchda 함수를 사용하여 OPC HDA 서버와 연결된 OPC HDA 클라이언트를 생성합니다.

hdaObj = opchda('localhost','matrikon.OPC.Simulation')
hdaObj = 

OPC HDA Client localhost/matrikon.OPC.Simulation:
               Host: localhost
           ServerID: matrikon.OPC.Simulation
            Timeout: 10 seconds

             Status: disconnected

         Aggregates: -- (client is disconnected)
     ItemAttributes: -- (client is disconnected)

client 객체는 서버와의 연결을 관리하며, 사용자가 서버에 대한 정보를 검색하고 서버 네임스페이스를 탐색하고 서버에 저장된 데이터를 읽을 수 있도록 합니다.

이 시점에서 클라이언트는 아직 서버에 연결되지 않았습니다. 클라이언트를 서버에 연결합니다.

connect(hdaObj);

클라이언트가 연결되었는지 확인하기 위해 클라이언트의 Status 속성을 표시합니다.

hdaObj.Status
ans =

    'connected'

관심 항목 정의

이 예제에서는 Saw-toothed WavesReal8 항목과 RandomReal8UInt2 항목을 사용합니다. 사용 편의성을 위해 항목 이름을 셀형 배열로 만듭니다.

itmIDs = {'Saw-toothed Waves.Real8', ...
    'Random.Real8', ...
    'Random.UInt2'};

서버에서 원시 데이터 읽기

readRaw 함수를 사용하여 지난 하루 동안의 기록 서버에서 원시 데이터 값을 읽습니다.

data = readRaw(hdaObj,itmIDs,now-1,now)
data = 

1-by-3 OPC HDA Data object:

            ItemID                Value          Start TimeStamp       End TimeStamp            Quality        
    -----------------------  ----------------  -------------------  -------------------  ----------------------
    Saw-toothed Waves.Real8  20 double values  2024-04-29 08:59:49  2024-04-29 09:01:10  1 unique quality [Raw]
    Random.Real8             20 double values  2024-04-29 08:59:49  2024-04-29 09:01:10  1 unique quality [Raw]
    Random.UInt2             20 uint16 values  2024-04-29 08:59:49  2024-04-29 09:01:10  1 unique quality [Raw]

Use the showValues method to display all values.

참고: Matrikon 서버는 각 항목에 대해 최근 200개의 시뮬레이션 값만 보관합니다.

opc.setDateDisplayFormat을 사용하여 첫 번째 데이터 요소의 값을 사용자 지정 날짜 표시 형식으로 표시합니다. readProcessed 함수를 사용하여 서버에서 집계된 데이터를 읽으십시오.

opc.setDateDisplayFormat('yyyy-mm-dd HH:MM:SS');
showValues(data(1))
OPC HDA Data object for item Saw-toothed Waves.Real8:

         TIMESTAMP           VALUE       QUALITY
    ===================  =============  ==========
    2024-04-29 08:59:49       3.141593  Raw (Good)
    2024-04-29 08:59:50       6.283185  Raw (Good)
    2024-04-29 08:59:51       9.424778  Raw (Good)
    2024-04-29 08:59:52      12.566371  Raw (Good)
    2024-04-29 08:59:53      15.707963  Raw (Good)
    2024-04-29 08:59:54      18.849556  Raw (Good)
    2024-04-29 08:59:55      21.991149  Raw (Good)
    2024-04-29 08:59:56      25.132741  Raw (Good)
    2024-04-29 08:59:57      28.274334  Raw (Good)
    2024-04-29 08:59:58      31.415927  Raw (Good)
    2024-04-29 08:59:59      34.557520  Raw (Good)
    2024-04-29 09:01:02      37.699112  Raw (Good)
    2024-04-29 09:01:03      40.840705  Raw (Good)
    2024-04-29 09:01:04      43.982298  Raw (Good)
    2024-04-29 09:01:05      47.123890  Raw (Good)
    2024-04-29 09:01:06      50.265483  Raw (Good)
    2024-04-29 09:01:07      53.407076  Raw (Good)
    2024-04-29 09:01:08      56.548668  Raw (Good)
    2024-04-29 09:01:09      59.690261  Raw (Good)
    2024-04-29 09:01:10      62.831854  Raw (Good)

서버에서 처리된 데이터 읽기

HDA Client 객체의 Aggregates 속성을 쿼리하여 서버에서 지원하는 집계 유형을 확인합니다.

hdaObj.Aggregates
ans = 

OPC HDA Aggregate Types:
          Name         ID                                          Description                                        
    -----------------  --  -------------------------------------------------------------------------------------------
    INTERPOLATIVE      1   Retrieve interpolated values.
    TIMEAVERAGE        4   Retrieve the time weighted average data over the resample interval.
    MINIMUMACTUALTIME  7   Retrieve the minimum value in the resample interval and the timestamp of the minimum value.
    MINIMUM            8   Retrieve the minimum value in the resample interval.
    MAXIMUMACTUALTIME  9   Retrieve the maximum value in the resample interval and the timestamp of the maximum value.
    MAXIMUM            10  Retrieve the maximum value in the resample interval.

Matrikon 서버는 시간 가중 평균값을 지원하므로, 여기서는 지난 1분 동안의 10초 단위 데이터에 대해 해당 집계 유형을 사용하겠습니다. 아래에서 Aggregates 속성을 사용하여 집계 유형을 지정하는 방법을 확인하십시오.

pData = readProcessed(hdaObj,itmIDs,hdaObj.Aggregates.TIMEAVERAGE,10,now-1/24/60,now)'
pData = 

1-by-3 OPC HDA Data object:

            ItemID                Value         Start TimeStamp       End TimeStamp          Quality      
    -----------------------  ---------------  -------------------  -------------------  ------------------
    Saw-toothed Waves.Real8  6 double values  2024-04-29 09:00:11  2024-04-29 09:01:01  2 unique qualities
    Random.Real8             6 double values  2024-04-29 09:00:11  2024-04-29 09:01:01  2 unique qualities
    Random.UInt2             6 uint16 values  2024-04-29 09:00:11  2024-04-29 09:01:01  2 unique qualities

Use the showValues method to display all values.

Random.Real8 항목의 값을 표시합니다.

itmInd = getIndexFromID(pData,'Random.Real8');
opc.setDateDisplayFormat('yyyy-mm-dd HH:MM:SS');
showValues(pData(itmInd))
OPC HDA Data object for item Random.Real8:

         TIMESTAMP           VALUE             QUALITY
    ===================  =============  ======================
    2024-04-29 09:00:11    1898.988063  Calculated (Good)     
    2024-04-29 09:00:21    1898.988063  Calculated (Good)     
    2024-04-29 09:00:31    1898.988063  Calculated (Good)     
    2024-04-29 09:00:41    1898.988063  Calculated (Good)     
    2024-04-29 09:00:51    1898.988063  Calculated (Good)     
    2024-04-29 09:01:01    9079.370319  Calculated (Uncertain)

마지막 값은 시간 간격이 10초가 채 되지 않기 때문에 품질이 'Uncertain'입니다.

정리

데이터 수집이 완료되면 HDA client 객체의 연결을 끊고 삭제하십시오. HDA Client 객체를 삭제하면 서버에서 자동으로 해당 객체의 연결이 끊어지지만, 이 예제에서는 그 과정을 명시적으로 보여줍니다.

disconnect(hdaObj)
delete(hdaObj)