1 Partial Public Module Examples
2 Public Function Record_Position(gclib As Gclib, fileA As String, fileB As String)
3 Dim writerA = New System.IO.StreamWriter(fileA, False)
4 Dim writerB = New System.IO.StreamWriter(fileB, False)
8 gclib.GProgramDownload(
9 "RC 0;' Disable Recording" + vbCr +
10 "DP 0, 0;' Set current position to 0" + vbCr +
11 "DM posA[1000], posB[1000];' Define a new array that will hold positional data" + vbCr +
12 "RA posA[], posB[];' Sets position array to be where recorded data will be stored" + vbCr +
13 "RD _TPA, _TPB;' Defines Position to be the type of data that will be recorded" + vbCr +
14 "RC 1,-1000;' Begins recording at 512Hz in continuous mode" + vbCr +
15 "MO AB;' Turns motors off" + vbCr +
16 "AI -1;' Waits for active low on Input 1" + vbCr +
17 "RC 0;' Disable Recording after Input 1 goes low" + vbCr +
25 Dim leading_comma = False
27 Console.WriteLine("Begin recording")
30 System.Threading.Thread.Sleep(1000) 'Sleep while we wait for roughly half the array to be written
31 rd = gclib.GCmdI("MG _RD") 'Gets address of next value in the position array
33 'Get values from posA[] array and write to file
34 Write_Array_To_File(gclib, writerA, "posA", previous_rd, rd, leading_comma)
36 'Get values from posB[] array and write to file
37 Write_Array_To_File(gclib, writerB, "posB", previous_rd, rd, leading_comma)
41 recording = gclib.GCmdI("MG _RC") 'Check status of RC
45 Loop While recording > 0 'While recording is active
47 Console.WriteLine("End recording")
52 Return Examples.GALIL_EXAMPLE_OK
55 Private Sub Write_Array_To_File(gclib As Gclib, writer As System.IO.StreamWriter, array_name As String, previous_rd As Integer, rd As Integer, leading_comma As Boolean)
56 Dim values = New List(Of Double)
58 If previous_rd < rd Then 'No array wrap around
59 'Grab list of doubles from controller and add it to values
60 values.AddRange(gclib.GArrayUpload(array_name, previous_rd, rd - 1))
62 'Grab list of doubles from controller and add it to values
63 values.AddRange(gclib.GArrayUpload(array_name, previous_rd, 999))
66 'Grab list of doubles from controller and add it to values
67 values.AddRange(gclib.GArrayUpload(array_name, 0, rd - 1))
71 For i = 0 To values.Count() - 1
78 writer.Write(String.Format("{0:0.000}", values(i)))