1046 - PhidgetBridge 4-Input sample code as with PHmanager

Legacy support with Phidget21
teamtwf8
Phidgetly
Posts: 34
Joined: Mon Sep 11, 2006 1:24 pm
Contact:

1046 - PhidgetBridge 4-Input sample code as with PHmanager

Postby teamtwf8 » Thu Jul 21, 2011 12:56 am

Hi Patrick or others,

When I run the PH control manager from the taskbar and double click on the 1046 - PhidgetBridge 4-Input from there it opens a program.
This program has the calibration option.

However the sample code from the download section for VB6.0 does not have the calibration section. :(
Is it possible to share this part of the code?
It is not that I am lazy but it takes time to invent the wheel again. :mrgreen:

Let me know what is possible.

Thanks in advance,

Paco Raap

mphi
Phidgetly
Posts: 39
Joined: Tue Nov 16, 2010 4:27 pm
Contact:

Re: 1046 - PhidgetBridge 4-Input sample code as with PHmanag

Postby mphi » Thu Jul 21, 2011 9:22 am

The logic in how you can calibrate bridge values are shown in the C# and VB.NET examples. Please have a look at them.

teamtwf8
Phidgetly
Posts: 34
Joined: Mon Sep 11, 2006 1:24 pm
Contact:

Re: 1046 - PhidgetBridge 4-Input sample code as with PHmanag

Postby teamtwf8 » Fri Jul 22, 2011 12:02 am

Thanks,

Will check them.

Paco

teamtwf8
Phidgetly
Posts: 34
Joined: Mon Sep 11, 2006 1:24 pm
Contact:

Re: 1046 - PhidgetBridge 4-Input sample code as with PHmanag

Postby teamtwf8 » Fri Jul 22, 2011 2:18 pm

OK,

Installed Express 2010 and copied the code.
Hum, VB.net clearly different in approach.

Adapted the code to vb6 and after 8 hours I am still missing a key point I found out by step by step debugging.

If I click cmdset2 button it looses the values from cmdset1 action.
I know I am close but I am sure I overlook something very simple.

Any suggestion in the rigth direction would be appricated.
Added the code.

Code: Select all

' Program:     Bridge-full

' Description:
' -This example:
'    o displays all the information it can about the PhidgetBridge.
'    o allows user to change enable states, gain, and data rate.

Option Explicit
Dim WithEvents PhidgetBridge As PhidgetBridge
'Attribute PhidgetBridge.VB_VarHelpID = -1
Dim Value1 As Double
Dim Value1Coor As Double
Dim Value2 As Double
Dim Value2Coor As Double
Dim sSlope As Long
Dim yInt As Long
Dim sForce As Long
Dim sBridgeValue1 As Long
Dim s1 As String
Dim s2 As String
Dim s3 As String
Dim s4 As String
Dim S5 As String
Dim s6 As String
Dim S7 As String

Private Sub Form_Load()
    Set PhidgetBridge = Controls.Add("Phidget21COM.PhidgetBridge", "phidgetBridge")
    PhidgetBridge.Open
    attachF.Text = PhidgetBridge.IsAttached
    'enabledState.Enabled = False
    enabledState.Enabled = True 'bij opstarten gelijk de enable state activeren
    'controleer serienummer phidget en licentienummer anders textbox als niet OK.
    cmdSet1.Visible = False
    cmdSet2.Visible = False
    cmdSet1.Enabled = False
    cmdSet2.Enabled = False
   
    End Sub
Private Sub cmdSavesettings()

Open "C:\shockdyno\system.txt" For Output As #1
    s1 = "1"
    s2 = "2"
    s3 = "3"
    s4 = "4"
    S5 = "5"
Write #1, s1, s2, s3, s4, S5
Close #1

End Sub
Private Sub cmdMainscreen()
mainscreen Show
frm1.Hide
End Sub
Private Sub PhidgetBridge_OnAttach()
   
    Dim i As Long
   
    enabledState.Enabled = True
    bridgeIndex.Enabled = True
    bridgeIndex.Locked = False
    gain.Enabled = True
    gain.Locked = False
   
    DisplayDetails
   
    For i = 0 To PhidgetBridge.InputCount - 1
        bridgeIndex.AddItem (i)
    Next i
   
   bridgeIndex = 0
   
   If (PhidgetBridge.Enabled(bridgeIndex)) Then
        enabledState.Value = 1
   Else
        enabledState.Value = 0
   End If
   
   gain.AddItem (1)
   gain.AddItem (8)
   gain.AddItem (16)
   gain.AddItem (32)
   gain.AddItem (64)
   gain.AddItem (128)
   'gain = 1 'standaard waarde
   gain = 32 'eigen vaste waarde
   
   dataRateSlider.Min = PhidgetBridge.DataRateMax / 8
   dataRateSlider.Max = PhidgetBridge.DataRateMin / 8
   dataRateSlider.Value = PhidgetBridge.DataRate / 8
   dataRateF.Text = PhidgetBridge.DataRate
   
End Sub



Private Sub PhidgetBridge_OnDetach()
    attachF.Text = "False"
    nameF.Text = ""
    serialF.Text = ""
    versionF.Text = ""
    numBridgesF.Text = ""
    enabledState.Value = 0
    enabledState.Enabled = False
    bridgeIndex.Clear
    gain.Clear
    bridgeValueF.Text = ""
    dataRateF.Text = ""
End Sub

Private Sub bridgeIndex_Click()
   If (PhidgetBridge.Enabled(bridgeIndex)) Then
        enabledState.Value = 1
   Else
        enabledState.Value = 0
   End If
   
    Select Case PhidgetBridge.gain(bridgeIndex)
        Case PHIDGETCOM_BRIDGE_GAIN_1:
            gain = 1
        Case PHIDGETCOM_BRIDGE_GAIN_1:
            gain = 8:
            Case PHIDGETCOM_BRIDGE_GAIN_16:
            gain = 16
        Case PHIDGETCOM_BRIDGE_GAIN_32:
            gain = 32:
            Case PHIDGETCOM_BRIDGE_GAIN_64:
            gain = 64
        Case PHIDGETCOM_BRIDGE_GAIN_128:
            gain = 128:
    End Select
End Sub

Private Sub dataRateSlider_Change()
    PhidgetBridge.DataRate = dataRateSlider.Value * 8
    dataRateF.Text = dataRateSlider.Value * 8
End Sub

Private Sub enabledState_Click()

    If (enabledState.Value = 0) Then
        PhidgetBridge.Enabled(bridgeIndex) = False
    Else
        PhidgetBridge.Enabled(bridgeIndex) = True
    End If
End Sub

Private Sub Gain_Click()
    Select Case gain
        Case 1: PhidgetBridge.gain(bridgeIndex) = PHIDGETCOM_BRIDGE_GAIN_1
        Case 8: PhidgetBridge.gain(bridgeIndex) = PHIDGETCOM_BRIDGE_GAIN_8
        Case 16: PhidgetBridge.gain(bridgeIndex) = PHIDGETCOM_BRIDGE_GAIN_16
        Case 32: PhidgetBridge.gain(bridgeIndex) = PHIDGETCOM_BRIDGE_GAIN_32
        Case 64: PhidgetBridge.gain(bridgeIndex) = PHIDGETCOM_BRIDGE_GAIN_64
        Case 128: PhidgetBridge.gain(bridgeIndex) = PHIDGETCOM_BRIDGE_GAIN_128
    End Select
End Sub

'Display the properties of the device
Private Sub DisplayDetails()
    Dim i As Integer
    attachF.Text = PhidgetBridge.IsAttached
    nameF.Text = PhidgetBridge.DeviceName
    serialF.Text = PhidgetBridge.SerialNumber
    versionF.Text = PhidgetBridge.DeviceVersion
    numBridgesF.Text = PhidgetBridge.InputCount
   
End Sub

Private Sub PhidgetBridge_OnBridgeData(ByVal Index As Long, ByVal Value As Double)
    bridgeValue.Text = PhidgetBridge.bridgeValue(bridgeIndex)
    convertedValue.Text = Format$(((sSlope * bridgeValue.Text) + yInt), "0.00")
    If cmdSet2.Enabled = True Then
    'convertedValue.Text = Format$(((sSlope * bridgeValue.Text) + yInt), "0.00")
   
    'VB.net code
    'bridgeValueTxt.Text = e.Value.ToString
    'convertedValueTxt.Text = Math.Round((slope * e.Value) + yInt, 2).ToString
    End If
End Sub
Private Sub cmdCalibration_Click()
cmdSet1.Visible = True
cmdSet1.Enabled = True
End Sub
Private Sub cmdSet1_Click()


'save the bridge value and the first weigth value
Value1 = bridgeValue.Text
Value1Coor = TextSet1.Text
cmdSet1.Visible = False
cmdSet2.Visible = True
cmdSet2.Enabled = True
End Sub

Private Sub cmdSet2_Click()


'save the bridge value and the second weigth value
Value2 = bridgeValue.Text
Value2Coor = TextSet2.Text
sSlope = (Value2Coor - Value1Coor) / (Value2 - Value1)
yInt = ((Value2Coor - Value1Coor) / (Value2 - Value1)) * (Value1Coor - (Value1 * sSlope))
cmdSet2.Visible = False
End Sub

Private Sub unload()
'sla de waarden op bij het verlaten het programma
cmdSavesettings
unload Me
End Sub

Private Sub test()


End Sub

teamtwf8
Phidgetly
Posts: 34
Joined: Mon Sep 11, 2006 1:24 pm
Contact:

Re: 1046 - PhidgetBridge 4-Input sample code (solved)

Postby teamtwf8 » Wed Jul 27, 2011 2:28 pm

Problem solved. :D

Took some time.

Paco


Return to “VB 6.0”

Who is online

Users browsing this forum: No registered users and 2 guests