Hello,
For efficiency, I wish to loop through handling of data from 2 CR1000X Com ports. Here is the very minimal code:
Public PTemp, pbuffer(2) As String * 50, i As Long
Const cports = {ComC3,ComC5}
BeginProg
SerialOpen (cports(1),19200,0,0,50) ' 19200,N,8,1,None
SerialOpen (cports(2),19200,0,0,50) ' 19200,N,8,1,None
Scan (10,Sec,3,0)
PanelTemp (PTemp,250)
For i = 1 To 2
SerialIn (pbuffer(i),cports(i),300,CHR(13)+CHR(10),50)
' Do some processing
NextScan
EndProg
The error is:
[Version]C:\Campbellsci\Lib\Compilers\CR1000XComp.exe VERSION:CR1000X.Std.06.01 DATE:08/23/2022
cport-test.CR1X -- Compile Failed!
line 7: ComPort 0 illegal.
line 7: Parameter must be a constant integer: SerialOpen (cports(1),19200,0,0,50) .
line 8: ComPort 0 illegal.
line 8: Parameter must be a constant integer: SerialOpen (cports(2),19200,0,0,50) .
line 13: Incomplete expression: cports(i).
Error(s) detected in the program. Double-click an error above to navigate to it.
I understand that the Com port must be a constant integer value but no matter how I change the above or even if I substitute the actual Com port numbers (10 and 11), I just keeping getting errors. I don't mind the two SerialOpen calls having the direct Com port names but the real problem is referencing the correct Com port in the SerialIn without extra if-then code that should not be necessary. Perhaps it just cannot be done?
Thanks in advance for any help.
v/r,
PH
This post is under review.