-
Notifications
You must be signed in to change notification settings - Fork 1
/
ubi_2.4.vb
7315 lines (5695 loc) · 299 KB
/
ubi_2.4.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports System.Windows.Forms
Imports System.Drawing
Imports Microsoft.VisualBasic.Compatibility
Imports ZedGraph
Imports System.IO
Friend Class DMK_v1
Inherits System.Windows.Forms.Form ' must be first (stupid VB...)
Dim invert_raw As Integer = 1 'placve -1 here to invert the raw data (i.e. raw data will be multipolied by this)
Dim version As String = "Jan_21_2018_AK"
Dim plot_data_point As Integer = True
Dim program_directory As String = Environment.CurrentDirectory
'Dim library_directory As String = program_directory & "\lib\"
Dim rootdata_directory As String = program_directory & "\rootdata\"
Dim Gain_Volts(2, 4, 10) As Single
Dim Baseline_Y(5000) As Single
Dim Auto_File_Name As String
Dim auto_run As Integer = False
Const Blue_Filter As Short = 110
Const IR_Filter As Short = 165
Dim Halt_Script As Short
Dim Script() As String
Dim record_files As Boolean = False
Dim Script_Counter As Short
Dim C_Script As String
Public Graph_Name() As String = {"0", "1", "2", "3", "4", "5", "6"}
Dim fluorescence_shutter_status As Integer
Dim Shutter_delay As Integer = 1.6
Const BoardNum As Short = 0 ' Board number
Dim Trace_protocol() As Integer = {0, 0, 0} ' associates a protocol to a trace, such that the trace will automatically pick it's protocol when m_trace is called (deprecated)
Dim Xe_intensity_value As Single
Dim M_Primary_Gain(,) As Short = {{0, 0, 0}, {0, 0, 0}}
Dim M_Reference_Gain(,) As Short = {{0, 0, 0}, {0, 0, 0}}
Dim m_set_auto_gain(,) As Short = {{0, 0, 0}, {0, 0, 0}}
Dim m_take_data(,) As Integer
Dim Pre_Delay(,) As String = {{"0", "0", "0"}, {"0", "0", "0"}}
Dim script_file As String
Dim s_Plot_File_Name(10) As String
Dim ref_mode As Integer
Dim s_Plot_File_Type(10) As Integer
Dim D_Out_Mask As Integer
Dim laser As Integer = 0
Dim Current_Wheel_Position As Single
Dim view_laser As Integer
Dim servo_position(8, 30) As Integer
Dim current_servo, number_servo_positions, current_servo_position As Integer
Dim sub_name As String
Dim Sub_Return_Pointer(36) As Integer 'where to return after a subroutine
Dim Sub_Return_Level As Integer
Dim number_variables As Integer
Dim user_variable(100, 100) As String
Dim user_variable_name(1000) As String
Dim user_variable_index(100) As Integer
Dim Base_File_Name, Base_Base_File_Name As String
Dim run_another_script As Integer = False
Dim dice_length As Integer
Dim take_notes As Integer
Dim stir_status As Integer = 0
Dim Current_Trace As Short
Dim pre_pulse_light As Short
Dim Max_Number_Lights As Integer = 32
'from pblast"
Dim stemp As Single
'Dim Count_time_num$
Dim temp1 As Short
Dim temp2 As Short
Dim temp3 As Short
Dim PB_multiplier As Single
Dim PB_freq As Double
Dim PB_Numm As Object
Dim PB_pulselen As Single
Dim ptb1, ptb0, ptb2 As Short 'changed from object
Dim ptb3 As Short
Dim PB_cycles As Double
Dim pb_flags As Integer
Dim tempi As Integer
Dim ccc(10) As Integer
Dim tttemp As Short
Dim PBStatt As Integer
Dim pb_port As Short
Dim max_measuring_pulse_duration As Single = 0.0002
Dim nmp As Integer
Dim new_firgelli As Integer = False
Dim gain_slop As Single = 8.0
Dim number_of_channels_to_scan As Integer
Dim cblaster As New ChrisBlasterIO("Nexys2") ' object for communicating and using the ChrisBlaster FPGA board
Dim protocol_menu() As Protocol
' Saturation Pulse button protocol
Dim saturation_test As Protocol
'Dim geoffs_detector_position As Integer = -9999
'Dim absorbance_target_position As Integer = 4300
'Dim fluorescence_target_position As Integer = 2900
'Dim df_target_position As Integer = 1500
'Dim WithEvents sp As New SerialPort
Dim spec_mode As Integer = False 'False
Dim start_lambda As Single = 525
Dim delta_lambda As Single = 1
Dim mono_BoardNum As Integer = 1 ' 1608fs board for monochromator control
Dim mono_D_Out_Mask As Integer = 0 'mask for the digital IO for the monochromator board
Dim steps_per_nanometer As Single = 96 / 5
Dim current_lambda As Single 'holds the value of the current monochromator position
Dim x_mode As Integer = 0
Dim list_of_base_additions As New System.Collections.Generic.List(Of String)
Public Sub dmkversion1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'This sub places a default image in the pictureboxes to populate the pixels
Dim XSize As Integer = 320
Dim YSize As Integer = 240
'Dim MyPic As String = "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\hangar1.jpg"
'Dim MyImage As New Bitmap(MyPic)
'Dim s_Plot_File_name(10) As String
' Stretches the image to fit the pictureBoxes.
Dim i As Integer
For i = 1 To 6
Graph_Name(i) = "GRAPH: " & i
Next i
movelin.Visible = True
' Button8.Visible = False
' Button9.Visible = False
' TrackBar1.Visible = False
' Label6.Visible = False
view_laser = False
'set up variable to hold autogain stuff
'iv = VB.Len(Script(Script_Counter)) - 1
' number_variables = 1
' user_variable_name(number_variables) = "auto_gain"
' user_variable_index(number_variables) = 1
' Jabber_jabber.List1.Items.Add(user_variable_name(number_variables))
'this is for the monochromator on Charley
'Dim BaudRates() As String = {"300", "1200", "2400", "4800", "9600", "14400", "19200", "28800", "38400", "57600", "115200"}
'cmbBaud.Items.AddRange(BaudRates)
'cmbBaud.SelectedIndex = 4
'Try
' GetSerialPortNames()
' cmbPort.SelectedIndex = 0
' Catch
' MsgBox("No ports connected.")
' End Try
Jabber_jabber.Show()
'jabber_box.
Jabber_jabber.List1.Items.Add("Hello!")
End Sub
Private Sub parsenum(ByRef num As String)
'back up copy of code inserted into Private Sub P_blast
Freq = 10 ^ 8
pulselen = 1 / Freq
StdDelay = 5 'standard 5 cycle delay with this board (or 50 nsec)
num = Trim(num)
If VB.Right(num, 1) = "u" Then
multiplier = 0.000001
ElseIf VB.Right(num, 1) = "m" Then
multiplier = 0.001
ElseIf VB.Right(num, 1) = "n" Then
multiplier = 0.000000001
Else
multiplier = 1
End If
'seconds = multiplier * numm
numm = Val(num)
Time_Interval_in_Seconds = numm * multiplier
'DMK_v1.List1.AddItem "n " & num$ & " TIS " & Time_Interval_in_Seconds & " m " & multiplier
System.Windows.Forms.Application.DoEvents()
cycles = Int(multiplier * numm / pulselen) - StdDelay
'DMK_v1.List1.AddItem "cycles " & cycles
System.Windows.Forms.Application.DoEvents()
ptb0 = cycles And &HFFS
cycles = (cycles - ptb0) / 256
ptb1 = cycles And &HFFS
cycles = (cycles - ptb1) / 256
ptb2 = cycles And &HFFS
cycles = (cycles - ptb2) / 256
ptb3 = cycles And &HFFS
'DMK_v1.List1.AddItem "0: " & ptb0 & " 1: " & ptb1 & " 2: " & ptb2 & " 3: " & ptb3
End Sub
Private Sub SaveToChrisBlaster(ByRef Current_Protocol As Short, ByVal memory_index As Integer, ByRef Number_Loops() As Short, _
ByRef Intensity(,) As Short, ByRef Number_Pulses(,) As Short, ByRef Number_Measuring_Lights() As Short, _
ByRef Measuring_Light(,) As Short, ByRef Choke_actinic(,) As Short, ByRef Measuring_Interval(,,) As String, _
ByRef Primary_Gain(,) As Short, ByRef reference_gain(,) As Short, ByRef Measuring_Pulse_Duration(,) As String, _
ByRef Gain() As Integer, ByRef In_Channel() As Short, _
ByRef Ref_channel_number() As Short, _
ByRef points As Integer, ByRef data_time() As Single, _
ByRef Xe_Flash(,) As Short, ByRef q_switch(,) As Short, ByVal M_Far_Red(,) As Short, _
ByVal M_Blue_actinic(,) As Short, ByVal pre_pulse(,) As Short, ByVal pre_pulse_time(,) As String, _
ByVal Pre_Delay(,) As String, ByVal m_take_data(,) As Short)
'Dim ulstat As Short
Dim PP_Line As Short = 0
'Dim i, j As Object
Dim i As Object
'Dim ii As Integer
'Dim k As Short
'Dim AD_Trigger As Short
Dim Loop_Return_Index() As Short
'Dim Options As Integer
'Dim ss As Short
'Dim CurCount, CurIndex As Integer
Dim Time_Accumulator As Single = 0
Dim Measuring_Pulse_Number As Integer = 0
'Dim Timed_Out As Short
Dim Time_Out_Time As Single = 1
Dim Each_Measuring_Pulse_Interval() As Single
Dim Current_Measuring_Point As Integer = 0
'Dim Give_Saturating_Pulse As Short
'Dim SH_State As Integer
ReDim Loop_Return_Index(Number_Loops(Current_Protocol))
ReDim Each_Measuring_Pulse_Interval(Number_Measuring_Lights(Current_Protocol))
'Dim pbstat As Integer
points = 0
For i = 1 To Number_Loops(Current_Protocol)
If m_take_data(Current_Protocol, i) > 0 Then
points = points + (Number_Measuring_Lights(Current_Protocol) * Number_Pulses(Current_Protocol, i))
End If
Next i
Dim expected_run_time As Double
' Use the ChrisBlaster to run the protocol
Dim program As Protocol = New Protocol()
' The protocol object holds all of the relevent values of a protocol in one easy package for use by the ChrisBlasterIO object
' to handle the nuts & bolts of programming the hardware
program.Adc_Gain = Gain(Current_Protocol)
'program.Baseline_End =
'program.Baseline_Start =
program.In_Channel = In_Channel(Current_Protocol)
program.laser = laser
For n_light As Integer = 1 To Number_Measuring_Lights(Current_Protocol)
'program.Measuring_Pulse_Duration(n_light) = Measuring_Pulse_Duration(Current_Protocol, n_light)
Next
program.Number_Loops = Number_Loops(Current_Protocol)
program.Number_Measuring_Lights = Number_Measuring_Lights(Current_Protocol)
program.pre_pulse_light = pre_pulse_light
program.Ref_Channel = Ref_channel_number(Current_Protocol)
program.Xe_intensity_value = Xe_intensity_value
For loopindex As Integer = 0 To Number_Loops(Current_Protocol) - 1 ' VB for loops don't work the same as Java, C#, C, or C++ for loops
program.Blue_Actinic(loopindex) = M_Blue_actinic(Current_Protocol, loopindex + 1)
program.Far_Red(loopindex) = M_Far_Red(Current_Protocol, loopindex + 1)
program.Intensity(loopindex) = Intensity(Current_Protocol, loopindex + 1)
program.Number_Pulses(loopindex) = Number_Pulses(Current_Protocol, loopindex + 1)
program.Pre_Delay(loopindex) = Pre_Delay(Current_Protocol, loopindex + 1)
program.Pre_Pulse(loopindex) = pre_pulse(Current_Protocol, loopindex + 1)
program.Pre_Pulse_Time(loopindex) = pre_pulse_time(Current_Protocol, loopindex + 1)
'program.Saturating_Pulse(loopindex) =
'program.choke_actinic(loopindex) = m_choke_actinic(Current_Protocol, loopindex + 1)
program.Take_Data(loopindex) = m_take_data(Current_Protocol, loopindex + 1)
program.Xe_Flash(loopindex) = Xe_Flash(Current_Protocol, loopindex + 1)
' update expected_run_time
If program.Pre_Delay(loopindex) <> "" Then expected_run_time = expected_run_time + Protocol.TimeInSeconds(program.Pre_Delay(loopindex))
If program.Pre_Pulse_Time(loopindex) <> "" Then expected_run_time = expected_run_time + Protocol.TimeInSeconds(program.Pre_Pulse_Time(loopindex))
For lightindex As Integer = 0 To Number_Measuring_Lights(Current_Protocol) - 1
program.Measuring_Interval(lightindex, loopindex) = Measuring_Interval(Current_Protocol, lightindex + 1, loopindex + 1)
program.Measuring_Light(lightindex) = Measuring_Light(Current_Protocol, lightindex + 1)
program.choke_actinic(lightindex) = Measuring_Light(Current_Protocol, lightindex + 1)
program.Primary_Gain(lightindex) = Primary_Gain(Current_Protocol, lightindex + 1)
program.Reference_Gain(lightindex) = reference_gain(Current_Protocol, lightindex + 1)
expected_run_time = expected_run_time + _
(Protocol.TimeInSeconds(program.Measuring_Interval(lightindex, loopindex)) _
* program.Number_Pulses(loopindex)) + _
Protocol.TimeInSeconds("20u")
Next lightindex
Next loopindex
Dim data_time_in_doubles(-1) As Double
Dim programed_successfully As Boolean = cblaster.ProgramProtocol(memory_index, program, data_time_in_doubles)
If Not programed_successfully Then
System.Windows.Forms.MessageBox.Show("There was an error while programming protocol " & Current_Protocol & " to the ChrisBlaster (memory address " & memory_index & ").", _
"Error!")
System.Windows.Forms.Application.DoEvents()
End If
End Sub
Private Sub Multi_Trace_from_FPGA(ByRef Current_Protocol As Short, ByVal memory_index As Integer, _
ByRef Number_Loops() As Short, ByRef Intensity(,) As Short, ByRef Number_Pulses(,) As Short, _
ByRef Number_Measuring_Lights() As Short, ByRef Measuring_Light(,) As Short, ByRef Choke_Actinic(,) As Short, _
ByRef Measuring_Interval(,,) As String, ByRef Primary_Gain(,) As Short, ByRef reference_gain(,) As Short, _
ByRef Measuring_Pulse_Duration(,) As String, ByRef Gain() As Integer, ByRef In_Channel() As Short, ByRef Ref_Channel_Number() As Short, _
ByRef points As Integer, _
ByRef data_time() As Single, ByRef Xe_Flash(,) As Short, ByRef q_switch(,) As Short, ByVal M_Far_Red(,) As Short, _
ByVal M_Blue_actinic(,) As Short, ByVal pre_pulse(,) As Short, ByVal pre_pulse_time(,) As String, _
ByVal Pre_Delay(,) As String, ByVal m_take_data(,) As Short)
'Dim ulstat As Short
'Dim Start_of_Wait, end_of_wait As Single
''ulstat = cbDOut(BoardNum, AUXPORT, 0)
'Trace_Running = True
''Dim Time_In_S As Single
'Dim PP_Line As Short = 0
''Dim i, j As Object
'Dim i As Object
'Dim ii As Integer
''Dim k As Short
''Dim AD_Trigger As Short
'Dim Loop_Return_Index() As Short
''Dim Points&
'Dim CBRate As Integer = 50000
'Dim CBCount As Integer
'Dim LowChan, HighChan As Short
'Dim Options As Integer
''Dim ulstat%
'Dim ss As Short
'Dim CurCount, CurIndex As Integer
'Dim Time_Accumulator As Single = 0
'Dim Measuring_Pulse_Number As Integer = 0
'Dim Timed_Out As Short
'Dim Time_Out_Time As Single = 1
'Dim Each_Measuring_Pulse_Interval() As Single
'Dim Current_Measuring_Point As Integer = 0
''Dim Give_Saturating_Pulse As Short
'Dim SH_State As Integer
''Dim TTT1, TTT2 As Single
'Dim Raw_Data() As Short
'ReDim Loop_Return_Index(Number_Loops(Current_Protocol))
'ReDim Each_Measuring_Pulse_Interval(Number_Measuring_Lights(Current_Protocol))
''Dim pbstat As Integer
'points = 0
'For i = 1 To Number_Loops(Current_Protocol)
' If m_take_data(Current_Protocol, i) > 0 Then
' points = points + (Number_Measuring_Lights(Current_Protocol) * Number_Pulses(Current_Protocol, i))
' Else
' List1.Items.Add("skip data collection found at loop " + Str(i))
' End If
'Next i
'ReDim data_time(points * 4 + 10)
'ReDim Data_Volts(points + 10, 4)
'ReDim Ref_Data_Volts(points * 4 + 10)
'ReDim Raw_Data(points * 4 + 10) ' dimension an array to hold the input values
'Start_of_Wait = VB.Timer()
''Dim time_temp As String
'' insert a 1 s delay
'SH_State = 0 'hold mode
'ProgressBar1.Value = Primary_Gain(Current_Protocol, 1)
'sample_gain_label.Text = Primary_Gain(Current_Protocol, 1)
'ProgressBar2.Value = reference_gain(Current_Protocol, 1)
'reference_gain_label.Text = reference_gain(Current_Protocol, 1)
'ProgressBar3.Value = Intensity(Current_Protocol, 1)
'actinic_label.Text = Intensity(Current_Protocol, 1)
'Dim expected_run_time As Double = 0 ' This variable keeps track of how long to wait for a protocol to finish (used to detect time-out errors)
'' Use the ChrisBlaster to run the protocol
'Dim program As Protocol = New Protocol()
'' The protocol object holds all of the relevent values of a protocol in one easy package for use by the ChrisBlasterIO object
'' to handle the nuts & bolts of programming the hardware
'program.Adc_Gain = Gain
''program.Baseline_End =
''program.Baseline_Start =
'program.In_Channel = In_Channel
'program.laser = laser
'For n_light As Integer = 1 To Number_Measuring_Lights(Current_Protocol)
' program.Measuring_Pulse_Duration(n_light) = Measuring_Pulse_Duration(Current_Protocol, n_light)
'Next n_light
'program.Number_Loops = Number_Loops(Current_Protocol)
'program.Number_Measuring_Lights = Number_Measuring_Lights(Current_Protocol)
'program.pre_pulse_light = pre_pulse_light
'program.Ref_Channel = use_ref_channel
'program.Xe_intensity_value = Xe_intensity_value
'For loopindex As Integer = 0 To Number_Loops(Current_Protocol) - 1 ' VB for loops don't work the same as Java, C#, C, or C++ for loops
' program.Blue_Actinic(loopindex) = M_Blue_actinic(Current_Protocol, loopindex + 1)
' program.Far_Red(loopindex) = M_Far_Red(Current_Protocol, loopindex + 1)
' program.Intensity(loopindex) = Intensity(Current_Protocol, loopindex + 1)
' program.Number_Pulses(loopindex) = Number_Pulses(Current_Protocol, loopindex + 1)
' program.Pre_Delay(loopindex) = Pre_Delay(Current_Protocol, loopindex + 1)
' program.Pre_Pulse(loopindex) = pre_pulse(Current_Protocol, loopindex + 1)
' program.Pre_Pulse_Time(loopindex) = pre_pulse_time(Current_Protocol, loopindex + 1)
' 'program.Saturating_Pulse(loopindex) =
' program.Take_Data(loopindex) = m_take_data(Current_Protocol, loopindex + 1)
' program.Xe_Flash(loopindex) = Xe_Flash(Current_Protocol, loopindex + 1)
' ' update expected_run_time
' If program.Pre_Delay(loopindex) <> "" Then expected_run_time = expected_run_time + Protocol.TimeInSeconds(program.Pre_Delay(loopindex))
' If program.Pre_Pulse_Time(loopindex) <> "" Then expected_run_time = expected_run_time + Protocol.TimeInSeconds(program.Pre_Pulse_Time(loopindex))
' For lightindex As Integer = 0 To Number_Measuring_Lights(Current_Protocol) - 1
' program.Measuring_Interval(lightindex, loopindex) = Measuring_Interval(Current_Protocol, lightindex + 1, loopindex + 1)
' program.Measuring_Light(lightindex) = Measuring_Light(Current_Protocol, lightindex + 1)
' program.choke_actinic(lightindex) = Choke_Actinic(Current_Protocol, lightindex + 1)
' program.Primary_Gain(lightindex) = Primary_Gain(Current_Protocol, lightindex + 1)
' program.Reference_Gain(lightindex) = reference_gain(Current_Protocol, lightindex + 1)
' expected_run_time = expected_run_time + _
' (Protocol.TimeInSeconds(program.Measuring_Interval(lightindex, loopindex)) _
' * program.Number_Pulses(loopindex)) + _
' Protocol.TimeInSeconds("20u")
' Next lightindex
'Next loopindex
'Dim data_time_in_doubles(-1) As Double
'data_time_in_doubles = cblaster.GenerateTimeMap(program)
'ReDim data_time(data_time_in_doubles.Length)
'For t As Integer = 0 To data_time_in_doubles.Length - 1
' data_time(t) = Convert.ToSingle(data_time_in_doubles(t))
'Next
'Time_Out_Time = 2 * data_time(data_time.Length - 2) ' time point of last data point
''Midnight bug fix:
'Dim time_now As Double = VB.Timer
'If (time_now < Start_of_Wait) Then
' end_of_wait = Start_of_Wait - time_now - (24 * 60 * 60) ' midnight adjusted code
'Else
' end_of_wait = Start_of_Wait - VB.Timer() ' original code
'End If
''List1.AddItem "points:" & Str$(Points&)
''************************
'' Collect the values with cbAInScan%()
'' Parameters:
'' BoardNum% :the number used by CB.CFG to describe this board
'' LowChan% :the first channel of the scan
'' HighChan% :the last channel of the scan
'' CBCount& :the total number of A/D samples to collect
'' CBRate& :sample rate
'' Gain :the gain for the board
'' ADData% :the array for the collected data values
'' Options :data collection options
'Time_Out_Time = Time_Out_Time * 5
''CBRate = 3 ' sampling rate (samples per second)
'LowChan = 0 'In_Channel '0 ' first channel to acquire
'HighChan = 3 'In_Channel ' 0 ' last channel to acquire
'number_of_channels_to_scan = HighChan - LowChan ' used later in data analyses
'Const FirstPoint As Integer = 0 ' set first element in buffer to transfer to array
'' total number of data points to collect
'CBCount = points * number_of_channels_to_scan 'highchannel-lowchannel
''If points > 10000 Then
'MemHandle = cbWinBufAlloc(points * number_of_channels_to_scan + 10) ' set aside memory to hold data
''End If
'' MemHandle = cbWinBufAlloc(CBCount) ' set aside memory to hold data
'ulstat = cbSetTrigger(BoardNum, TRIGPOSEDGE, 0, 0.5) 'changes high from 1 to 2
''Options = EXTTRIGGER + BACKGROUND + NOCONVERTDATA '+ SINGLEIO
'Options = EXTCLOCK + BACKGROUND + NOCONVERTDATA '+ SINGLEIO
'' return data as 16-bit values
'' collect data in BACKGROUND mode
'' use NOCONVERTDATA if using 16 bit board
'' List1.Items.Add(" trace started")
'System.Windows.Forms.Application.DoEvents()
'If MemHandle = 0 Then Stop ' check that a handle to a memory buffer exists
'ulstat = cbAInScan(BoardNum, LowChan, HighChan, CBCount, CBRate, Gain, MemHandle, Options)
''Call Hold_on_There(3)
''Call outt(BaseAddress + 6, 0) 'not needed for this version of PB?
''Call outt(BaseAddress + 7, 0) '7)
''put the device in run mode
''Call outt(BaseAddress + 1, 0) '7)
'If (Not cblaster.StartRunningProtocol(memory_index)) Then
' System.Windows.Forms.MessageBox.Show("Protocol " & Current_Protocol & " from memory index " & memory_index & " failed to run or timed out.")
' System.Windows.Forms.Application.DoEvents()
'End If
'ulstat = cbGetStatus(BoardNum, ss, CurCount, CurIndex, AIFUNCTION)
'Timed_Out = False
'Time_Out_Time = VB.Timer() + Time_Out_Time
''Midnight bug fix:
'' First, find the correct ending wait time
'Dim midnight_mark As Boolean = False
'If (Time_Out_Time > (24 * 60 * 60)) Then
' Time_Out_Time = Time_Out_Time - (24 * 60 * 60)
' midnight_mark = True ' tell following code not to trigger "timed out" until after midnight
'End If
'Label13.Text = CurCount & " / " & CBCount
'While CurCount < CBCount And Timed_Out = False
' If (VB.Timer() > Time_Out_Time And midnight_mark = False) Then Timed_Out = True ' don't time-out before midnight
' If (midnight_mark = True And VB.Timer() < 60) Then midnight_mark = False ' indicate that midnight has passed
' System.Windows.Forms.Application.DoEvents()
' ulstat = cbGetStatus(BoardNum, ss, CurCount, CurIndex, AIFUNCTION)
' Label13.Text = CurCount & " / " & CBCount
' 'System.Windows.Forms.Application.DoEvents()
'End While
'Label3.Text = CurCount & " * " & CBCount
'System.Windows.Forms.Application.DoEvents()
''List1.Items.Add(CBCount & "CC:" & CurCount)
''ulstat = cbDOut(BoardNum, AUXPORT, &HFFS)
'If Timed_Out = True Then
' ulstat = cbStopBackground(BoardNum, AIFUNCTION)
' System.Windows.Forms.MessageBox.Show("Timed out!")
' System.Windows.Forms.Application.DoEvents()
'Else
' List1.Items.Add(" trace done")
' 'Scrolling text box fix: make the box jump to the bottom after adding an item
' List1.TopIndex = List1.Items.Count - 1
'End If
'ulstat = cbStopBackground(BoardNum, AIFUNCTION) 'clears variables and flags after normal termination
''Transfer the data from the memory buffer set up by Windows to an array for use by Visual Basic
'ulstat = cbWinBufToArray(MemHandle, Raw_Data(0), FirstPoint, CBCount)
''If ulstat% <> 0 Then Stop
'' convert RAW data into VOLTS
'' For i = 0 To (points - 1) * 2 Step 2
'' ulstat = cbToEngUnits(BoardNum, Gain, Raw_Data(i), TTT1)
''ulstat = cbToEngUnits(BoardNum, Gain, Raw_Data(i + 1), TTT2)
''Data_Volts(i / 2) = (TTT1 / TTT2)
''Next i
'' Data_Volts is zero-indexed
'' Raw_Data is zero_indexed
'For i = 0 To (points - 1)
' For ii = 0 To number_of_channels_to_scan - 1 'this change may allow us to scan more than 4 channels
' ulstat = cbToEngUnits(BoardNum, Gain, Raw_Data((i * 4) + ii), Data_Volts(i, ii))
' Next ii
'Next i
'Trace_Running = False
End Sub
Private Sub Multi_Trace(ByRef Current_Protocol As Short, ByRef Number_Loops() As Short, ByRef Intensity(,) _
As Short, ByRef Number_Pulses(,) As Short, ByRef Number_Measuring_Lights() As Short, _
ByRef Measuring_Light(,) As Short, ByRef choke_actinic(,) As Short, ByRef Measuring_Interval(,,) As String, _
ByRef Primary_Gain(,) As Short, ByRef reference_gain(,) As Short, ByRef Measuring_Pulse_Duration(,) As String, _
ByRef Gain() As Integer, ByRef In_Channel() As Short, ByRef Ref_channel_number() As Short, ByRef points As Integer, ByRef data_time() As Single, _
ByRef Xe_Flash(,) As Short, ByRef q_switch(,) As Short, ByVal M_Far_Red(,) As Short, ByVal M_Blue_actinic(,) _
As Short, ByVal pre_pulse(,) As Short, ByVal pre_pulse_time(,) As String, ByVal Pre_Delay(,) As String, _
ByVal m_take_data(,) As Short)
halt.Enabled = True
Dim ulstat As Short
Dim Start_of_Wait, end_of_wait As Single
'ulstat = cbDOut(BoardNum, AUXPORT, 0)
Trace_Running = True
'Dim Time_In_S As Single
Dim PP_Line As Short = 0
'Dim i, j As Object
Dim i As Object
Dim ii As Integer
'Dim k As Short
'Dim AD_Trigger As Short
Dim Loop_Return_Index() As Short
'Dim Points&
Dim CBRate As Integer = 50000
Dim CBCount As Integer
Dim LowChan, HighChan As Short
Dim Options As Integer
'Dim ulstat%
Dim ss As Short
Dim CurCount, CurIndex As Integer
Dim Time_Accumulator As Single = 0
Dim Measuring_Pulse_Number As Integer = 0
Dim Timed_Out As Short
Dim Time_Out_Time As Single = 1
Dim Each_Measuring_Pulse_Interval() As Single
Dim Current_Measuring_Point As Integer = 0
'Dim Give_Saturating_Pulse As Short
Dim SH_State As Integer
'Dim TTT1, TTT2 As Single
Dim Raw_Data() As Short
ReDim Loop_Return_Index(Number_Loops(Current_Protocol))
ReDim Each_Measuring_Pulse_Interval(Number_Measuring_Lights(Current_Protocol))
'Dim pbstat As Integer
Dim tt As Integer = m_take_data.Length()
points = 0
For i = 1 To Number_Loops(Current_Protocol)
If m_take_data(Current_Protocol, i) > 0 Then
points = points + (Number_Measuring_Lights(Current_Protocol) * Number_Pulses(Current_Protocol, i))
End If
Next i
'List1.Items.Add("protocol: " + Str(Current_Protocol) + " points = " + Str(points))
LowChan = 0 'In_Channel '0 ' first channel to acquire
HighChan = 3 'In_Channel ' 0 ' last channel to acquire
number_of_channels_to_scan = HighChan - LowChan + 1 ' used later in data analyses
ReDim data_time(points * number_of_channels_to_scan + 10)
ReDim Data_Volts(points + 10, number_of_channels_to_scan)
ReDim Ref_Data_Volts(points * number_of_channels_to_scan + 10)
ReDim Raw_Data(points * number_of_channels_to_scan + 10) ' dimension an array to hold the input values
Start_of_Wait = VB.Timer()
'Dim time_temp As String
' insert a 1 s delay
SH_State = 0 'hold mode
ProgressBar1.Value = Primary_Gain(Current_Protocol, 1)
sample_gain_label.Text = Primary_Gain(Current_Protocol, 1)
ProgressBar2.Value = reference_gain(Current_Protocol, 1)
reference_gain_label.Text = reference_gain(Current_Protocol, 1)
ProgressBar3.Value = Intensity(Current_Protocol, 1)
actinic_label.Text = Intensity(Current_Protocol, 1)
Dim ix As Short
'Jabber_jabber.gain_data_list.Items.Add("after: ")
'For ix = 1 To M_Number_Measuring_Lights(Current_Protocol)
' Jabber_jabber.gain_data_list.Items.Add(m_Primary_Gain(Current_Protocol, ix))
'Next
'For ix = 1 To m_Number_Measuring_Lights(Current_Protocol)
' Jabber_jabber.gain_data_list.Items.Add(m_reference_gain(Current_Protocol, ix))
'Next
Dim expected_run_time As Double = 0 ' This variable keeps track of how long to wait for a protocol to finish (used to detect time-out errors)
' Use the ChrisBlaster to run the protocol
Dim program As Protocol = New Protocol()
' The protocol object holds all of the relevent values of a protocol in one easy package for use by the ChrisBlasterIO object
' to handle the nuts & bolts of programming the hardware
program.Adc_Gain = Gain(Current_Protocol)
'program.Baseline_End =
'program.Baseline_Start =
program.In_Channel = In_Channel(Current_Protocol)
program.Ref_Channel = Ref_channel_number(Current_Protocol)
program.laser = laser
program.Number_Measuring_Lights = Number_Measuring_Lights(Current_Protocol)
For n_light As Integer = 1 To Number_Measuring_Lights(Current_Protocol)
'PROBLEM idemntified:
' when using nLIGHTS>5 crashes. Most likely caused by FUd 1 versus 0 indexing
' Note: I figured this out once, and it seems to be in the Measuring_Pulse_Duration
'DMK_update: program.Measuring_Pulse_Duration(n_light - 1) = Measuring_Pulse_Duration(Current_Protocol, n_light)
'a possible problem! changed program.Measuring_Pulse_Duration(n_light) to program.Measuring_Pulse_Duration(n_light - 1)
'Note: program.Measuring_Pulse_Duration is zero-indexed, Measuring_Pulse_Duration(Current_Protocol, n_light) is 1-indexed!!
' I thus changed to offset the index when transferring the values into the
' object by subtracting one from the index program.Measuring_Pulse_Duration(n_light - 1)
program.Measuring_Pulse_Duration(n_light - 1) = Measuring_Pulse_Duration(Current_Protocol, n_light) 'a possible problem! changed program.Measuring_Pulse_Duration(n_light) to program.Measuring_Pulse_Duration(n_light - 1)
Next
program.Number_Loops = Number_Loops(Current_Protocol)
program.pre_pulse_light = pre_pulse_light
program.Xe_intensity_value = Xe_intensity_value
'@@
For loopindex As Integer = 0 To Number_Loops(Current_Protocol) - 1 ' VB for loops don't work the same as Java, C#, C, or C++ for loops
program.Blue_Actinic(loopindex) = M_Blue_actinic(Current_Protocol, loopindex + 1)
program.Far_Red(loopindex) = M_Far_Red(Current_Protocol, loopindex + 1)
program.Intensity(loopindex) = Intensity(Current_Protocol, loopindex + 1)
program.Number_Pulses(loopindex) = Number_Pulses(Current_Protocol, loopindex + 1)
program.Pre_Delay(loopindex) = Pre_Delay(Current_Protocol, loopindex + 1)
program.Pre_Pulse(loopindex) = pre_pulse(Current_Protocol, loopindex + 1)
program.Pre_Pulse_Time(loopindex) = pre_pulse_time(Current_Protocol, loopindex + 1)
'program.Saturating_Pulse(loopindex) =
program.Take_Data(loopindex) = m_take_data(Current_Protocol, loopindex + 1)
program.Xe_Flash(loopindex) = Xe_Flash(Current_Protocol, loopindex + 1)
' update expected_run_time
If program.Pre_Delay(loopindex) <> "" Then expected_run_time = expected_run_time + Protocol.TimeInSeconds(program.Pre_Delay(loopindex))
If program.Pre_Pulse_Time(loopindex) <> "" Then expected_run_time = expected_run_time + Protocol.TimeInSeconds(program.Pre_Pulse_Time(loopindex))
For lightindex As Integer = 0 To Number_Measuring_Lights(Current_Protocol) - 1
program.Measuring_Interval(lightindex, loopindex) = Measuring_Interval(Current_Protocol, lightindex + 1, loopindex + 1)
program.Measuring_Light(lightindex) = Measuring_Light(Current_Protocol, lightindex + 1)
program.choke_actinic(lightindex) = choke_actinic(Current_Protocol, lightindex + 1)
program.Primary_Gain(lightindex) = Primary_Gain(Current_Protocol, lightindex + 1)
'gain_data_list.Items.Add(" !!pg: " + Str(Primary_Gain(Current_Protocol, lightindex + 1)))
program.Reference_Gain(lightindex) = reference_gain(Current_Protocol, lightindex + 1)
expected_run_time = expected_run_time + _
(Protocol.TimeInSeconds(program.Measuring_Interval(lightindex, loopindex)) _
* program.Number_Pulses(loopindex)) + _
Protocol.TimeInSeconds("20u")
'Jabber_jabber.List1.Items.Add("protocol: " + Str(Current_Protocol) + "%%%: " + program.Measuring_Pulse_Duration(lightindex)) ' + " " + Str(program.Measuring_Light(lightindex)) + " " + Str(program.choke_actinic(lightindex)) + " " + Str(program.Primary_Gain(lightindex)) + " " + Str(program.Reference_Gain(lightindex)))
Next lightindex
Next loopindex
'Jabber_jabber.List1.Items.Add("expected run time= " + Str(expected_run_time))
Dim data_time_in_doubles(-1) As Double
'*****************************************this is where the cblaster is programmed************************************
Dim programed_successfully As Boolean = cblaster.ProgramProtocol(Current_Protocol, program, data_time_in_doubles)
'*****************************************above is where the cblaster is programmed************************************
If programed_successfully Then
ReDim data_time(data_time_in_doubles.Length)
For t As Integer = 0 To data_time_in_doubles.Length - 1
data_time(t) = Convert.ToSingle(data_time_in_doubles(t))
Next
End If
Jabber_jabber.List1.Items.Add(" trace started")
Time_Out_Time = 2 * data_time(data_time.Length - 2) + 0.1 ' time point of last data point and multiple by 2 for good measure
'Jabber_jabber.List1.Items.Add("Time_Out_Time = " + Str(Time_Out_Time))
'Midnight bug fix:
Dim time_now As Double = VB.Timer
If (time_now < Start_of_Wait) Then
end_of_wait = Start_of_Wait - time_now - (24 * 60 * 60) ' midnight adjusted code
Else
end_of_wait = Start_of_Wait - VB.Timer() ' original code
End If
'Call outt(BaseAddress% + 6, 0)
'Call outt(BaseAddress% + 7, 7)
'List1.AddItem "points:" & Str$(Points&)
'************************
' Collect the values with cbAInScan%()
' Parameters:
' BoardNum% :the number used by CB.CFG to describe this board
' LowChan% :the first channel of the scan
' HighChan% :the last channel of the scan
' CBCount& :the total number of A/D samples to collect
' CBRate& :sample rate
' Gain :the gain for the board
' ADData% :the array for the collected data values
' Options :data collection options
Time_Out_Time = Time_Out_Time * 5
'CBRate = 3 ' sampling rate (samples per second)
'LowChan = 0 'In_Channel '0 ' first channel to acquire
'HighChan = 3 'In_Channel ' 0 ' last channel to acquire
Const FirstPoint As Integer = 0 ' set first element in buffer to transfer to array
' total number of data points to collect
CBCount = points * number_of_channels_to_scan 'highchannel-lowchannel
'If points > 10000 Then
MemHandle = cbWinBufAlloc(points * number_of_channels_to_scan + 10) ' set aside memory to hold data
'End If
' MemHandle = cbWinBufAlloc(CBCount) ' set aside memory to hold data
ulstat = cbSetTrigger(BoardNum, TRIGPOSEDGE, 0, 0.5) 'changes high from 1 to 2
'Options = EXTTRIGGER + BACKGROUND + NOCONVERTDATA '+ SINGLEIO
Options = EXTCLOCK + BACKGROUND + NOCONVERTDATA '+ SINGLEIO
' return data as 16-bit values
' collect data in BACKGROUND mode
' use NOCONVERTDATA if using 16 bit board
' List1.Items.Add(" trace started")
System.Windows.Forms.Application.DoEvents()
If MemHandle = 0 Then
Jabber_jabber.List1.Items.Add("Memhandle failed")
Stop ' check that a handle to a memory buffer exists
End If
ulstat = cbAInScan(BoardNum, LowChan, HighChan, CBCount, CBRate, Gain(Current_Protocol), MemHandle, Options)
'Call Hold_on_There(3)
'Call outt(BaseAddress + 6, 0) 'not needed for this version of PB?
'Call outt(BaseAddress + 7, 0) '7)
'put the device in run mode
'Call outt(BaseAddress + 1, 0) '7)
If (Not cblaster.StartRunningProtocol(Current_Protocol)) Then
System.Windows.Forms.MessageBox.Show("Protocol " & Current_Protocol & " failed to run or timed out.")
System.Windows.Forms.Application.DoEvents()
End If
ulstat = cbGetStatus(BoardNum, ss, CurCount, CurIndex, AIFUNCTION)
Timed_Out = False
Time_Out_Time = VB.Timer() + Time_Out_Time
'Midnight bug fix:
' First, find the correct ending wait time
Dim midnight_mark As Boolean = False
If (Time_Out_Time > (24 * 60 * 60)) Then
Time_Out_Time = Time_Out_Time - (24 * 60 * 60)
midnight_mark = True ' tell following code not to trigger "timed out" until after midnight
End If
'List1.Items.Add(CurCount & " / " & CBCount)
'Dim count As Integer
'Dim ulstat2
If spec_mode = True Then
'ulstat = cbCLoad(1, 1, 0)
End If
While CurCount < CBCount And Timed_Out = False
If (VB.Timer() > Time_Out_Time And midnight_mark = False) Then
Timed_Out = True ' don't time-out before midnight
Jabber_jabber.List1.Items.Add("timed out (midnight=False)")
End If
If (midnight_mark = True And VB.Timer() < 60) Then
Jabber_jabber.List1.Items.Add("timed out at not mid")
midnight_mark = False ' indicate that midnight has passed
End If
System.Windows.Forms.Application.DoEvents()
ulstat = cbGetStatus(BoardNum, ss, CurCount, CurIndex, AIFUNCTION)
Label13.Text = CurCount & " / " & CBCount
'Label4.Text = count
If spec_mode = True Then
'ulstat2 = cbCIn(1, 1, count)
'Set_Lambda(count * delta_lambda + start_lambda)
'Label4.Text = delta_lambda
'Set_Lambda(start_lambda)
End If
System.Windows.Forms.Application.DoEvents()
End While
Label13.Text = CurCount & " ! " & CBCount
System.Windows.Forms.Application.DoEvents()
'List1.Items.Add(CBCount & "CC:" & CurCount)
'ulstat = cbDOut(BoardNum, AUXPORT, &HFFS)
If Timed_Out = True Then
ulstat = cbStopBackground(BoardNum, AIFUNCTION)
System.Windows.Forms.MessageBox.Show("Timed out!")
System.Windows.Forms.Application.DoEvents()
Else
Jabber_jabber.List1.Items.Add(" trace done")
'List1.Items.Add(Str(CurCount) + " * " + Str(CBCount))
'Scrolling text box fix: make the box jump to the bottom after adding an item
Jabber_jabber.List1.TopIndex = List1.Items.Count - 1
End If
ulstat = cbStopBackground(BoardNum, AIFUNCTION) 'clears variables and flags after normal termination
'Transfer the data from the memory buffer set up by Windows to an array for use by Visual Basic
ulstat = cbWinBufToArray(MemHandle, Raw_Data(0), FirstPoint, CBCount)
'If ulstat% <> 0 Then Stop
' convert RAW data into VOLTS
' For i = 0 To (points - 1) * 2 Step 2
' ulstat = cbToEngUnits(BoardNum, Gain, Raw_Data(i), TTT1)
'ulstat = cbToEngUnits(BoardNum, Gain, Raw_Data(i + 1), TTT2)
'Data_Volts(i / 2) = (TTT1 / TTT2)
'Next i
For i = 0 To (points - 1)
For ii = 0 To number_of_channels_to_scan - 1
ulstat = cbToEngUnits(BoardNum, Gain(Current_Protocol), Raw_Data((i * 4) + ii), Data_Volts(i, ii))
'List1.Items.Add("i:" & Str(i) & " ii:" & Str(ii) & " rdi:" & Str((i * 4) + ii) & "d:" & Str(Data_Volts(i, ii)))
Next ii
Next i
Dim testvar As Integer = Raw_Data.Length()
Dim testvar2 As Integer = Data_Volts.Length()
Trace_Running = False
End Sub
Public Sub dmk_exit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dmk_exit.Click
End
End Sub
Private Sub DMK_v1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim ulstat As Short
'Dim i, ii As Short
Dim i As Short
'Dim PBstat As Short
'current_lambda = My.Settings.lambda
LambdaText.Text = current_lambda
BaseAddress = 0
' declare revision level of Universal Library
ulstat = cbDeclareRevision(CURRENTREVNUM)
' Initiate error handling
' activating error handling will trap errors like
' bad channel numbers and non-configured conditions.
' Parameters:
' PRINTALL :all warnings and errors encountered will be printed
' DONTSTOP :if an error is encountered, the program will not stop,
' errors must be handled locally
ulstat = cbErrHandling(PRINTALL, STOPALL)
If ulstat <> 0 Then Stop
' If cbErrHandling% is set for STOPALL or STOPFATAL during the program
' design stage, Visual Basic will be unloaded when an error is encountered.
' We suggest trapping errors locally until the program is ready for compiling
' to avoid losing unsaved data during program design. This can be done by
' setting cbErrHandling options as above and checking the value of ULStat%
' after a call to the library. If it is not equal to 0, an error has occurred.
'FileOpen(1, "c:\testx.dat", OpenMode.Output)