Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

  1. Attribute VB_Name = "Module1"
  2. Public nod, Dev As Long
  3. Public serial, version As String
  4.  
  5.  
  6. Type USMCMode
  7.     PMode As Long       'Turn off buttons (TRUE - buttons disabled)
  8.     PReg As Long        'Current reduction regime (TRUE - regime is on)
  9.     ResetD As Long      'Turn power off and make a whole step (TRUE - apply)
  10.     EmReset As Long     'Quick power off
  11.     Tr1T As Long        'Trailer 1 TRUE state (TRUE : +3/+5Â; FALSE : 0Â)
  12.     Tr2T As Long        'Trailer 2 TRUE state (TRUE : +3/+5Â; FALSE : 0Â)
  13.     RotTrT As Long      'Rotary Transducer TRUE state (TRUE : +3/+5Â; FALSE : 0Â)
  14.     TrSwap As Long      'If TRUE, Trailers are treated to be swapped
  15.     Tr1En As Long       'If TRUE Trailer 1 Operation Enabled
  16.     Tr2En As Long       'If TRUE Trailer 2 Operation Enabled
  17.     RotTeEn As Long     'If TRUE Rotary Transducer Operation Enabled
  18.     RotTrOp As Long     'Rotary Transducer Operation Select (stop on error for TRUE)
  19.     Butt1T As Long      'Button 1 TRUE state (TRUE : +3/+5Â; FALSE : 0Â)
  20.     Butt2T As Long      'Button 2 TRUE state (TRUE : +3/+5Â; FALSE : 0Â)
  21.     ResetRT As Long     'Reset Rotary Transducer Check Positions (need one full revolution before it can detect error)
  22.     SyncOUTEn As Long   'If TRUE output syncronization enabled
  23.     SyncOUTR As Long    'If TRUE output synchronization counter will be reset
  24.     SyncINOp As Long    'Synchronization input mode:
  25.                         'True - Step motor will move one time to the destination position
  26.                         'False - Step motor will move multiple times by steps equal to the value destination position
  27.     SyncCount As Long   'Number of steps after which synchronization output sygnal occures
  28.     SyncInvert As Long  'Set to TRUE to invert output synchronization signal
  29.     'new
  30.     EncoderEn As Long   'Enable Encoder on pins {SYNCIN,ROTTR} - disables Synchronization input and Rotary Transducer
  31.     EncoderInv As Long  'Invert Encoder Counter Direction
  32.     ResBEnc As Long     'Reset <Encoder Position> and <SM Position in Encoder units> to 0
  33.     ResEnc As Long      'Reset <SM Position in Encoder units> to <Encoder Position>
  34.     Rsv1 As Long
  35.     Rsv2 As Long
  36. End Type
  37.  
  38. Type USMCParameters
  39.     AccelT As Single        'Acceleration time (in ms)
  40.     DecelT As Single        'Deceleration time (in ms)
  41.     PTimeout As Single      'Time (in ms) after which current will be reduced to 60% of normal
  42.     BTimeout1 As Single     'Time (in ms) after which speed of step motor rotation will be equal to the one specified at
  43.                             'BTO1P field (see below). (This parameter is used when controlling step motor using buttons)
  44.     BTimeout2 As Single     '
  45.     BTimeout3 As Single     '
  46.     BTimeout4 As Single     '
  47.     BTimeoutR As Single     'Time (in ms) after which reset command will be performed
  48.     BTimeoutD As Single     'This field is reserved for future use
  49.     MinP As Single          'Speed (steps/sec) while performing reset operation. (This parameter is used when controlling
  50.                             'step motor using buttons)
  51.     BTO1P As Single         'Speed (steps/sec) after BTIMEOUT 1 time have passed. (This parameter is used when controlling
  52.                             'step motor using buttons)
  53.     BTO2P As Single         '
  54.     BTO3P As Single         '
  55.     BTO4P As Single         '
  56.     MaxLoft As Integer      'Value in full steps that will be used performing backlash operation
  57.     StartPos As Long        'This field is reserved for future use
  58.     RTDelta As Integer      'Revolution distance – number of full steps per one full revolution
  59.     RTMinErr As Integer     'Number of full steps missed to raise the error flag
  60.     MaxTemp As Single       'Maximum allowed temperature (Celsius)
  61.     SynOUTP As Byte         'Duration of the output synchronization pulse
  62.     LoftPeriod As Single    'Speed of the last phase of the backlash operation.
  63.     'new
  64.     EncMult As Single       'Should be <Encoder Steps per Evolution> / <SM Steps per Evolution> and should be integer multiplied by 0.25
  65.     Rsv1 As Long
  66.     Rsv2 As Long
  67.     Rsv3 As Long
  68.     Rsv4 As Long
  69. End Type
  70.  
  71. Type USMCStartParameters
  72.     SDivisor As Byte    'Step is divided by this factor (1,2,4,8)
  73.     DefDir As Long      'Direction for backlash operation (relative)
  74.     LoftEn As Long      'Enable automatic backlash operation (works if slow start/stop mode is off)
  75.     SlStart As Long     'If TRUE slow start/stop mode enabled.
  76.     WSyncIN As Long     'If TRUE controller will wait for input synchronization signal to start
  77.     SyncOUTR As Long    'If TRUE output synchronization counter will be reset
  78.     ForceLoft As Long   'If TRUE and destination position is equal to the current position backlash operation will be performed.
  79.     'new
  80.     Rsv As Long
  81. End Type
  82.  
  83. Type USMCState
  84.     CurPos As Long      'Current position (in microsteps)
  85.     Temp As Single      'Current temperature of the driver
  86.     SDivisor As Byte    'Step is divided by this factor
  87.     Loft As Long        'Indicates backlash status
  88.     FullPower As Long   'If TRUE then full power.
  89.     CW_CCW As Long      'Current direction. Relatively!
  90.     Power As Long       'If TRUE then Step Motor is ON.
  91.     FullSpeed As Long   'If TRUE then full speed. Valid in "Slow Start" mode only.
  92.     AReset As Long      'TRUE After Device reset, FALSE after "Set Position".
  93.     RUN As Long         'Indicates if step motor is rotating
  94.     SyncIN As Long      'Logical state directly from input synchronization PIN
  95.     SyncOUT As Long     'Logical state directly from output synchronization PIN
  96.     RotTr As Long       'Indicates current rotary transducer press state
  97.     RotTrErr As Long    'Indicates rotary transducer error flag
  98.     EmReset As Long     'Indicates state of emergency disable button (local control)
  99.     Trailer1 As Long    'Indicates trailer 1 logical state.
  100.     Trailer2 As Long    'Indicates trailer 2 logical state.
  101.     Voltage As Single   'Input power source voltage (6-39V) -=24 version 0nly=-
  102.     'new
  103.     Rsv1 As Long
  104.     Rsv2 As Long
  105.    
  106. End Type
  107.  
  108. Declare Sub USMCGetLastErr Lib "USMCVBDLL.dll" _
  109.     Alias "_USMCVB_GetLastErr" (ByVal ErrStr As String, ByVal vlen As Long)
  110.  
  111. Declare Function USMCInit Lib "USMCVBDLL.dll" _
  112.     Alias "_USMCVB_Init" (ByRef value As Long, ByVal versions As String, _
  113.     ByVal vlen As Long, ByVal serials As String, ByVal slen As Long) As Long
  114.    
  115. Declare Function USMCGetState Lib "USMCVBDLL.dll" _
  116.     Alias "_USMCVB_GetState" (ByVal Dev As Long, ByRef Str As USMCState) As Long
  117.  
  118. Declare Function USMCGetStartParameters Lib "USMCVBDLL.dll" _
  119.     Alias "_USMCVB_GetStartParameters" (ByVal Dev As Long, ByRef Str As USMCStartParameters) As Long
  120.    
  121. Declare Function USMCStart Lib "USMCVBDLL.dll" _
  122.     Alias "_USMCVB_Start" (ByVal Dev As Long, ByVal DestPos As Long, ByRef Speed As Single, _
  123.                               ByRef Str As USMCStartParameters) As Long
  124.  
  125. Declare Function USMCStop Lib "USMCVBDLL.dll" _
  126.     Alias "_USMCVB_Stop" (ByVal Dev As Long) As Long
  127.  
  128. Declare Function USMCGetMode Lib "USMCVBDLL.dll" _
  129.     Alias "_USMCVB_GetMode" (ByVal Dev As Long, ByRef Str As USMCMode) As Long
  130.    
  131. Declare Function USMCSetMode Lib "USMCVBDLL.dll" _
  132.     Alias "_USMCVB_SetMode" (ByVal Dev As Long, ByRef Str As USMCMode) As Long
  133.  
  134. Declare Function USMCGetParameters Lib "USMCVBDLL.dll" _
  135.     Alias "_USMCVB_GetParameters" (ByVal Dev As Long, ByRef Str As USMCParameters) As Long
  136.    
  137. Declare Function USMCSetParameters Lib "USMCVBDLL.dll" _
  138.     Alias "_USMCVB_SetParameters" (ByVal Dev As Long, ByRef Str As USMCParameters) As Long
  139.  
  140. Declare Function USMCSaveParametersToFlash Lib "USMCVBDLL.dll" _
  141.     Alias "_USMCVB_SaveParametersToFlash" (ByVal Dev As Long) As Long
  142.    
  143. Declare Function USMCSetCurrentPosition Lib "USMCVBDLL.dll" _
  144.     Alias "_USMCVB_SetCurrentPosition" (ByVal Dev As Long, ByRef Str As USMCParameters) As Long
  145.    
  146.  
  147.  
  148. Sub PrintDMode(mode As USMCMode)
  149.     Dim out As String
  150.     out = "Mode parameters:" & (Chr(13))
  151.     out = out & "Buttons - "
  152.     If mode.PMode <> 0 Then
  153.         out = out & "Disabled" & (Chr(13))
  154.     Else
  155.         out = out & "Enabled" & (Chr(13)) & "Button 1 TRUE state - "
  156.         If mode.Butt1T <> 0 Then
  157.             out = out & "+3/+5 V" & (Chr(13))
  158.         Else
  159.             out = out & "0 V(GND)" & (Chr(13))
  160.         End If
  161.         out = out & "Button 2 TRUE state - "
  162.         If mode.Butt2T <> 0 Then
  163.             out = out & "+3/+5 V" & (Chr(13))
  164.         Else
  165.             out = out & "0 V(GND)" & (Chr(13))
  166.         End If
  167.     End If
  168.     out = out & "Current reduction regime - "
  169.     If mode.PReg <> 0 Then
  170.         out = out & "Used" & (Chr(13))
  171.     Else
  172.         out = out & "Not Used" & (Chr(13))
  173.     End If
  174.    
  175.     If mode.ResetD <> 0 Then
  176.         out = out & "Power - "
  177.         If mode.EmReset <> 0 Then
  178.             out = out & "Emerjency Off" & (Chr(13))
  179.         Else
  180.             out = out & "Off" & (Chr(13))
  181.         End If
  182.     Else
  183.         out = out & "Power - On" & (Chr(13))
  184.     End If
  185.     If mode.Tr1En <> 0 Or mode.Tr2En <> 0 Then
  186.         out = out & "Trailers are - "
  187.         If mode.TrSwap <> 0 Then
  188.             out = out & "Swapped" & (Chr(13))
  189.         Else
  190.             out = out & "Direct" & (Chr(13))
  191.         End If
  192.     End If
  193.     out = out & "Trailer 1 - "
  194.     If mode.Tr1En <> 0 Then
  195.         out = out & "Enabled" & (Chr(13)) & "Trailer 1 TRUE state - "
  196.         If mode.Tr1T <> 0 Then
  197.             out = out & "+3/+5 V" & (Chr(13))
  198.         Else
  199.             out = out & "0 V(GND)" & (Chr(13))
  200.         End If
  201.     Else
  202.         out = out & "Disabled" & (Chr(13))
  203.     End If
  204.     out = out & "Trailer 2 - "
  205.     If mode.Tr2En <> 0 Then
  206.         out = out & "Enabled" & (Chr(13)) & "Trailer 2 TRUE state - "
  207.         If mode.Tr2T <> 0 Then
  208.             out = out & "+3/+5 V" & (Chr(13))
  209.         Else
  210.             out = out & "0 V(GND)" & (Chr(13))
  211.         End If
  212.     Else
  213.         out = out & "Disabled" & (Chr(13))
  214.     End If
  215.     out = out & "Rotary Transducer - "
  216.     If mode.RotTeEn <> 0 Then
  217.         out = out & "Enabled" & (Chr(13)) & "Rotary Transducer TRUE state - "
  218.         If mode.RotTrT <> 0 Then
  219.             out = out & "+3/+5 V" & (Chr(13))
  220.         Else
  221.             out = out & "0 V(GND)" & (Chr(13))
  222.         End If
  223.         out = out & "Rotary Transducer Operation - "
  224.         If mode.RotTrOp <> 0 Then
  225.             out = out & "Stop on error" & (Chr(13))
  226.         Else
  227.             out = out & "Check and ignore error" & (Chr(13))
  228.         End If
  229.         out = out & "Reset Rotary Transducer Check Positions - "
  230.         If mode.ResetRT <> 0 Then
  231.             out = out & "Initiated" & (Chr(13))
  232.         Else
  233.             out = out & "No, why?" & (Chr(13))
  234.         End If
  235.     Else
  236.         out = out & "Disabled" & (Chr(13))
  237.     End If
  238.     out = out & "Output Syncronization - "
  239.     If mode.SyncOUTEn <> 0 Then
  240.         out = out & "Enabled" & (Chr(13)) & "Reset Output Synchronization Counter - "
  241.         If mode.SyncOUTR <> 0 Then
  242.             out = out & "Initiated" & (Chr(13))
  243.         Else
  244.             out = out & "No, why?" & (Chr(13))
  245.         End If
  246.         out = out & "Number of steps after which synchronization output sygnal occures - " & mode.SyncCount & (Chr(13))
  247.     Else
  248.         out = out & "Disabled" & (Chr(13))
  249.     End If
  250.     out = out & "Synchronization input mode:" & (Chr(13))
  251.     If mode.SyncINOp <> 0 Then
  252.         out = out & "Step motor will move one time to the destination position" & (Chr(13))
  253.     Else
  254.         out = out & "Step motor will move multiple times by [destination position]" & (Chr(13))
  255.     End If
  256.     out = out & "Synchronization Output - "
  257.     If mode.SyncInvert <> 0 Then
  258.         out = out & "INVERTED" & (Chr(13))
  259.     Else
  260.         out = out & "NORMAL" & (Chr(13))
  261.     End If
  262.     MsgBox out, vbOKOnly, "USMC_SetMode Successful"
  263. End Sub
  264.  
  265. Sub PrintDState(state As USMCState)
  266. Dim out As String
  267. With state
  268.     out = "The state is:" & (Chr(13))
  269.     out = out & "- Current Position in microsteps - " & Format(.CurPos) & (Chr(13))
  270.     out = out & "- Temperature - " & Format(.Temp, "0.00") & (Chr(176)) & (Chr(67)) & (Chr(13))
  271.     out = out & "- Step Divisor - " & Format(.SDivisor, "0") & (Chr(13))
  272.     out = out & "- Loft State - "
  273.     If .Loft <> 0 Then
  274.         out = out & "Indefinite" & (Chr(13))
  275.     Else
  276.         out = out & "Fixed" & (Chr(13))
  277.     End If
  278.     out = out & "- Power - "
  279.     If .Power <> 0 Then
  280.         If .FullPower <> 0 Then
  281.             out = out & "Full" & (Chr(13))
  282.         Else
  283.             out = out & "Half" & (Chr(13))
  284.         End If
  285.     Else
  286.         out = out & "Off" & (Chr(13))
  287.     End If
  288.     If .RUN <> 0 Then
  289.         out = out & "- Step Motor is Running in "
  290.         If .CW_CCW <> 0 Then
  291.             out = out & "CCW Direction "
  292.         Else
  293.             out = out & "CW Direction "
  294.         End If
  295.         If (.SDivisor = 1) And (.FullSpeed <> 0) Then
  296.             out = out & "at Full Speed" & (Chr(13))
  297.         Else
  298.             out = out & (Chr(13))
  299.         End If
  300.     Else
  301.         out = out & "- Step Motor is Not Running" & (Chr(13))
  302.     End If
  303.     out = out & "- Device "
  304.     If .AReset <> 0 Then
  305.         out = out & "is After Reset" & (Chr(13))
  306.     Else
  307.         out = out & "Position Already Set" & (Chr(13))
  308.     End If
  309.     out = out & "- Input Synchronization Logical Pin State - "
  310.     If .SyncIN <> 0 Then
  311.         out = out & "TRUE" & (Chr(13))
  312.     Else
  313.         out = out & "FALSE" & (Chr(13))
  314.     End If
  315.     out = out & "- Output Synchronization Logical Pin State - "
  316.     If .SyncOUT <> 0 Then
  317.         out = out & "TRUE" & (Chr(13))
  318.     Else
  319.         out = out & "FALSE" & (Chr(13))
  320.     End If
  321.     out = out & "- Rotary Transducer Logical Pin State - "
  322.     If .RotTr <> 0 Then
  323.         out = out & "TRUE" & (Chr(13))
  324.     Else
  325.         out = out & "FALSE" & (Chr(13))
  326.     End If
  327.     out = out & "- Rotary Transducer Error Flag - "
  328.     If .RotTrErr <> 0 Then
  329.         out = out & "Error" & (Chr(13))
  330.     Else
  331.         out = out & "Clear" & (Chr(13))
  332.     End If
  333.     out = out & "- Emergency Disable Button - "
  334.     If .EmReset <> 0 Then
  335.         out = out & "Pushed" & (Chr(13))
  336.     Else
  337.         out = out & "Unpushed" & (Chr(13))
  338.     End If
  339.     out = out & "- Trailer 1 Press State - "
  340.     If .Trailer1 <> 0 Then
  341.         out = out & "Pushed" & (Chr(13))
  342.     Else
  343.         out = out & "Unpushed" & (Chr(13))
  344.     End If
  345.     out = out & "- Trailer 2 Press State - "
  346.     If .Trailer2 <> 0 Then
  347.         out = out & "Pushed" & (Chr(13))
  348.     Else
  349.         out = out & "Unpushed" & (Chr(13))
  350.     End If
  351.     out = out & "- Input Voltage - "
  352.     If .Voltage = 0 Then
  353.         out = out & "Low" & (Chr(13))
  354.     Else
  355.         out = out & Format(.Voltage, "0.0") & (Chr(13))
  356.     End If
  357.     MsgBox out, vbOKOnly, "USMC_GetState Successful"
  358. End With
  359. End Sub
  360.  
  361. Sub PrintError()
  362.     Dim out As String
  363.     out = String(1000, 0)
  364.     USMCGetLastErr out, 1000
  365.     MsgBox out, vbOKOnly, "Error"
  366. End Sub
  367.  
  368. Sub PrintDStartParameters(DPos As Long, Speed As Single, sp As USMCStartParameters)
  369. With sp
  370.     Dim out As String
  371.     out = "Destination position - " & Format(DPos) & (Chr(13))
  372.     out = out & "Speed - " & Format(Speed, "##.00") & " tacts/s" & (Chr(13))
  373.     out = out & "Steps Divisor - " & Format(.SDivisor, "0") & (Chr(13))
  374.     If .SDivisor = 1 Then
  375.         out = out & "Slow start/stop mode - "
  376.         If .SlStart <> 0 Then
  377.             out = out & "Enabled" & (Chr(13))
  378.         Else
  379.             out = out & "Disabled" & (Chr(13))
  380.         End If
  381.     Else
  382.         out = out & "Automatic backlash operation - "
  383.         If .LoftEn <> 0 Then
  384.             out = out & "Enabled" & (Chr(13))
  385.             out = out & "Automatic backlash operation direction - "
  386.             If .DefDir <> 0 Then
  387.                 out = out & "CCW" & (Chr(13))
  388.             Else
  389.                 out = out & "CW" & (Chr(13))
  390.             End If
  391.             out = out & "Force automatic backlash operation - "
  392.             If .ForceLoft <> 0 Then
  393.                 out = out & "TRUE" & (Chr(13))
  394.             Else
  395.                 out = out & "FALSE" & (Chr(13))
  396.             End If
  397.         Else
  398.             out = out & "Disabled" & (Chr(13))
  399.         End If
  400.     End If
  401.     If .WSyncIN <> 0 Then
  402.         out = out & "Controller will wait for input synchronization signal to start" & (Chr(13))
  403.     Else
  404.         out = out & "Input synchronization signal ignored" & (Chr(13))
  405.     End If
  406.     If .SyncOUTR <> 0 Then
  407.         out = out & "Output synchronization counter will be reset" & (Chr(13))
  408.     Else
  409.         out = out & "Output synchronization counter will not be reset" & (Chr(13))
  410.     End If
  411.    
  412.     MsgBox out, vbOKOnly, "USMC_Start Successful"
  413.  
  414. End With
  415. End Sub
  416.  
  417. Sub PrintDParameters(Parameters As USMCParameters)
  418. With Parameters
  419.     Dim out As String
  420.     out = "The parameters are:" & (Chr(13))
  421.     out = out & "Full acceleration time - " & Format(.AccelT, "###0") & " ms" & (Chr(13))
  422.     out = out & "Full deceleration time - " & Format(.DecelT, "###0") & " ms" & (Chr(13))
  423.     out = out & "Power reduction timeout - " & Format(.PTimeout, "###0") & " ms" & (Chr(13))
  424.     out = out & "Button speedup timeout 1 - " & Format(.BTimeout1, "###0") & " ms" & (Chr(13))
  425.     out = out & "Button speed after timeout 1 - " & Format(.BTO1P, "###0.00") & " steps/s" & (Chr(13))
  426.     out = out & "Button speedup timeout 2 - " & Format(.BTimeout2, "###0") & " ms" & (Chr(13))
  427.     out = out & "Button speed after timeout 2 - " & Format(.BTO2P, "###0.00") & " steps/s" & (Chr(13))
  428.     out = out & "Button speedup timeout 3 - " & Format(.BTimeout3, "###0") & " ms" & (Chr(13))
  429.     out = out & "Button speed after timeout 3 - " & Format(.BTO3P, "###0.00") & " steps/s" & (Chr(13))
  430.     out = out & "Button speedup timeout 4 - " & Format(.BTimeout4, "###0") & " ms" & (Chr(13))
  431.     out = out & "Button speed after timeout 4 - " & Format(.BTO4P, "###0.00") & " steps/s" & (Chr(13))
  432.     out = out & "Button reset timeout - " & Format(.BTimeoutR, "###0") & " ms" & (Chr(13))
  433.     out = out & "Button reset operation speed - " & Format(.MinP, "###0.00") & " steps/s" & (Chr(13))
  434.     out = out & "Backlash operation distance - " & Format(.MaxLoft) & " steps" & (Chr(13))
  435.     out = out & "Revolution distance - " & Format(.RTDelta) & " steps" & (Chr(13))
  436.     out = out & "Minimal revolution distance error - " & Format(.RTMinErr) & " steps" & (Chr(13))
  437.     out = out & "Power off temperature - " & Format(.MaxTemp, "##0.00") & (Chr(176)) & (Chr(67)) & (Chr(13))
  438.     out = out & "Duration of the output synchronization pulse - "
  439.     If .SynOUTP = 0 Then
  440.        out = out & "minimal" & (Chr(13))
  441.     Else
  442.        out = out & Format(.SynOUTP - 0.5, "##0.0") & " * [Tact Period]" & (Chr(13))
  443.     End If
  444.     out = out & "Speed of the last phase of the backlash operation - "
  445.     If .LoftPeriod = 0 Then
  446.        out = out & "normal" & (Chr(13))
  447.     Else
  448.        out = out & Format(.LoftPeriod - 0.5, "###0.00") & " steps/s" & (Chr(13))
  449.     End If
  450.     MsgBox out, vbOKOnly, "USMC_SetParameters Successful"
  451.  
  452. End With
  453. End Sub
  454.