Hielscher Sonicator XML 데이터용 실시간 Excel 로거
작동 방식
스크립트가 실행되면 사용자에게 소닉레이터 xml 데이터의 XML 소스 주소(예: http://192.168.233.233/mdata.xml)를 입력하라는 메시지가 표시됩니다. 그런 다음 구조화된 헤더 행을 생성하고 매초마다 데이터 가져오기를 시작합니다. 각각의 새로운 데이터 포인트가 테이블에 추가되고 산점형 차트에 시간에 따른 전력, 진폭 및 에너지 추세가 표시됩니다. 센서 오류 값(예: 센서가 연결되지 않은 경우)은 자동으로 필터링됩니다.
Windows 사용자를 위한 지침
Excel에서 Visual Basic 편집기를 열고 새 모듈을 삽입한 다음 전체 스크립트를 붙여넣습니다. InitLogger 매크로를 실행하면 로거가 자동으로 시작됩니다. 매크로가 사용 설정되어 있고 Excel에 네트워크 액세스 권한이 있는지 확인합니다.
macOS 사용자를 위한 지침
Excel에서 Visual Basic 편집기를 엽니다. 새 모듈을 삽입하고 전체 스크립트를 붙여넣습니다. 동일한 매크로를 실행하기만 하면 제공된 IP를 사용하여 데이터를 가져옵니다. MacOS 사용자는 Excel에서 AppleScript를 실행하도록 허용해야 하며, 메시지가 표시되면 시스템 환경설정에서 네트워크 액세스 권한을 부여해야 할 수도 있습니다.
업데이트, 면책 조항 및 라이선스
디바이스 유형과 제공되는 소프트웨어 버전에 따라 XML 데이터 문자열이 다를 수 있습니다. 다른 수의 값과 다른 순서 또는 형식으로 포함될 수 있습니다. 따라서 그에 따라 아래 스크립트를 조정해야 할 수도 있습니다. 기술 지원, 버그 수정 또는 향후 업데이트에 대한 의무는 없습니다. 이 도구는 어떠한 종류의 보장이나 보증 없이 제공됩니다. 여기에는 상품성 또는 특정 목적에의 적합성과 같은 묵시적 보증이 명시적으로 제외됩니다. Hielscher 초음파는 소프트웨어 사용으로 인해 발생하는 직접적, 간접적 또는 결과적 손해를 포함한 어떠한 손해에 대해서도 책임을 지지 않습니다. 이는 예시일 뿐입니다. 비상업적 및 연구 목적으로만 무료로 사용할 수 있습니다. 적절한 출처를 명시한 재배포는 허용됩니다. 사전 서면 동의 없이 상업적으로 재판매하거나 독점 시스템에 포함시키는 것은 엄격히 금지됩니다.
Sonicator XML 데이터를 Excel 스프레드시트로 변환하기
' ==============================================================================
' Realtime Excel Logger for Hielscher Sonicator XML Data
'
' Description:
' This VBA module fetches XML data from a Hielscher sonicator over the network
' (typically from a local IP like http://192.168.233.233/mdata.xml), parses it,
' logs real-time data into Excel, and visualizes selected parameters (Power, Amplitude,
' and Energy) using a live updating scatter-line chart.
'
' Disclaimer & License:
' This script is provided "as is" without any warranty. It is free for non-commercial
' use, and redistribution is permitted only with attribution. Resale or inclusion in
' commercial software is strictly prohibited without explicit permission.
' (c) Hielscher Ultrasonics GmbH (Germany), 2025. All rights reserved. https://www.hielscher.com
' Last Update: June 17th, 2025, for sonicator software version 25.0.1
' ==============================================================================
' === Realtime Excel Logger Module ===
Dim nextRow As Long ' Row index for logging the next data point
Dim chartObject As chartObject ' Reference to the live chart object
Dim isRunning As Boolean ' Controls whether logging continues
' === MAIN ENTRY POINT ===
Sub InitLogger()
Dim ws As Worksheet
Set ws = Sheet1 ' Use the first worksheet
ws.Cells.Clear ' Clear all existing content on the sheet
' Request and store the XML source IP address
ws.Cells(1, 1).Value = "XML Source"
ws.Cells(1, 2).Value = InputBox("Enter device IP address", "XML Source", "http://192.168.233.233/mdata.xml")
' Create header row starting at row 2
ws.Cells(2, 1).Resize(1, 14).Value = Array( _
"Timestamp", "Status", "Total Power (W)", "Net Power (W)", "Amplitude (%)", _
"Energy (Ws)", "ADC", "Frequency (Hz)", "Temperature (°C)", "Time (s)", _
"ControlBits", "LimitType", "SetPower (%)", "Cycle (%)")
nextRow = 3 ' Start logging at row 3
isRunning = True ' Enable logging loop
Application.OnTime Now + TimeSerial(0, 0, 1), "LoggerTick" ' Schedule first data fetch
End Sub
' === PERIODIC TIMER CALLBACK ===
Sub LoggerTick()
If Not isRunning Then Exit Sub
FetchOnce
Application.OnTime Now + TimeSerial(0, 0, 1), "LoggerTick" ' Schedule next fetch
End Sub
' === FETCH AND LOG DATA ===
Sub FetchOnce()
Dim ipAddress As String, rawData As String
Dim dataFields() As String, mStart As Long, mEnd As Long
Dim ws As Worksheet: Set ws = Sheet1
ipAddress = Trim(ws.Cells(1, 2).Value) ' Get IP from input cell
If ipAddress = "" Then Exit Sub ' Exit if IP is missing
rawData = GetMDataXML(ipAddress) ' Fetch the raw XML from device
If rawData = "" Then Exit Sub ' Exit if fetch failed
' Extract only the content inside ...
mStart = InStr(rawData, "")
mEnd = InStr(rawData, " ")
If mStart = 0 Or mEnd = 0 Then Exit Sub ' Exit if tag not found
rawData = Mid(rawData, mStart + 7, mEnd - mStart - 7)
dataFields = Split(rawData, ";") ' Parse by semicolon delimiter
If UBound(dataFields) < 12 Then Exit Sub ' Ensure all fields are present
' Determine next available row
nextRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row + 1
' Write parsed values into worksheet
With ws
.Cells(nextRow, 1).Value = Format(Now, "yyyy-mm-dd HH:nn:ss") ' Timestamp (rounded to seconds)
.Cells(nextRow, 2).Value = Val(dataFields(0)) ' Status
.Cells(nextRow, 3).Value = Val(dataFields(1)) / 10 ' Total Power (W)
.Cells(nextRow, 4).Value = Val(dataFields(2)) / 10 ' Net Power (W)
.Cells(nextRow, 5).Value = Val(dataFields(3)) / 10 ' Amplitude (%)
.Cells(nextRow, 6).Value = Val(dataFields(4)) ' Energy (Ws)
.Cells(nextRow, 7).Value = Val(dataFields(5)) / 10 ' ADC
.Cells(nextRow, 8).Value = Val(dataFields(6)) ' Frequency (Hz)
.Cells(nextRow, 9).Value = IIf(Val(dataFields(7)) = 2550, "", Val(dataFields(7)) / 10) ' Temperature (°C), blank if 255
.Cells(nextRow, 10).Value = Val(dataFields(8)) / 10 ' Time (s)
.Cells(nextRow, 11).Value = Val(dataFields(9)) ' ControlBits
.Cells(nextRow, 12).Value = IIf(Val(dataFields(10)) = 0, "", Val(dataFields(10))) ' LimitType, blank if 0
.Cells(nextRow, 13).Value = Val(dataFields(11)) / 20 ' SetPower (%)
.Cells(nextRow, 14).Value = Val(dataFields(12)) / 10 ' Cycle (%).Value = Val(dataFields(12)) / 10 ' Cycle (%)
End With
UpdateChart
End Sub
' === CREATE / UPDATE SCATTER-LINE CHART ===
Sub UpdateChart()
Dim ws As Worksheet: Set ws = Sheet1
Dim lastRow As Long: lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
If lastRow < 4 Then Exit Sub
' Format timestamp column to display yyyy-mm-dd HH:mm:ss
ws.Columns(1).NumberFormat = "yyyy-mm-dd hh:mm:ss"
' Create chart if not already initialized
If chartObject Is Nothing Then
Set chartObject = ws.ChartObjects.Add(Left:=ws.Cells(2, 16).Left, Top:=ws.Cells(2, 16).Top, Width:=500, Height:=300)
chartObject.Name = "LiveChart"
End If
' Configure the scatter line chart with latest data
With chartObject.Chart
.ChartType = xlXYScatterLines
Do While .SeriesCollection.Count > 0: .SeriesCollection(1).Delete: Loop
' Plot Total Power
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = "Power (W)"
.SeriesCollection(1).XValues = ws.Range("A3:A" & lastRow)
.SeriesCollection(1).Values = ws.Range("C3:C" & lastRow)
' Plot Amplitude
.SeriesCollection.NewSeries
.SeriesCollection(2).Name = "Amplitude (%)"
.SeriesCollection(2).XValues = ws.Range("A3:A" & lastRow)
.SeriesCollection(2).Values = ws.Range("E3:E" & lastRow)
' Plot Energy
.SeriesCollection.NewSeries
.SeriesCollection(3).Name = "Energy (Ws)"
.SeriesCollection(3).XValues = ws.Range("A3:A" & lastRow)
.SeriesCollection(3).Values = ws.Range("F3:F" & lastRow)
.HasTitle = True
.ChartTitle.Text = "Hielscher Sonicator: Live Chart"
.Axes(xlCategory).HasTitle = True
.Axes(xlCategory).AxisTitle.Text = "Time"
.Axes(xlValue).HasTitle = True
.Axes(xlValue).AxisTitle.Text = "Value"
' Format the X-axis to show MM:SS
.Axes(xlCategory).TickLabels.NumberFormat = "mm:ss"
End With
End Sub
' === FETCH XML VIA PLATFORM-SPECIFIC METHOD ===
Function GetMDataXML(ip As String) As String
Dim os As String: os = Application.OperatingSystem
' macOS: use AppleScript shell call to curl
If InStr(1, os, "Mac", vbTextCompare) > 0 Then
Dim script As String
script = "do shell script " & Chr(34) & "curl -s " & ip & Chr(34)
On Error Resume Next
GetMDataXML = MacScript(script)
If Err.Number <> 0 Then GetMDataXML = ""
' Windows: use MSXML2.XMLHTTP request
Else
Dim http As Object
Set http = CreateObject("MSXML2.XMLHTTP")
On Error Resume Next
http.Open "GET", ip, False
http.Send
If Err.Number = 0 And http.Status = 200 Then
GetMDataXML = http.responseText
Else
GetMDataXML = ""
End If
End If
End Function
