Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

CR6 PulsePort with CPort in Array


steveg Aug 13, 2015 08:19 PM

Hi All,

I'm writing some software for the CR6 in which I want to be able to pulse certain ports depending on which device I am up to. I expect this to vary across project, so want to be able to configure this easily as required, rather than hardcoding things in all the time.
I figured I'd be able to setup an array to house port numbers, then reference that array as I cycle through a for loop.

See below. Thanks in advance for your thoughts on how I could handle this.

Cheers,

Steve

Code:

Dim i As Long
Const InstrumentCount As Long = 4 'define my number of instruments
Dim InstrumentPorts(InstrumentCount) As INT 'create array to hold ports to use at different times

BeginProg
'Configure the port for the instruments
InstrumentPorts(1) = C1
InstrumentPorts(2) = C4
InstrumentPorts(3) = C3
InstrumentPorts(4) = C2

Scan (1,Sec,0,0)
For i = 1 To InstrumentCount
'How I'd like to write it
PulsePort(InstrumentPorts(i),100) '<-----Compiler does not like this!!

'How I feel like I might need to write it
If InstrumentPorts(i) = C1 Then
PulsePort(C1,100)
ElseIf InstrumentPorts(i) = C2 Then
PulsePort(C2,100)
ElseIf InstrumentPorts(i) = C3 Then
PulsePort(C3,100)
ElseIf InstrumentPorts(i) = C4 Then
PulsePort(C4,100)
Else
EndIf
Next i

NextScan
EndProg


jra Aug 14, 2015 02:37 PM

Steve,
The first parameter in the PulsePort() instruction, the port number, needs to be a Constant, not variable as you have declared using the Dim statement.
If you put your cursor on that first parameter in the instruction and press your F1 key you'll bring up the context sensitive help. At the bottom there is a line indicating the "Type" of entry required, there you'll see it needs to be a constant. This is demonstrated at about 2:55 in this video tutorial https://www.campbellsci.com/videos?video=42.

So, I think you're on the right track with your If/Then construction.


steveg Aug 16, 2015 10:37 PM

Thanks Janet for the prompt response.

I've made up a new sub:


Sub MyPulsePort(portString As String * 2, pulseLen_ms As Long)
'Takes care of pulsing required port when text based selection of the port is required, as if from a config file
'Only works for C1 to C4 at the moment
Select Case portString
Case "C1"
PulsePort(C1,pulseLen_ms)
Case "C2"
PulsePort(C2,pulseLen_ms)
Case "C3"
PulsePort(C3,pulseLen_ms)
Case "C4"
PulsePort(C4,pulseLen_ms)
Case Else
'Do nothing
EndSelect
EndSub

Haven't tested it yet, but think it will be fine.

Extension questions:
Is there much difference between writing:
Case "C3"

OR

Case Is = "C3"

???

Steve


jra Aug 17, 2015 04:07 PM

Steve,
As far as I can tell
Case "C3" is the same as Case Is = "C3"
Janet


steveg Aug 17, 2015 05:30 PM

Thanks Janet.
I'll keep you posted following some testing.
Cheers,

Steve

Log in or register to post/reply in the forum.