diff options
author | Martin Burnicki <martin.burnicki@meinberg.de> | 2014-08-15 12:00:00 +0200 |
---|---|---|
committer | Martin Burnicki <martin.burnicki@meinberg.de> | 2014-08-14 12:00:00 +0200 |
commit | 59e61043c1771cd3596861f7116e7a3fe5ed370d (patch) | |
tree | 3697f9e8ffaf15049301cd57978a859b5b476479 | |
parent | ac08e59d3c927bd0ae95f926df08295c7e9b2269 (diff) | |
download | mbgsdk-win-59e61043c1771cd3596861f7116e7a3fe5ed370d.tar.gz mbgsdk-win-59e61043c1771cd3596861f7116e7a3fe5ed370d.zip |
Update example code for VB.NETmbgsdk-vb.net-2014-08-14
Read and display device info.
Read raw IRIG data, if supported, and display time decoded from this data.
Read and display IRIG time, if supported.
-rw-r--r-- | vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.designer.vb | 113 | ||||
-rw-r--r-- | vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.resx | 123 | ||||
-rw-r--r-- | vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.vb | 225 | ||||
-rw-r--r-- | vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.vbproj | 6 | ||||
-rw-r--r-- | vb.net/mbglib/mbgdefs-vb.net.vb | 20 | ||||
-rw-r--r-- | vb.net/mbglib/mbgdevio-vb.net.vb | 383 |
6 files changed, 675 insertions, 195 deletions
diff --git a/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.designer.vb b/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.designer.vb index 115e036..845fc0c 100644 --- a/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.designer.vb +++ b/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.designer.vb @@ -23,69 +23,54 @@ 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() - Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(mbgdevio_demo_vb_net)) - Me.components = New System.ComponentModel.Container() - Me.ToolTip1 = New System.Windows.Forms.ToolTip(components) - Me.UpdateCommandButton = New System.Windows.Forms.Button - Me.InfoTextBox = New System.Windows.Forms.TextBox - Me.SuspendLayout() - Me.ToolTip1.Active = True - Me.Text = "Check Radio Clock Sync Status" - Me.ClientSize = New System.Drawing.Size(433, 308) - Me.Location = New System.Drawing.Point(4, 23) - Me.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultLocation - Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.BackColor = System.Drawing.SystemColors.Control - Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable - Me.ControlBox = True - Me.Enabled = True - Me.KeyPreview = False - Me.MaximizeBox = True - Me.MinimizeBox = True - Me.Cursor = System.Windows.Forms.Cursors.Default - Me.RightToLeft = System.Windows.Forms.RightToLeft.No - Me.ShowInTaskbar = True - Me.HelpButton = False - Me.WindowState = System.Windows.Forms.FormWindowState.Normal - Me.Name = "mbgdevio_demo_vb6" - Me.UpdateCommandButton.TextAlign = System.Drawing.ContentAlignment.MiddleCenter - Me.UpdateCommandButton.Text = "Update" - Me.UpdateCommandButton.Size = New System.Drawing.Size(129, 33) - Me.UpdateCommandButton.Location = New System.Drawing.Point(152, 264) - Me.UpdateCommandButton.TabIndex = 1 - Me.UpdateCommandButton.BackColor = System.Drawing.SystemColors.Control - Me.UpdateCommandButton.CausesValidation = True - Me.UpdateCommandButton.Enabled = True - Me.UpdateCommandButton.ForeColor = System.Drawing.SystemColors.ControlText - Me.UpdateCommandButton.Cursor = System.Windows.Forms.Cursors.Default - Me.UpdateCommandButton.RightToLeft = System.Windows.Forms.RightToLeft.No - Me.UpdateCommandButton.TabStop = True - Me.UpdateCommandButton.Name = "UpdateCommandButton" - Me.InfoTextBox.AutoSize = False - Me.InfoTextBox.Size = New System.Drawing.Size(401, 233) - Me.InfoTextBox.Location = New System.Drawing.Point(16, 16) - Me.InfoTextBox.MultiLine = True - Me.InfoTextBox.TabIndex = 0 - Me.InfoTextBox.AcceptsReturn = True - Me.InfoTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Left - Me.InfoTextBox.BackColor = System.Drawing.SystemColors.Window - Me.InfoTextBox.CausesValidation = True - Me.InfoTextBox.Enabled = True - Me.InfoTextBox.ForeColor = System.Drawing.SystemColors.WindowText - Me.InfoTextBox.HideSelection = True - Me.InfoTextBox.ReadOnly = False - Me.InfoTextBox.Maxlength = 0 - Me.InfoTextBox.Cursor = System.Windows.Forms.Cursors.IBeam - Me.InfoTextBox.RightToLeft = System.Windows.Forms.RightToLeft.No - Me.InfoTextBox.ScrollBars = System.Windows.Forms.ScrollBars.None - Me.InfoTextBox.TabStop = True - Me.InfoTextBox.Visible = True - Me.InfoTextBox.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D - Me.InfoTextBox.Name = "InfoTextBox" - Me.Controls.Add(UpdateCommandButton) - Me.Controls.Add(InfoTextBox) - Me.ResumeLayout(False) - Me.PerformLayout() - End Sub +Me.components = New System.ComponentModel.Container +Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components) +Me.UpdateCommandButton = New System.Windows.Forms.Button +Me.InfoTextBox = New System.Windows.Forms.TextBox +Me.SuspendLayout() +' +'UpdateCommandButton +' +Me.UpdateCommandButton.BackColor = System.Drawing.SystemColors.Control +Me.UpdateCommandButton.Cursor = System.Windows.Forms.Cursors.Default +Me.UpdateCommandButton.ForeColor = System.Drawing.SystemColors.ControlText +Me.UpdateCommandButton.Location = New System.Drawing.Point(147, 356) +Me.UpdateCommandButton.Name = "UpdateCommandButton" +Me.UpdateCommandButton.RightToLeft = System.Windows.Forms.RightToLeft.No +Me.UpdateCommandButton.Size = New System.Drawing.Size(129, 33) +Me.UpdateCommandButton.TabIndex = 1 +Me.UpdateCommandButton.Text = "Update" +Me.UpdateCommandButton.UseVisualStyleBackColor = False +' +'InfoTextBox +' +Me.InfoTextBox.AcceptsReturn = True +Me.InfoTextBox.BackColor = System.Drawing.SystemColors.Window +Me.InfoTextBox.Cursor = System.Windows.Forms.Cursors.IBeam +Me.InfoTextBox.ForeColor = System.Drawing.SystemColors.WindowText +Me.InfoTextBox.Location = New System.Drawing.Point(16, 16) +Me.InfoTextBox.MaxLength = 0 +Me.InfoTextBox.Multiline = True +Me.InfoTextBox.Name = "InfoTextBox" +Me.InfoTextBox.RightToLeft = System.Windows.Forms.RightToLeft.No +Me.InfoTextBox.Size = New System.Drawing.Size(401, 325) +Me.InfoTextBox.TabIndex = 0 +' +'mbgdevio_demo_vb_net +' +Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) +Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font +Me.BackColor = System.Drawing.SystemColors.Control +Me.ClientSize = New System.Drawing.Size(433, 401) +Me.Controls.Add(Me.UpdateCommandButton) +Me.Controls.Add(Me.InfoTextBox) +Me.Cursor = System.Windows.Forms.Cursors.Default +Me.Location = New System.Drawing.Point(4, 23) +Me.Name = "mbgdevio_demo_vb_net" +Me.RightToLeft = System.Windows.Forms.RightToLeft.No +Me.Text = "Check Radio Clock Sync Status" +Me.ResumeLayout(False) + +End Sub #End Region End Class
\ No newline at end of file diff --git a/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.resx b/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.resx new file mode 100644 index 0000000..13795a7 --- /dev/null +++ b/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.resx @@ -0,0 +1,123 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <metadata name="ToolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>17, 17</value> + </metadata> +</root>
\ No newline at end of file diff --git a/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.vb b/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.vb index 59acd29..edc3d3b 100644 --- a/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.vb +++ b/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.vb @@ -5,7 +5,7 @@ Friend Class mbgdevio_demo_vb_net '************************************************************************** ' - ' $Id: mbgdevio-demo-vb.net.vb 1.1 2008/05/23 11:04:54Z martin REL_M $ + ' $Id: mbgdevio-demo-vb.net.vb 1.2 2014/08/14 08:59:34Z martin REL_M $ ' ' Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany ' @@ -33,6 +33,12 @@ Friend Class mbgdevio_demo_vb_net ' ' ----------------------------------------------------------------------- ' $Log: mbgdevio-demo-vb.net.vb $ + ' Revision 1.2 2014/08/14 08:59:34Z martin + ' Read and display device info. + ' Read raw IRIG data, if supported, and + ' display time decoded from this data. + ' Read and display IRIG time, if supported. + ' Code cleanup. ' Revision 1.1 2008/05/23 11:04:54Z martin ' Initial revision for VB.NET 2005, based on v1.4 for VB6. ' @@ -86,15 +92,14 @@ Friend Class mbgdevio_demo_vb_net c = "+" End If - PcpsTimeToString = VB6.Format(LongYear, "000#") & "-" _ - & VB6.Format(t.month, "0#") & "-" _ - & VB6.Format(t.mday, "0#") & " " _ - & VB6.Format(t.hour, "0#") & ":" _ - & VB6.Format(t.min, "0#") & ":" _ - & VB6.Format(t.sec, "0#") & "." _ - & VB6.Format(t.sec100, "0#") _ - & " UTC" & c _ - & VB6.Format(offs_utc) & "h" + PcpsTimeToString = LongYear.ToString("D4") + "-" _ + + t.month.ToString("D2") + "-" _ + + t.mday.ToString("D2") + " " _ + + t.hour.ToString("D2") + ":" _ + + t.min.ToString("D2") + ":" _ + + t.sec.ToString("D2") + "." _ + + t.sec100.ToString("D2") + " UTC" _ + + c + offs_utc.ToString("D2") + "h" End Function @@ -104,8 +109,8 @@ Friend Class mbgdevio_demo_vb_net Private Function PcpsTimeStampToHexString(ByRef t As PCPS_TIME_STAMP) As String - PcpsTimeStampToHexString = VB6.Format(Hex(t.sec), "00000000") & "." _ - & VB6.Format(Hex(t.frac), "00000000") + PcpsTimeStampToHexString = t.sec.ToString("X8") + "." + t.frac.ToString("X8") + End Function @@ -120,6 +125,7 @@ Friend Class mbgdevio_demo_vb_net Const frac_scale As Double = 4294967296.0# ' &H100000000 Dim dt As Date Dim frac As Double + Dim lfrac As Long ' Convert seconds since 1970 to the VB date format dt = System.Date.FromOADate(CDbl(t.sec) / DaysPerYear + EpocheOffs1970) @@ -140,11 +146,11 @@ Friend Class mbgdevio_demo_vb_net ' Re-scale the fractions depending on the number of decimal ' digits we want to print, e.g. if we want to print 7 digits ' (100 nanosecond units) then we must multiply by 1E7 - ' and specify the format string accordingly. - frac = frac * 10000000.0# + ' and specify the output format accordingly. + lfrac = frac * 10000000.0# - PcpsTimeStampToString = VB6.Format(dt, "yyyy-mm-dd hh:MM:ss") & "." _ - & VB6.Format(frac, "0000000") + PcpsTimeStampToString = dt.ToString("yyyy-MM-dd HH:mm:ss") _ + + "." + lfrac.ToString("D7") End Function @@ -154,7 +160,7 @@ Friend Class mbgdevio_demo_vb_net Private Function PcpsHrTimeToUtcTimeString(ByRef ht As PCPS_HR_TIME) As String - PcpsHrTimeToUtcTimeString = PcpsTimeStampToString(ht.tstamp) & " UTC" + PcpsHrTimeToUtcTimeString = PcpsTimeStampToString(ht.tstamp) + " UTC" End Function @@ -168,7 +174,7 @@ Friend Class mbgdevio_demo_vb_net Dim tmp_ht As PCPS_HR_TIME Dim hours As Short - Dim Mins As Short + Dim mins As Short Dim c As String ' Add the UTC offset to the seconds field in order to yield local time @@ -185,12 +191,13 @@ Friend Class mbgdevio_demo_vb_net End If ' Convert the UTC offset which is in seconds to hours and minutes - Mins = tmp_ht.utc_offs / 60 ' now we have total minutes - hours = Mins / 60 ' determine the number of hours - Mins = Mins - hours * 60 ' determine remaining minutes - - PcpsHrTimeToLocalTimeString = PcpsTimeStampToString(tmp_ht.tstamp) & " UTC" & c & VB6.Format(hours, "0#") & ":" & VB6.Format(Mins, "0#") & "h" + mins = tmp_ht.utc_offs / 60 ' now we have total minutes + hours = mins / 60 ' determine the number of hours + mins = mins - hours * 60 ' determine remaining minutes + PcpsHrTimeToLocalTimeString = PcpsTimeStampToString(tmp_ht.tstamp) + " UTC" _ + + c + hours.ToString("D2") + ":" _ + + mins.ToString("D2") + "h" End Function @@ -204,7 +211,9 @@ Friend Class mbgdevio_demo_vb_net r2d = 180 / 3.1415 - MbgPosLlaStr = "Lat: " & VB6.Format(lla.lat * r2d, "0.0000") & " deg, " & "Lon: " & VB6.Format(lla.lon * r2d, "0.0000") & " deg, " & "Alt: " & VB6.Format(lla.alt, "0") & " m" + MbgPosLlaStr = "Lat: " + VB6.Format(lla.lat * r2d, "0.0000") + " deg, " _ + + "Lon: " + VB6.Format(lla.lon * r2d, "0.0000") + " deg, " _ + + "Alt: " + VB6.Format(lla.alt, "0") + " m" End Function @@ -215,10 +224,10 @@ Friend Class mbgdevio_demo_vb_net Private Function MbgPosDms(ByRef dms As MBG_DMS) As String - MbgPosDms = Chr(dms.prefix) & " " _ - & VB6.Format(dms.deg, "0") & ":" _ - & VB6.Format(dms.min, "00") & ":" _ - & VB6.Format(dms.sec, "00.00") + MbgPosDms = Chr(dms.prefix) + " " _ + + VB6.Format(dms.deg, "0") + ":" _ + + VB6.Format(dms.min, "00") + ":" _ + + VB6.Format(dms.sec, "00.00") End Function @@ -229,9 +238,9 @@ Friend Class mbgdevio_demo_vb_net Private Function MbgRcvrPosStr(ByRef pos As MBG_RCVR_POS) As String - MbgRcvrPosStr = MbgPosDms(pos.latitude) & ", " _ - & MbgPosDms(pos.longitude) & ", " _ - & VB6.Format(pos.lla.alt, "0") & " m" + MbgRcvrPosStr = MbgPosDms(pos.latitude) + ", " _ + + MbgPosDms(pos.longitude) + ", " _ + + VB6.Format(pos.lla.alt, "0") + " m" End Function @@ -248,6 +257,7 @@ Friend Class mbgdevio_demo_vb_net Dim h As Integer ' device handle Dim rc As Integer ' return code from API functions Dim currTime As PCPS_TIME + Dim device_info As PCPS_DEV Dim f As Integer ' flag ' Find out how many devices are installed @@ -268,12 +278,24 @@ Friend Class mbgdevio_demo_vb_net Exit Sub End If + ' Read device info + rc = mbg_get_device_info(h, device_info) + + If rc <> 0 Then + Me.InfoTextBox.Text = "** Failed to read device info from device." + GoTo done + End If + + Me.InfoTextBox.Text = "Device: " + device_info.cfg.fw_id _ + + ", S/N: " + device_info.cfg.sernum _ + + Chr(13) + Chr(10) + Chr(13) + Chr(10) + ' Read the current time and status rc = mbg_get_time(h, currTime) If rc <> 0 Then - Me.InfoTextBox.Text = "Error accessing the device." + Me.InfoTextBox.Text = "** Failed to read time from device." GoTo done End If @@ -283,13 +305,13 @@ Friend Class mbgdevio_demo_vb_net LongYear = currTime.year + 1900 End If - Me.InfoTextBox.Text = "Current local time" _ - & " (" & MbgSyncStatusStr(CShort(currTime.status)) & "):" _ - & Chr(13) & Chr(10) + Me.InfoTextBox.Text = Me.InfoTextBox.Text + "Current local time" _ + + " (" + MbgSyncStatusStr(CShort(currTime.status)) + "):" _ + + Chr(13) + Chr(10) Me.InfoTextBox.Text = Me.InfoTextBox.Text _ - & PcpsTimeToString(currTime) _ - & Chr(13) & Chr(10) + + PcpsTimeToString(currTime) _ + + Chr(13) + Chr(10) ' If the device supports HR time, also read the HR time @@ -304,18 +326,22 @@ Friend Class mbgdevio_demo_vb_net rc = mbg_get_hr_time(h, ht) If rc = PCPS_SUCCESS Then - Me.InfoTextBox.Text = Me.InfoTextBox.Text & Chr(13) & Chr(10) & "HR time " & " (" & MbgSyncStatusStr(ht.status) & "):" & Chr(13) & Chr(10) & PcpsHrTimeToUtcTimeString(ht) & Chr(13) & Chr(10) & PcpsHrTimeToLocalTimeString(ht) & Chr(13) & Chr(10) & "Raw: " & PcpsTimeStampToHexString(ht.tstamp) + Me.InfoTextBox.Text = Me.InfoTextBox.Text + Chr(13) + Chr(10) _ + + "HR time (" + MbgSyncStatusStr(ht.status) + "):" + Chr(13) + Chr(10) _ + + PcpsHrTimeToUtcTimeString(ht) + Chr(13) + Chr(10) _ + + PcpsHrTimeToLocalTimeString(ht) + Chr(13) + Chr(10) _ + + "Raw: " + PcpsTimeStampToHexString(ht.tstamp) Else - Me.InfoTextBox.Text = Me.InfoTextBox.Text & "Error reading HR time." + Me.InfoTextBox.Text = Me.InfoTextBox.Text + "Error reading HR time." End If Else - Me.InfoTextBox.Text = Me.InfoTextBox.Text & "Device does not support HR time." + Me.InfoTextBox.Text = Me.InfoTextBox.Text + "Device does not support HR time." End If Else - Me.InfoTextBox.Text = Me.InfoTextBox.Text & "Error checking if device supports HR time." + Me.InfoTextBox.Text = Me.InfoTextBox.Text + "Error checking if device supports HR time." End If - Me.InfoTextBox.Text = Me.InfoTextBox.Text & Chr(13) & Chr(10) & Chr(13) & Chr(10) + Me.InfoTextBox.Text = Me.InfoTextBox.Text + Chr(13) + Chr(10) + Chr(13) + Chr(10) rc = mbg_dev_is_gps(h, f) @@ -330,24 +356,95 @@ Friend Class mbgdevio_demo_vb_net If rc = PCPS_SUCCESS Then Me.InfoTextBox.Text = Me.InfoTextBox.Text _ - & "Receiver position: " & Chr(13) & Chr(10) _ - & MbgPosLlaStr(pos.lla) & Chr(13) & Chr(10) _ - & MbgRcvrPosStr(pos) + + "Receiver position: " + Chr(13) + Chr(10) _ + + MbgPosLlaStr(pos.lla) + Chr(13) + Chr(10) _ + + MbgRcvrPosStr(pos) + Else + Me.InfoTextBox.Text = Me.InfoTextBox.Text _ + + "Error reading receiver position." + End If + Else + Me.InfoTextBox.Text = Me.InfoTextBox.Text _ + + "Device does not support receiver position." + End If + Else + Me.InfoTextBox.Text = Me.InfoTextBox.Text _ + + "Error checking if device supports receiver position." + End If + + Me.InfoTextBox.Text = Me.InfoTextBox.Text _ + + Chr(13) + Chr(10) + Chr(13) + Chr(10) + + + ' If the device supports raw IRIG data, read it. + rc = mbg_dev_has_raw_irig_data(h, f) + + Dim d As MBG_RAW_IRIG_DATA + + If rc = PCPS_SUCCESS Then + ' could check successfully + If f <> 0 Then + ' device provides raw IRIG data + rc = mbg_get_raw_irig_data(h, d) + + If rc = PCPS_SUCCESS Then + Me.InfoTextBox.Text = Me.InfoTextBox.Text + "Raw IRIG data:" + For i As Integer = 0 To 15 + Me.InfoTextBox.Text = Me.InfoTextBox.Text + " " + d.b(i).ToString("X2") + Next + Me.InfoTextBox.Text = Me.InfoTextBox.Text + Chr(13) + Chr(10) + + Me.InfoTextBox.Text = Me.InfoTextBox.Text + "Time from raw IRIG data: " _ + + mbg_decode_raw_irig_hour(d).ToString("D2") + ":" _ + + mbg_decode_raw_irig_min(d).ToString("D2") + ":" _ + + mbg_decode_raw_irig_sec(d).ToString("D2") + Else + Me.InfoTextBox.Text = Me.InfoTextBox.Text _ + + "Error reading raw IRIG data." + End If + Else + Me.InfoTextBox.Text = Me.InfoTextBox.Text _ + + "Device does not support raw IRIG data." + End If + Else + Me.InfoTextBox.Text = Me.InfoTextBox.Text _ + + "Error checking if device supports raw IRIG data." + End If + + Me.InfoTextBox.Text = Me.InfoTextBox.Text + Chr(13) + Chr(10) + + + ' If the device supports raw IRIG time, read it. + rc = mbg_dev_has_irig_time(h, f) + + Dim irig_time As PCPS_IRIG_TIME + + If rc = PCPS_SUCCESS Then + ' could check successfully + If f <> 0 Then + ' device provides raw IRIG data + rc = mbg_get_irig_time(h, irig_time) + + If rc = PCPS_SUCCESS Then + Me.InfoTextBox.Text = Me.InfoTextBox.Text + "IRIG time read directly: " _ + + irig_time.hour.ToString("D2") + ":" _ + + irig_time.min.ToString("D2") + ":" _ + + irig_time.sec.ToString("D2") Else Me.InfoTextBox.Text = Me.InfoTextBox.Text _ - & "Error reading receiver position." + + "Error reading IRIG time." End If Else Me.InfoTextBox.Text = Me.InfoTextBox.Text _ - & "Device does not support receiver position." + + "Device does not support IRIG time." End If Else Me.InfoTextBox.Text = Me.InfoTextBox.Text _ - & "Error checking if device supports receiver position." + + "Error checking if device supports IRIG time." End If Me.InfoTextBox.Text = Me.InfoTextBox.Text _ - & Chr(13) & Chr(10) & Chr(13) & Chr(10) + + Chr(13) + Chr(10) + Chr(13) + Chr(10) @@ -365,12 +462,12 @@ Friend Class mbgdevio_demo_vb_net If rc = PCPS_SUCCESS Then Me.InfoTextBox.Text = Me.InfoTextBox.Text _ - & "Ucap Entries: " & VB6.Format(ucap_entries.used, "0") _ - & "/" & VB6.Format(ucap_entries.max, "0") _ - & " used" & Chr(13) & Chr(10) + + "Ucap Entries: " + VB6.Format(ucap_entries.used, "0") _ + + "/" + VB6.Format(ucap_entries.max, "0") _ + + " used" + Chr(13) + Chr(10) Else Me.InfoTextBox.Text = Me.InfoTextBox.Text _ - & "Error reading ucap entries." + + "Error reading ucap entries." End If ' Though it's only useful to read a capture event if ucap_entries.used @@ -380,46 +477,46 @@ Friend Class mbgdevio_demo_vb_net If rc = PCPS_SUCCESS Then Me.InfoTextBox.Text = Me.InfoTextBox.Text _ - & "Ucap read: Raw: " & PcpsTimeStampToHexString(ucap.tstamp) _ - & Chr(13) & Chr(10) + + "Ucap read: Raw: " + PcpsTimeStampToHexString(ucap.tstamp) _ + + Chr(13) + Chr(10) If ucap.tstamp.sec = 0 And ucap.tstamp.frac = 0 Then ' No capture event has been available in the buffer Me.InfoTextBox.Text = Me.InfoTextBox.Text _ - & "(No ucap event available)" + + "(No ucap event available)" Else ' Print the user capture input channel number and the time stamp. ' Any of the PcpsHrTime.. or PcpsTimeStamp.. functions could be ' used here to print the time stamp. Me.InfoTextBox.Text = Me.InfoTextBox.Text _ - & "Ch" & VB6.Format(ucap.signal) & ": " _ - & PcpsHrTimeToLocalTimeString(ucap) + + "Ch" + VB6.Format(ucap.signal) + ": " _ + + PcpsHrTimeToLocalTimeString(ucap) ' Check the ucap event status to see if an overrun has occurred ' (i.e. the interval between 2 events has been too short) If ucap.status And PCPS_UCAP_OVERRUN Then - Me.InfoTextBox.Text = Me.InfoTextBox.Text & " << OVR" + Me.InfoTextBox.Text = Me.InfoTextBox.Text + " << OVR" End If ' Check the ucap event status to see if a buffer overflow has ' occurred (i.e. more events have occurred than could be stored ' in the FIF buffer) If ucap.status And PCPS_UCAP_BUFFER_FULL Then - Me.InfoTextBox.Text = Me.InfoTextBox.Text & " << FULL" + Me.InfoTextBox.Text = Me.InfoTextBox.Text + " << FULL" End If End If Else - Me.InfoTextBox.Text = Me.InfoTextBox.Text & "Error reading ucap entries." + Me.InfoTextBox.Text = Me.InfoTextBox.Text + "Error reading ucap entries." End If Else - Me.InfoTextBox.Text = Me.InfoTextBox.Text & "Device does not support user captures." + Me.InfoTextBox.Text = Me.InfoTextBox.Text + "Device does not support user captures." End If Else - Me.InfoTextBox.Text = Me.InfoTextBox.Text & "Error checking if device supports user captures." + Me.InfoTextBox.Text = Me.InfoTextBox.Text + "Error checking if device supports user captures." End If - Me.InfoTextBox.Text = Me.InfoTextBox.Text & Chr(13) & Chr(10) + Me.InfoTextBox.Text = Me.InfoTextBox.Text + Chr(13) + Chr(10) done: diff --git a/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.vbproj b/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.vbproj index bf8932e..d5509da 100644 --- a/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.vbproj +++ b/vb.net/demo/mbgdevio/mbgdevio-demo-vb.net.vbproj @@ -89,6 +89,12 @@ </Compile> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="mbgdevio-demo-vb.net.resx"> + <SubType>Designer</SubType> + <DependentUpon>mbgdevio-demo-vb.net.vb</DependentUpon> + </EmbeddedResource> + </ItemGroup> + <ItemGroup> <Folder Include="My Project\" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" /> diff --git a/vb.net/mbglib/mbgdefs-vb.net.vb b/vb.net/mbglib/mbgdefs-vb.net.vb index 11d4747..a104edb 100644 --- a/vb.net/mbglib/mbgdefs-vb.net.vb +++ b/vb.net/mbglib/mbgdefs-vb.net.vb @@ -6,7 +6,7 @@ Module mbgdefs '************************************************************************** ' - ' $Id: mbgdefs-vb.net.vb 1.1 2008/05/23 11:18:33Z martin REL_M $ + ' $Id: mbgdefs-vb.net.vb 1.2 2014/08/14 09:03:36Z martin REL_M $ ' ' Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany ' @@ -25,6 +25,9 @@ Module mbgdefs ' ' ----------------------------------------------------------------------- ' $Log: mbgdefs-vb.net.vb $ + ' Revision 1.2 2014/08/14 09:03:36Z martin + ' Added some status code definitions. + ' Updated some comments. ' Revision 1.1 2008/05/23 11:18:33Z martin ' Initial revision for VB.NET 2005. ' @@ -35,8 +38,9 @@ Module mbgdefs Public Const PCPS_SUCCESS As Short = 0 - ' Bit masks used with both the status fields of the PCPS_TIME structure - ' and the PCPS_HR_TIME structure: + ' Bit masks used with the 8 bit wide status fields of the PCPS_TIME + ' structure and the PCPS_HR_TIME structure (PCPS_STATUS type) as well + ' as with the 16 bit wide extended status (PCPS_STATUS_X type): Public Const PCPS_FREER As Short = &H1S ' DCF77 clock running on xtal ' GPS receiver has not verified its position @@ -63,10 +67,14 @@ Module mbgdefs ' day-of-year from the IRIG signal. - ' Bit masks used with the status fields of the PCPS_HR_TIME structure only: + ' Bit masks used with the 16 bit wide extended status (PCPS_STATUS_X type) only, + ' e.g. the status fields of the PCPS_HR_TIME and PCPS_IRIG_TIME structure: - Public Const PCPS_LS_ENB As Short = &H100S ' current second is leap second - Public Const PCPS_ANT_FAIL As Short = &H200S ' antenna failure + Public Const PCPS_LS_ENB As Short = &H100S ' current second is leap second + Public Const PCPS_ANT_FAIL As Short = &H200S ' antenna failure + Public Const PCPS_LS_ANN_NEG As Short = &H400S ' announced leap second is negative + Public Const PCPS_SCALE_GPS As Short = &H800S ' time stamp is GPS scale + Public Const PCPS_SCALE_TAI As Short = &H1000S ' time stamp is TAI scale ' The next two status bits are used only if the PCPS_HR_TIME structure diff --git a/vb.net/mbglib/mbgdevio-vb.net.vb b/vb.net/mbglib/mbgdevio-vb.net.vb index e036c24..0d82cfd 100644 --- a/vb.net/mbglib/mbgdevio-vb.net.vb +++ b/vb.net/mbglib/mbgdevio-vb.net.vb @@ -6,7 +6,7 @@ Module mbgdevio '************************************************************************** ' - ' $Id: mbgdevio-vb.net.vb 1.1 2008/05/23 10:56:21Z martin REL_M $ + ' $Id: mbgdevio-vb.net.vb 1.2 2014/08/14 09:06:52Z martin REL_M $ ' ' Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany ' @@ -25,6 +25,12 @@ Module mbgdevio ' ' ----------------------------------------------------------------------- ' $Log: mbgdevio-vb.net.vb $ + ' Revision 1.2 2014/08/14 09:06:52Z martin + ' Added functions and definitions to support device info. + ' Added functions and definitions to support raw IRIG time. + ' Added functions and definitions to support raw IRIG data. + ' Use fixed width data types where possible and appropriate. + ' Updated comments. ' Revision 1.1 2008/05/23 10:56:21Z martin ' Initial revision for VB.NET 2005, based v1.4 for VB6. ' @@ -35,8 +41,78 @@ Module mbgdevio Public Const MBGDEVIO_VERSION As Short = &H212S - ' The structure below is passed to the function mbg_get_time - ' to read date, time, and status + ' A port resource info structure + + <StructLayout(LayoutKind.Sequential, Pack:=1)> _ + Public Structure PCPS_PORT_RSRC + Dim base As UInt16 ' I/O Port base address + Dim num As UInt16 ' Size of I/O port range + End Structure + + + ' The maximum length of a device name, including terminating 0 + Public Const PCPS_CLOCK_NAME_SZ As Integer = 10 + + ' Fixed device characteristics depending on the device type + + <StructLayout(LayoutKind.Sequential, Pack:=1)> _ + Public Structure PCPS_DEV_TYPE + Dim num As UInt16 + <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=PCPS_CLOCK_NAME_SZ)> _ + Dim name As String + Dim dev_id As UInt16 + Dim ref_type As UInt16 + Dim bus_flags As UInt16 + End Structure + + + ' The number of port resources reported in PCPS_DEV_CFG + Public Const N_PCPS_PORT_RSRC As Integer = 2 + + ' The maximum length of a firmware ID string, including terminating 0 + Public Const PCPS_ID_SZ As Integer = 33 + + ' The maximum length of a serial number string, including terminating 0 + Public Const PCPS_SN_SZ As Integer = 17 + + + ' Variable device characteristics depending firmware version + ' bus configuration, etc. + + <StructLayout(LayoutKind.Sequential, Pack:=1)> _ + Public Structure PCPS_DEV_CFG + Dim err_flags As UInt32 ' PCPS_ERR_FLAGS + Dim bus_num As UInt16 ' PCPS_BUS_NUM + Dim slot_num As UInt16 ' PCPS_SLOT_NUM + <MarshalAs(UnmanagedType.ByValArray, SizeConst:=N_PCPS_PORT_RSRC)> _ + Dim port() As PCPS_PORT_RSRC + Dim status_port As UInt16 + Dim irq_num As Int16 + Dim timeout_clk As UInt32 + Dim fw_rev_num As UInt16 + Dim features As UInt32 ' PCPS_FEATURES + <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=PCPS_ID_SZ)> _ + Dim fw_id As String ' PCPS_ID_STR + <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=PCPS_SN_SZ)> _ + Dim sernum As String ' PCPS_SN_STR + End Structure + + + ' General device info that can be retrieved by an API call + + <StructLayout(LayoutKind.Sequential, Pack:=1)> _ + Public Structure PCPS_DEV + Dim type As PCPS_DEV_TYPE + Dim cfg As PCPS_DEV_CFG + End Structure + + + ' This structure is passed to the function mbg_get_time + ' to be filled up with date, time, and status. + ' This is supported by all devices but the resolution of time + ' is limited to 10 ms (100ths of seconds). + ' The PCPS_HR_TIME structure should be read preferably, + ' if supported by the device. <StructLayout(LayoutKind.Sequential, Pack:=1)> _ Public Structure PCPS_TIME @@ -54,54 +130,52 @@ Module mbgdevio End Structure - ' The structure below has been introduced to be able to handle - ' high resolution time stamps. + ' A structure which can hold a high resolution time stamp. <StructLayout(LayoutKind.Sequential, Pack:=1)> _ Public Structure PCPS_TIME_STAMP - Dim sec As Integer ' UInt32, seconds since 1970 (UTC) - Dim frac As Integer ' UInt32, fractions of second ( &HFFFFFFFF == 0.9999.. sec) + Dim sec As UInt32 ' seconds since 1970 (UTC) + Dim frac As UInt32 ' fractions of second ( &HFFFFFFFF == 0.9999.. sec) End Structure - ' The structure below holds a HR time stamp, plus UTC offset and status info + ' This structure holds a HR time stamp, plus UTC offset and status info. <StructLayout(LayoutKind.Sequential, Pack:=1)> _ Public Structure PCPS_HR_TIME Dim tstamp As PCPS_TIME_STAMP - Dim utc_offs As Integer ' [sec] signed!! (local time = tstamp + offs_utc) - Dim status As Short ' flag bits, see below + Dim utc_offs As Int32 ' [sec] signed!! (local time = tstamp + offs_utc) + Dim status As UInt16 ' bit coded PCPS_TIME_STATUS_X type Dim signal As Byte ' 0..255 End Structure - - ' The structure below holds a HR time plus an associated Windows - ' performance counter value which can be used to relate performance - ' counter values to the current time. Please note that an application - ' must also determine the Windows performance counter frequency in order - ' to convert differences of performance counter values to time intervals. + ' This structure holds a HR time plus an associated cycles count which is in fact + ' a value returned by the Windows QueryPerformanceCounter (QPC) API call. + ' The cycles count can be used to relate QPC values to the current time. + ' Please note that an application must also determine the Windows performance counter + ' frequency in order to convert differences of cycles counts to time intervals. <StructLayout(LayoutKind.Sequential, Pack:=1)> _ Public Structure PCPS_HR_TIME_CYCLES - Dim cycles As Long ' UInt64, performance counter value + Dim cycles As UInt64 ' performance counter value Dim t As PCPS_HR_TIME ' associated HR time End Structure - ' The structure below contains the maximum number of entries of an on-board + ' This structure contains the maximum number of entries of an on-board ' user capture FIFO buffer plus the number of currently used entries. <StructLayout(LayoutKind.Sequential, Pack:=1)> _ Public Structure PCPS_UCAP_ENTRIES - Dim used As Integer ' the number of saved capture events - Dim max As Integer ' capture buffer size + Dim used As UInt32 ' the number of saved capture events + Dim max As UInt32 ' capture buffer size End Structure ' The definitions below are used with geographic positions. - ' The type below is used to hold a geographic position + ' This structure is used to hold a geographic position ' in kartesian coordinates. <StructLayout(LayoutKind.Sequential, Pack:=1)> _ @@ -112,55 +186,202 @@ Module mbgdevio End Structure - ' The type below is used to pass a geographic position + ' This structure is used to hold a geographic position ' in raw geographic coordinates. <StructLayout(LayoutKind.Sequential, Pack:=1)> _ Public Structure MBG_POS_LLA - Dim lat As Double ' latitude, in radians - Dim lon As Double ' longitude, in radians - Dim alt As Double ' altitude (height above ellipsoid), in meters + Dim lat As Double ' latitude, in radians + Dim lon As Double ' longitude, in radians + Dim alt As Double ' altitude (height above ellipsoid), in meters End Structure - ' The type below is used to store a geographic coordinate + ' This structure is used to store a geographic coordinate ' in broken-down (human readable) format. <StructLayout(LayoutKind.Sequential, Pack:=1)> _ Public Structure MBG_DMS - Dim prefix As Short ' ASCII code of 'N', 'E', 'S' or 'W' - Dim deg As Short ' [0...90 (lat) or 0...180 (lon)] - Dim min As Short ' [0...59] - Dim sec As Double ' [0...59.999] + Dim prefix As UInt16 ' ASCII code of 'N', 'E', 'S' or 'W' + Dim deg As UInt16 ' [0...90 (lat) or 0...180 (lon)] + Dim min As UInt16 ' [0...59] + Dim sec As Double ' [0...59.999] End Structure + ' The geographic position read from a GPS receiver. + ' The position is stored in different formats, so the application + ' doesn't have to do huge computations to display the position + ' in the prefered format. + <StructLayout(LayoutKind.Sequential, Pack:=1)> _ Public Structure MBG_RCVR_POS Dim xyz As MBG_POS_XYZ ' always WGS84 ECEF coordinates Dim lla As MBG_POS_LLA ' depending on the ellipsoid used for reference Dim longitude As MBG_DMS ' longitude in degrees, minutes, seconds Dim latitude As MBG_DMS ' latitude in degrees, minutes, seconds - Dim ellipsoid As Short ' ellipsoid used for reference + Dim ellipsoid As Int16 ' ellipsoid used for reference + End Structure + + + ' This structure can be used to read the raw IRIG time decoded + ' by an IRIG receiver device, if the device supports this. + ' + ' The granularity of the value in the .frac field depends on + ' the update interval of the structure as implemented + ' in the firmware. I.e. if the raw IRIG time is updated + ' only once per second, the .frac value can always be 0. + + <StructLayout(LayoutKind.Sequential, Pack:=1)> _ + Public Structure PCPS_IRIG_TIME + Dim status As UInt16 ' bit coded status bits (PCPS_TIME_STATUS_X type) + Dim offs_utc As Int16 ' [minutes] + Dim yday As UInt16 ' day of year, 1..356/366 + Dim frac As UInt16 ' fractions of seconds, 0.1 ms units + Dim sec As Byte ' seconds, 0..59, or 60 if leap second + Dim min As Byte ' minutes, 0..59 + Dim hour As Byte ' hours, 0..23 + Dim year As Byte ' 2 digit year number, &HFF if year not supp. by the IRIG code + Dim signal As Byte ' signal strength + Dim reserved As Byte ' currently not used, always 0 + End Structure + + + ' The buffer size used to read raw IRIG data bits. + Public Const MBG_RAW_IRIG_DATA_SIZE As Integer = 16 + + ' An array of bytes containing raw IRIG data bits + ' decoded from a timecode fed to a timecode receiver. + + <StructLayout(LayoutKind.Sequential, Pack:=1)> _ + Public Structure MBG_RAW_IRIG_DATA + <MarshalAs(UnmanagedType.ByValArray, SizeConst:=MBG_RAW_IRIG_DATA_SIZE)> _ + Dim b() As Byte End Structure + ' The function below takes a PCPS_TIME_STAMP structure and returns + ' a string which represents the date and time. + + Public Function PcpsTimeStampToString(ByRef t As PCPS_TIME_STAMP) As String + + Const DaysPerYear As Double = 86400.0# + Const EpocheOffs1970 As Double = 25569.0# + Const frac_scale As Double = 4294967296.0# ' &H100000000 + Dim dt As Date + Dim frac As Double + Dim lfrac As Long + + ' Convert seconds since 1970 to the VB date format + dt = System.DateTime.FromOADate(CDbl(t.sec) / DaysPerYear + EpocheOffs1970) + + ' Convert the fractions of the second to decimal fractions + ' (&HFFFFFFFF = 0.999999...) + frac = CDbl(t.frac) + + ' Negative frac values require special handling since VB6 only + ' provides signed 32 bit values whereas the frac value's nature + ' is unsigned + If t.frac < 0 Then + frac = frac + frac_scale + End If + + frac = frac / frac_scale + + ' Re-scale the fractions depending on the number of decimal + ' digits we want to print, e.g. if we want to print 7 digits + ' (100 nanosecond units) then we must multiply by 1E7 + ' and specify the output format accordingly. + lfrac = frac * 10000000.0# + + PcpsTimeStampToString = dt.ToString("yyyy-mm-dd hh:MM:ss") _ + + "." + lfrac.ToString("D7") + End Function + + + ' The functions below simplify decoding of data from a MBG_RAW_IRIG_DATA + ' structure. + + ' Get a particular bit from MBG_RAW_IRIG_DATA + + Public Function mbg_decode_raw_irig_bit(ByVal idx As Integer, ByRef d As MBG_RAW_IRIG_DATA) As Integer + + Dim byte_offs As Integer = idx >> 3 + Dim bit_shift As Integer = 7 - (idx And 7) + + mbg_decode_raw_irig_bit = (d.b(byte_offs) >> bit_shift) And &H1 + + End Function + + + ' Decode a particular value from MBG_RAW_IRIG_DATA. The value + ' must be coded in subsequent bits. + + Public Function mbg_decode_raw_irig_val(ByVal first_idx As Integer, _ + ByVal num_bits As Integer, _ + ByRef d As MBG_RAW_IRIG_DATA) As Long + Dim ret_val As Long = 0 + Dim i As Integer = 0 + + While i < num_bits + Dim next_bit As Long + next_bit = mbg_decode_raw_irig_bit(first_idx + i, d) << i + ret_val = ret_val Or next_bit + i = i + 1 + End While + + mbg_decode_raw_irig_val = ret_val + + End Function + + + ' Decode the seconds field from MBG_RAW_IRIG_DATA + ' This is supported for IRIG / IEEE / Afnor code formats. + + Public Function mbg_decode_raw_irig_sec(ByRef p As MBG_RAW_IRIG_DATA) As Integer + + mbg_decode_raw_irig_sec = mbg_decode_raw_irig_val(1, 4, p) _ + + mbg_decode_raw_irig_val(6, 3, p) * 10 + End Function + + + ' Decode the minutes field from MBG_RAW_IRIG_DATA + ' This is supported for IRIG / IEEE / Afnor code formats. + + Public Function mbg_decode_raw_irig_min(ByRef p As MBG_RAW_IRIG_DATA) As Integer + + mbg_decode_raw_irig_min = mbg_decode_raw_irig_val(10, 4, p) _ + + mbg_decode_raw_irig_val(15, 3, p) * 10 + End Function + + + ' Decode the hours field from MBG_RAW_IRIG_DATA + ' This is supported for IRIG / IEEE / Afnor code formats. + + Public Function mbg_decode_raw_irig_hour(ByRef p As MBG_RAW_IRIG_DATA) As Integer + + mbg_decode_raw_irig_hour = mbg_decode_raw_irig_val(20, 4, p) _ + + mbg_decode_raw_irig_val(25, 2, p) * 10 + End Function + + + ' ' Some of the functions exported by the mbgdevio DLL ' -------------------------------------------------- ' ' GENERAL NOTE: - ' Not all API calls described below are supported by any Meinberg - ' plug-in card. Calls to functions which are not supported by a device + ' Not all API calls described below are supported by every Meinberg + ' plug-in device. Calls to functions which are not supported by a device ' don't do any harm, they just return an error code to the application. ' However, every API call to an unsupported function results in a log entry ' in the Windows application event log, so an application should first check ' whether such an API call is supported by the specific device. API calls ' which are not supported by each device are commented accordingly. - ' Return the number of radio clock devices detected - ' If this function returns 0, then no devices has been detected. + ' Return the number of available devices. If this function returns 0 + ' then no device has been detected. Public Declare Function mbg_find_devices Lib "mbgdevio" () As Integer ' Open the device with given index and retrieve a handle to the device @@ -171,44 +392,55 @@ Module mbgdevio ' The device handle value will be set to 0. Public Declare Function mbg_close_device Lib "mbgdevio" (ByRef h As Integer) As Integer + ' Read general device info from the device referenced by handle h. + Public Declare Function mbg_get_device_info Lib "mbgdevio" (ByVal h As Integer, ByRef p As PCPS_DEV) As Integer + '-------------------------------------------------------------------------------- ' Read date, time, and status from the device referenced by handle h. ' This function is supported by all Meinberg plug-in boards and returns ' date and time in human readable format (calendar date and time). - ' However, the resolution of time is limited to 10 milliseconds. + ' However, the resolution of time is limited to 10 milliseconds, so + ' e.g. one of the mbg_get_hr_time... functions should be used preferably, + ' if supported by the device. Public Declare Function mbg_get_time Lib "mbgdevio" (ByVal h As Integer, ByRef t As PCPS_TIME) As Integer '-------------------------------------------------------------------------------- - ' The functions below read high resolution time plus status from the device - ' referenced by handle h. - ' These functions are NOT supported by all Meinberg plug-in boards, and the - ' effective resolution of the HR time depends on the characteristics of the - ' specific device. - - ' Check whether the device referenced by handle h supports HR time. + ' These functtions can be used to read a high resolution time (HR) stamp + ' plus status from a device. The effective resolution of the HR time depends + ' on the characteristics of the specific device. The returned time stamp may + ' be biased by a latency due to the IOCTL call performed by the function, + ' so there are variants of this functions available which can determine or + ' compensate this latency. + ' These functions are NOT supported by all Meinberg plug-in devices, and + ' mbg_dev_has_hr_time can be used to check if they are supported by a + ' particular device. + + ' Check whether the device referenced by handle h supports high resolution (HR) time. ' If it does then the value returned for f is not 0. Public Declare Function mbg_dev_has_hr_time Lib "mbgdevio" (ByVal h As Integer, ByRef f As Integer) As Integer - ' Read a HR time stamp from the board. The returned time stamp may be biased - ' by a latency due to the IOCTL call performed by the function. + ' Read a high resolution time stamp plus status from the device referenced + ' by handle h. Public Declare Function mbg_get_hr_time Lib "mbgdevio" (ByVal h As Integer, ByRef t As PCPS_HR_TIME) As Integer - ' Read a HR time stamp from the board plus a performance counter value - ' associated to that time stamp. The performance counter value can be used - ' by the application to compensate the latency mentioned above. + ' Read a HR time stamp from the device plus a performance counter AKA cycles + ' value associated to that time stamp. The cycles value can be used by the + ' application to compensate the latency introduced by the API call. Public Declare Function mbg_get_hr_time_cycles Lib "mbgdevio" (ByVal h As Integer, ByRef p As PCPS_HR_TIME_CYCLES) As Integer - ' Read a HR time stamp from the board and compensate the latency. Return the compensated - ' time stamp, and optionally also return the latency value in 100 nanosecond units. - ' If the application does not need the latency value then a null pointer may be passed - ' for parameter l. + ' Read a HR time stamp from the board and compensate the latency. + ' Return the compensated time stamp, and optionally also return + ' the latency value in 100 nanosecond units. + ' If the application does not need the latency value then a null pointer + ' may be passed for parameter l. Public Declare Function mbg_get_hr_time_comp Lib "mbgdevio" (ByVal h As Integer, ByRef t As PCPS_HR_TIME, ByRef l As Integer) As Integer '-------------------------------------------------------------------------------- - ' The functions below can be used with the capture buffer available on some cards. + ' The functions below can be used with the event capture buffer provided + ' by some devices. ' These functions are NOT supported by all Meinberg plug-in boards, and the ' effective accuracy of the time capture events depends on the characteristics ' of the specific device. @@ -225,22 +457,51 @@ Module mbgdevio ' FIFO buffer, and the number of events currently saved in the buffer. Public Declare Function mbg_get_ucap_entries Lib "mbgdevio" (ByVal h As Integer, ByRef p As PCPS_UCAP_ENTRIES) As Integer - ' Retrieve an entry from the on-board user capture FIFO buffer. The returned entry - ' is removed from the buffer. If no event is available in the buffer, i.e. the buffer - ' is empty, then then both the seconds and fractions of the returned time stamp are 0. + ' Retrieve an entry from the on-board user capture FIFO buffer. The returned + ' entry is removed from the buffer. If no event is available in the buffer, + ' i.e. the buffer is empty, then then both the seconds and fractions of the + ' returned time stamp are 0. Public Declare Function mbg_get_ucap_event Lib "mbgdevio" (ByVal h As Integer, ByRef t As PCPS_HR_TIME) As Integer '-------------------------------------------------------------------------------- - ' The functions below can be used to read the receiver position from GPS add-in - ' cards. This is NOT supported by non-GPS add-in cards, so there's another - ' function which checks whether a specific device is a GPS receiver. + ' The functions below can be used to read the receiver position from GPS devices. + ' This is NOT supported by non-GPS add-in cards, so there's another + ' function which checks whether a specific device supports this. - ' Check whether the device referenced by handle h is a GPS receiver. - ' If it is then the value returned for f is not 0. + ' Check whether the device referenced by handle h supports reading the receiver + ' position. If it does then the value returned for f is not 0. Public Declare Function mbg_dev_is_gps Lib "mbgdevio" (ByVal h As Integer, ByRef f As Integer) As Integer ' Read the current receiver position. Public Declare Function mbg_get_gps_pos Lib "mbgdevio" (ByVal h As Integer, ByRef p As MBG_RCVR_POS) As Integer + + '-------------------------------------------------------------------------------- + ' The functions below can be used to read the raw IRIG time a time code receiver + ' (TCR) has decoded from an incoming time code signal. + ' This is NOT supported by non-TCR devices, so there's another function which + ' checks whether this is supported. + + ' Check whether the device referenced by handle h supports reading raw IRIG time. + ' If it is then the value returned for f is not 0. + Public Declare Function mbg_dev_has_irig_time Lib "mbgdevio" (ByVal h As Integer, ByRef f As Integer) As Integer + + ' Read the raw IRIG time. + Public Declare Function mbg_get_irig_time Lib "mbgdevio" (ByVal h As Integer, ByRef p As PCPS_IRIG_TIME) As Integer + + + '-------------------------------------------------------------------------------- + ' The functions below can be used to read the raw data bits a time code receiver + ' (TCR) has decoded from an incoming time code. + ' This is NOT supported by non-TCR devices, so there's another function which + ' checks whether this is supported. + + ' Check whether the device referenced by handle h supports reading raw time + ' code data. If does then the value returned for f is not 0. + Public Declare Function mbg_dev_has_raw_irig_data Lib "mbgdevio" (ByVal h As Integer, ByRef f As Integer) As Integer + + ' Read the latest raw time code data bits. + Public Declare Function mbg_get_raw_irig_data Lib "mbgdevio" (ByVal h As Integer, ByRef p As MBG_RAW_IRIG_DATA) As Integer + End Module
\ No newline at end of file |