New topic: 

going round in circles!! trying to make 24 serial ports

<http://forums.realsoftware.com/viewtopic.php?t=47605>

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        eqdnb          Post subject: going round in circles!! trying to 
make 24 serial portsPosted: Mon Apr 15, 2013 4:00 pm                         
Joined: Mon Apr 15, 2013 2:58 pm
Posts: 1                i want to make an app which connects via serialports to 
approx 20 devices

i have got the hardware, an edgeport 8 usb, and a brainbox 8 card, and a couple 
of extra rs232 cards / usb adaptors

i , so far, can make an app which shows the info about each port
the problem is realbasic wont compile my program when i try to add more code

i add 1 serial port  in the editor, called serial1 ,to a window called ports, 
then duplicate it as many times as ports exist

with this sort of code
if spcount >1 then
  dim serial2 as serial
  serial2 = new serial
  Serial2.baud=serialrates(1)
  srlportbaud.append str(Serial2.baud)
  spopen=2
  end if

srlportbaud is to be an array i can refer to without having to replicate slow 
sytem calls

then i populate some popup menus in another window with the possible baud rates
i put this code in one popups change event
  dim retval as string
  ports.Serial1.close
  ports.Serial1.baud= pbpm1.ListIndex
  txpnameb1.text=str(ports.serialrates( pbpm1.ListIndex))
  retval=str(ports.Serial1.Open)
  ports.srlportbaud(0) =str(ports.Serial1.baud)
  txpnamea1.text=ports.srlportbaud(0)

but then if i add the following code to the change event of the popup for the 
next serial port , the compiler says my method is unknown, yet ive got code 
which creates serial2

  dim retval as string
 >> ports.Serial2.close (  compliler says no!! unknown method or property)
  ports.Serial2.baud= pbpm2.ListIndex
  txpnameb2.text=str(ports.serialrates( pbpm2.ListIndex))
  retval=str(ports.Serial2.Open)
  ports.srlportbaud(1) =str(ports.Serial2.baud)
  txpnamea2.text=ports.srlportbaud(1)


-------------------------------------------------------------------------
ive tried several methods , heres the full code

in a window called ports i add this code

  dim i , count as Integer
  
  serialrates(0)=300
  serialrates(1)=600
  serialrates(2)=1200
  serialrates(3)=1800
  serialrates(4)=2400
  serialrates(5)=3600
  serialrates(6)=4800
  serialrates(7)=7200
  serialrates(8)=9600
  serialrates(9)=14400
  serialrates(10)=19200
  serialrates(11)=28800
  serialrates(12)=38400
  serialrates(13)=57600
  serialrates(14)=115200
  serialrates(15)=230400
  
  serialpname(0)="COM1"
  serialpname(1)="COM2"
  serialpname(2)="COM3"
  serialpname(3)="COM4"
  serialpname(4)="COM5"
  serialpname(5)="COM6"
  serialpname(6)="COM7"
  serialpname(7)="COM8"
  serialpname(8)="COM9"
  serialpname(9)="COM10"
  serialpname(10)="COM11"
  serialpname(11)="COM12"
  serialpname(12)="COM13"
  serialpname(13)="COM14"
  serialpname(14)="COM15"
  serialpname(15)="COM16"
  serialpname(16)="COM17"
  serialpname(17)="COM18"
  serialpname(18)="COM19"
  serialpname(19)="COM20"
  serialpname(20)="COM21"
  serialpname(21)="COM22"
  serialpname(22)="COM23"
  serialpname(23)="COM24"
  serialpname(24)="COM25"
  
  count = System.SerialPortCount
  spcount =count
  tportsmax.text=str(count)
  
  Serial1.baud=serialrates(0)
  srlportbaud.append str(Serial1.baud)
  spopen=1
  
  If Serial1.Open then
  serial=1
  Else
  serial=0
  End if
  
  if spcount >1 then
  dim serial2 as serial
  serial2 = new serial
  Serial2.baud=serialrates(1)
  srlportbaud.append str(Serial2.baud)
  spopen=2
  end if
  if spcount >2 then
  dim serial3 as serial
  serial3 = new serial
  Serial3.baud=serialrates(2)
  srlportbaud.append str(Serial3.baud)
  spopen=3
  end if
  if spcount >3 then
  dim serial4 as serial
  serial4 = new serial
  Serial4.baud=serialrates(3)
  srlportbaud.append str(Serial4.baud)
  spopen=4
  end if
  
  if spcount >4 then
  dim serial5 as serial
  serial5 = new serial
  Serial5.baud=serialrates(4)
  srlportbaud.append str(Serial5.baud)
  spopen=5
  end if
  if spcount >5 then
  dim serial6 as serial
  serial6 = new serial
  Serial6.baud=serialrates(5)
  srlportbaud.append str(Serial6.baud)
  spopen=6
  end if
  if spcount >6then
  dim serial7 as serial
  serial7 = new serial
  Serial7.baud=serialrates(6)
  srlportbaud.append str(Serial7.baud)
  spopen=7
  end if
  
  if spcount >7 then
  dim serial8 as serial
  serial8 = new serial
  Serial8.baud=serialrates(7)
  srlportbaud.append str(Serial8.baud)
  spopen=8
  end if
  if spcount >8 then
  dim serial9 as serial
  serial9 = new serial
  Serial9.baud=serialrates(8)
  srlportbaud.append str(Serial9.baud)
  spopen=9
  end if
  if spcount >9 then
  dim serial10 as serial
  serial10 = new serial
  Serial10.baud=serialrates(8)
  srlportbaud.append str(Serial10.baud)
  spopen=10
  
  end if
  
  if spcount >10 then
  dim serial11 as serial
  serial11 = new serial
  Serial11.baud=serialrates(8)
  srlportbaud.append str(Serial11.baud)
  spopen=11
  end if
  
  if spcount >11 then
  dim serial12 as serial
  serial12 = new serial
  Serial12.baud=serialrates(8)
  srlportbaud.append str(Serial12.baud)
  spopen=12
  end if
  
  if spcount >12 then
  dim serial13 as serial
  serial13 = new serial
  Serial13.baud=serialrates(8)
  srlportbaud.append str(Serial13.baud)
  spopen=13
  end if
  if spcount >13 then
  dim serial14 as serial
  serial14 = new serial
  Serial14.baud=serialrates(8)
  srlportbaud.append str(Serial14.baud)
  spopen=14
  end if
  
  
  if spcount >14 then
  dim serial15 as serial
  serial15 = new serial
  Serial15.baud=serialrates(8)
  srlportbaud.append str(Serial15.baud)
  spopen=15
  end if
  
  if spcount >15 then
  dim serial16 as serial
  serial16 = new serial
  Serial16.baud=serialrates(8)
  srlportbaud.append str(Serial16.baud)
  spopen=16
  end if
 
  if spcount >16 then
  dim serial17 as serial
  serial17 = new serial
  Serial17.baud=serialrates(8)
  srlportbaud.append str(Serial17.baud)
  spopen=17
  end if
  
  if spcount >17 then
  dim serial18 as serial
  serial18 = new serial
  srlportbaud.append str(Serial18.baud)
  spopen=18
  end if
  if spcount >18 then
  dim serial19 as serial
  serial19 = new serial
  srlportbaud.append str(Serial19.baud)
  spopen=19
  end if
  if spcount >19 then
  dim serial20 as serial
  serial20 = new serial
  srlportbaud.append str(Serial20.baud)
  spopen=20
  end if
  
  if spcount >20 then
  dim serial21 as serial
  serial21 = new serial
  srlportbaud.append str(Serial21.baud)
  spopen=21
  end if
  
  if spcount >21 then
  dim serial22 as serial
  serial22 = new serial
  srlportbaud.append str(Serial22.baud)
  spopen=22
  end if
  
  if spcount >22 then
  dim serial23 as serial
  serial23 = new serial
  srlportbaud.append str(Serial23.baud)
  spopen=23
  end if
  tf1.text=str(spopen)


---------------------------------------------------------------------------------
then in another window called port settings

i have some text fields and popup menus for baud and com port
and add this code

  dim i , ii, count as Integer 
  count = ports.spcount 
  tportsmax.text=str(count)
 
  if count >0 then
  for i = 0 to count -1
  
  ' srlportindex.append System.SerialPort(i  ).inputdrivername
   srlportname.append System.SerialPort(i  ).Name
  'srlportrated.append str(System.SerialPort(i  ).ratedspeed)
  ' srlportmaxspeed.append str(System.SerialPort(i  ).maximumspeed)
  'srlportdriver.append System.SerialPort(i  ).outputdrivername
   
  
  next i
  
  for ii=0 to 25
  ppm1.AddRow(ports.serialpname( ii ))
  if  srlportname(0)= str(ports.serialpname( ii )) then
    ppm1.listindex=ii
    
  end if
  next ii
  
  for i=0 to 15
  pbpm1.AddRow str((ports.serialrates( i )))
  if ports.srlportbaud(0 ) = str(ports.serialrates( i )) then
    pbpm1.listindex=i
    
  end if
  next i
  
  
  txpname1.text=srlportname(0 )
  txpnamea1.text=ports.srlportbaud(0 )
  'txpnameb1.text= srlportrated(0 )
  end if
  
  if count >1 then
  
  for ii=0 to 25
  ppm2.AddRow(ports.serialpname( ii ))
  if srlportname(1)= str(ports.serialpname( ii )) then
    ppm2.listindex=ii
    
  end if
  next ii
  for i=0 to 15
  pbpm2.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(1) = str(ports.serialrates( i )) then
    pbpm2.listindex=i
    
  end if
  next i
  
  txpname2.text=srlportname(1)
  txpnamea2.text=ports.srlportbaud(1 )
  'txpnameb2.text= srlportrated(1 )
  end if
  
  if count >2 then
  
  for ii=0 to 25
  ppm3.AddRow(ports.serialpname( ii ))
  if srlportname(2)= str(ports.serialpname( ii )) then
    ppm3.listindex=ii
    
  end if
  next ii
  for i=0 to 15
  pbpm3.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(2) = str(ports.serialrates( i )) then
    pbpm3.listindex=i
    
  end if
  next i
  
  txpnamea3.text=ports.srlportbaud(2 )
  txpname3.text=srlportname(2 )
  'txpnameb3.text= srlportrated(2 )
  end if
  
  
  if count >3 then
  
  for ii=0 to 25
  ppm4.AddRow(ports.serialpname( ii ))
  if srlportname(3)= str(ports.serialpname( ii )) then
    ppm4.listindex=ii
  end if
  next ii
  for i=0 to 15
  pbpm4.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(3) = str(ports.serialrates( i )) then
    pbpm4.listindex=i   
  end if
  next i
  pbpm4.initialvalue=str(ports.srlportbaud( 3))
  
  txpnamea4.text=ports.srlportbaud(3 )
  
  txpname4.text=srlportname(3)
  txpnameb4.text=str(count)
  end if

  if count >4 then 
  for ii=0 to 25
  ppm5.AddRow(ports.serialpname( ii ))
  if srlportname(4)= str(ports.serialpname( ii )) then
    ppm5.listindex=ii
    
  end if
  next ii
  for i=0 to 15
  pbpm5.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(4) = str(ports.serialrates( i )) then
    pbpm5.listindex=i
    
  end if
  next i
  pbpm5.initialvalue=str(ports.srlportbaud( 4))
  
  txpnamea5.text=ports.srlportbaud(4 )
  txpname5.text=srlportname(4)
  txpnameb5.text=str(count)
  end if
  
  if count >5 then
  
  for ii=0 to 25
  ppm6.AddRow(ports.serialpname( ii ))
  if srlportname(5)= str(ports.serialpname( ii )) then
    ppm6.listindex=ii
    
  end if
  next ii
  for i=0 to 15
  pbpm6.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(5) = str(ports.serialrates( i )) then
    pbpm6.listindex=i
    
  end if
  next i
  pbpm6.initialvalue=str(ports.srlportbaud( 5))
  
  txpnamea6.text=ports.srlportbaud(5 )
  
  txpname6.text=srlportname(5)
  txpnameb6.text=str(count)
  end if
  
  if count >6 then
  
  for ii=0 to 25
  ppm7.AddRow(ports.serialpname( ii ))
  if srlportname(6)= str(ports.serialpname( ii )) then
    ppm7.listindex=ii
    
  end if
  next ii
  for i=0 to 15
  pbpm7.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(6) = str(ports.serialrates( i )) then
    pbpm7.listindex=i
  end if
  next i
  pbpm7.initialvalue=str(ports.srlportbaud( 6))
  
  txpnamea7.text=ports.srlportbaud(6 )
  txpname7.text=srlportname(6)
  txpnameb7.text=str(count)
  end if
  
  if count >7 then
  
  for ii=0 to 25
  ppm8.AddRow(ports.serialpname( ii ))
  if srlportname(7)= str(ports.serialpname( ii )) then
    ppm8.listindex=ii
  end if
  next ii
  for i=0 to 15
  pbpm8.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(7) = str(ports.serialrates( i )) then
    pbpm8.listindex=i
  end if
  next i
  pbpm8.initialvalue=str(ports.srlportbaud( 7))
  
  txpnamea8.text=ports.srlportbaud(7 )
  txpname8.text=srlportname(7)
  txpnameb8.text=str(count)
  end if
  if count >8 then
  
  for ii=0 to 25
  ppm9.AddRow(ports.serialpname( ii ))
  if srlportname(8)= str(ports.serialpname( ii )) then
    ppm9.listindex=ii
  end if
  next ii
  for i=0 to 15
  pbpm9.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(8) = str(ports.serialrates( i )) then
    pbpm9.listindex=i
  end if
  next i
  pbpm9.initialvalue=str(ports.srlportbaud( )
  
  txpnamea9.text=ports.srlportbaud(8 )
  txpname9.text=srlportname(8)
  txpnameb9.text=str(count)
  end if
  
  
  if count >9 then
  'ETC
  end if

--------------------------------------------------------------

all fine till i try to make the popup value changes active
popup menu 1 is fine
popups 2 onwards cause a problem


popup 1 s  code

  dim retval as string
  ports.Serial1.close
  ports.Serial1.baud= pbpm1.ListIndex
  txpnameb1.text=str(ports.serialrates( pbpm1.ListIndex))
  retval=str(ports.Serial1.Open)
  ports.srlportbaud(0) =str(ports.Serial1.baud)
  txpnamea1.text=ports.srlportbaud(0)



popup2 s code

  dim retval as string
  ports.Serial2.close
  ports.Serial2.baud= pbpm2.ListIndex
  txpnameb2.text=str(ports.serialrates( pbpm2.ListIndex))
  retval=str(ports.Serial2.Open)
  ports.srlportbaud(1) =str(ports.Serial2.baud)
  txpnamea2.text=ports.srlportbaud(1)

the compiler wont let me refer to object names which only exist during runtime
serial1 is created by dragging the serial icon in the editor
serial2 is the result of 

  ports window

  if spcount >1 then
  dim serial2 as serial
  serial2 = new serial
  Serial2.baud=serialrates(1)
  srlportbaud.append str(Serial2.baud)
  spopen=2
  end if

---------------------------------------
i have also tried another approach

in my ports window, i drag a serial object onto it in the editor
then i change its index param to 25

then my code looks like this  ( i am just sequentially setting the baudrates 
just for testing to check the code etc)
ports window

  dim i , count as Integer
  
  serialrates(0)=300
  serialrates(1)=600
  serialrates(2)=1200
  serialrates(3)=1800
  serialrates(4)=2400
  serialrates(5)=3600
  serialrates(6)=4800
  serialrates(7)=7200
  serialrates(8)=9600
  serialrates(9)=14400
  serialrates(10)=19200
  serialrates(11)=28800
  serialrates(12)=38400
  serialrates(13)=57600
  serialrates(14)=115200
  serialrates(15)=230400
  
  serialpname(0)="COM1"
  serialpname(1)="COM2"
  serialpname(2)="COM3"
  serialpname(3)="COM4"
  serialpname(4)="COM5"
  serialpname(5)="COM6"
  serialpname(6)="COM7"
  serialpname(7)="COM8"
  serialpname(8)="COM9"
  serialpname(9)="COM10"
  serialpname(10)="COM11"
  serialpname(11)="COM12"
  serialpname(12)="COM13"
  serialpname(13)="COM14"
  serialpname(14)="COM15"
  serialpname(15)="COM16"
  serialpname(16)="COM17"
  serialpname(17)="COM18"
  serialpname(18)="COM19"
  serialpname(19)="COM20"
  serialpname(20)="COM21"
  serialpname(21)="COM22"
  serialpname(22)="COM23"
  serialpname(23)="COM24"
  serialpname(24)="COM25"
  
  
  
  
  
  
  
  count = System.SerialPortCount
  
  spcount =count
  
  tportsmax.text=str(count)
  
  dim serial1(25) as serial
  serial1(1) = new serial
  
  
  for i = 0 to count - 1
  'PopupMenu1.AddRow( System.SerialPort( i ).Name )
  next
  
  'Serial1(1).close
  'Serial1(1).SerialPort=System.SerialPort("COM1")
  
  'Textfield1.Text=str(Serial1(1).Open)
  If Serial1(1).Open then
  serial=1
  Else
  serial=0
  End if
  
  
  Serial1(1).baud=serialrates(0)
  srlportbaud.append str(Serial1(1).baud)
  spopen=1
  
  If Serial1(1).Open then
  serial=1
  Else
  serial=0
  End if
  
  
  
  
  
  
  if spcount >1 then
  serial1(2) = new serial
  Serial1(2).baud=serialrates(1)
  srlportbaud.append str(Serial1(2).baud)
  spopen=2
  end if
  if spcount >2 then
  serial1(3) = new serial
  Serial1(3).baud=serialrates(2)
  srlportbaud.append str(Serial1(3).baud)
  spopen=3
  end if
  if spcount >3 then
  
  serial1(4) = new serial
  Serial1(4).baud=serialrates(3)
  srlportbaud.append str(Serial1(4).baud)
  spopen=4
  end if
  
  if spcount >4 then
  serial1(5) = new serial
  Serial1(5).baud=serialrates(4)
  srlportbaud.append str(Serial1(5).baud)
  spopen=5
  end if
  if spcount >5 then
  
  serial1(6) = new serial
  Serial1(6).baud=serialrates(5)
  srlportbaud.append str(Serial1(6).baud)
  spopen=6
  end if
  if spcount >6then
  
  serial1(7) = new serial
  Serial1(7).baud=serialrates(6)
  srlportbaud.append str(Serial1(7).baud)
  spopen=7
  end if
  
  if spcount >7 then
  
  serial1(8) = new serial
  Serial1(8).baud=serialrates(7)
  srlportbaud.append str(Serial1(8).baud)
  spopen=8
  end if
  if spcount >8 then
  
  serial1(9) = new serial
  Serial1(9).baud=serialrates(8)
  srlportbaud.append str(Serial1(9).baud)
  spopen=9
  end if
  if spcount >9 then
  
  serial1(10) = new serial
  Serial1(10).baud=serialrates(8)
  srlportbaud.append str(Serial1(10).baud)
  spopen=10
  
  end if
  
  if spcount >10 then
  
  serial1(11) = new serial
  Serial1(11).baud=serialrates(8)
  srlportbaud.append str(Serial1(11).baud)
  spopen=11
  end if
  
 
  --------------------------------------------------------------
  
 and in my port settings window

  dim i , ii, count as Integer
  
  count = ports.spcount
  
  tportsmax.text=str(count)
  
  
  if count >0 then
  for i = 0 to count -1
  
  ' srlportindex.append System.SerialPort(i  ).inputdrivername
   srlportname.append System.SerialPort(i  ).Name
  'srlportrated.append str(System.SerialPort(i  ).ratedspeed)
  ' srlportmaxspeed.append str(System.SerialPort(i  ).maximumspeed)
  'srlportdriver.append System.SerialPort(i  ).outputdrivername
  
  
  
  
  next
  
  for ii=0 to 25
  ppm1.AddRow(ports.serialpname( ii ))
  if  srlportname(0)= str(ports.serialpname( ii )) then
    ppm1.listindex=ii
    
  end if
  next ii
  
  for i=0 to 15
  pbpm1.AddRow str((ports.serialrates( i )))
  if ports.srlportbaud(0 ) = str(ports.serialrates( i )) then
    pbpm1.listindex=i
    
  end if
  next i
  
  
  txpname1.text=srlportname(0 )
  txpnamea1.text=ports.srlportbaud(0 )
  'txpnameb1.text= srlportrated(0 )
  end if
  
  if count >1 then
  for i = 0 to count -1
  
  
  
  next
  for ii=0 to 25
  ppm2.AddRow(ports.serialpname( ii ))
  if srlportname(1)= str(ports.serialpname( ii )) then
    ppm2.listindex=ii
    
  end if
  next ii
  for i=0 to 15
  pbpm2.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(1) = str(ports.serialrates( i )) then
    pbpm2.listindex=i
    
  end if
  next i
  
  txpname2.text=srlportname(1)
  txpnamea2.text=ports.srlportbaud(1 )
  'txpnameb2.text= srlportrated(1 )
  end if
  
  if count >2 then
  
  for ii=0 to 25
  ppm3.AddRow(ports.serialpname( ii ))
  if srlportname(2)= str(ports.serialpname( ii )) then
    ppm3.listindex=ii
    
  end if
  next ii
  for i=0 to 15
  pbpm3.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(2) = str(ports.serialrates( i )) then
    pbpm3.listindex=i
    
  end if
  next i
  
  txpnamea3.text=ports.srlportbaud(2 )
  txpname3.text=srlportname(2 )
  'txpnameb3.text= srlportrated(2 )
  end if
  
  
  if count >3 then
  
  
  for ii=0 to 25
  ppm4.AddRow(ports.serialpname( ii ))
  if srlportname(3)= str(ports.serialpname( ii )) then
    ppm4.listindex=ii
    
  end if
  next ii
  for i=0 to 15
  pbpm4.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(3) = str(ports.serialrates( i )) then
    pbpm4.listindex=i
    
  end if
  next i
  pbpm4.initialvalue=str(ports.srlportbaud( 3))
  
  txpnamea4.text=ports.srlportbaud(3 )
  
  txpname4.text=srlportname(3)
  txpnameb4.text=str(count)
  end if
  
  
  if count >4 then
  
  for ii=0 to 25
  ppm5.AddRow(ports.serialpname( ii ))
  if srlportname(4)= str(ports.serialpname( ii )) then
    ppm5.listindex=ii
    
  end if
  next ii
  for i=0 to 15
  pbpm5.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(4) = str(ports.serialrates( i )) then
    pbpm5.listindex=i
    
  end if
  next i
  pbpm5.initialvalue=str(ports.srlportbaud( 4))
  
  txpnamea5.text=ports.srlportbaud(4 )
  txpname5.text=srlportname(4)
  txpnameb5.text=str(count)
  end if
  
  if count >5 then
  
  for ii=0 to 25
  ppm6.AddRow(ports.serialpname( ii ))
  if srlportname(5)= str(ports.serialpname( ii )) then
    ppm6.listindex=ii
    
  end if
  next ii
  for i=0 to 15
  pbpm6.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(5) = str(ports.serialrates( i )) then
    pbpm6.listindex=i
    
  end if
  next i
  pbpm6.initialvalue=str(ports.srlportbaud( 5))
  
  txpnamea6.text=ports.srlportbaud(5 )
  
  txpname6.text=srlportname(5)
  txpnameb6.text=str(count)
  end if
  
  if count >6 then
  
  for ii=0 to 25
  ppm7.AddRow(ports.serialpname( ii ))
  if srlportname(6)= str(ports.serialpname( ii )) then
    ppm7.listindex=ii
    
  end if
  next ii
  for i=0 to 15
  pbpm7.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(6) = str(ports.serialrates( i )) then
    pbpm7.listindex=i
  end if
  next i
  pbpm7.initialvalue=str(ports.srlportbaud( 6))
  
  txpnamea7.text=ports.srlportbaud(6 )
  txpname7.text=srlportname(6)
  txpnameb7.text=str(count)
  end if
  
  if count >7 then
  
  for ii=0 to 25
  ppm8.AddRow(ports.serialpname( ii ))
  if srlportname(7)= str(ports.serialpname( ii )) then
    ppm8.listindex=ii
  end if
  next ii
  for i=0 to 15
  pbpm8.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(7) = str(ports.serialrates( i )) then
    pbpm8.listindex=i
  end if
  next i
  pbpm8.initialvalue=str(ports.srlportbaud( 7))
  
  txpnamea8.text=ports.srlportbaud(7 )
  txpname8.text=srlportname(7)
  txpnameb8.text=str(count)
  end if
  if count >8 then
  
  for ii=0 to 25
  ppm9.AddRow(ports.serialpname( ii ))
  if srlportname(8)= str(ports.serialpname( ii )) then
    ppm9.listindex=ii
  end if
  next ii
  for i=0 to 15
  pbpm9.AddRow(str(ports.serialrates( i )))
  if  ports.srlportbaud(8) = str(ports.serialrates( i )) then
    pbpm9.listindex=i
  end if
  next i
  pbpm9.initialvalue=str(ports.srlportbaud( )
  
  txpnamea9.text=ports.srlportbaud(8 )
  txpname9.text=srlportname(8)
  txpnameb9.text=str(count)
  end if
  
  
  if count >9 then
  for i = 0 to count -1
  'ppm10.AddRow(srlportname( i ))
  next
  for i=0 to 15
  'pbpm10.AddRow(str(ports.serialrates( i )))
  next i
  'pbpm4.initialvalue=str(ports.srlportbaud( 9))
  
  'txpnamea10.text=ports.srlportbaud(9 )
  txpname10.text=str(count)
  txpnameb10.text=str(count)
  end if
  //

--------------------------------------------------------------------------
this all works so far, until i start to add code to the popup menus change event

  dim retval as string
  ports.Serial1(1).close
  ports.Serial1(1).baud= pbpm2.ListIndex
  txpnameb1.text=str(ports.serialrates( pbpm1.ListIndex))
  retval=str(ports.Serial1(1).Open)
  ports.srlportbaud(0) =str(ports.Serial1(1).baud)
  txpnamea1.text=ports.srlportbaud(0)


now the compiler says NilObjectException
on this line > ports.Serial1(1).close

---------------------------------------------------------------


i hope ive explained the problem clearly, basically, how do i make an app which 
can access as many serial ports as are existing, and control the port settings 
etc, and send and receive data on them all.

do i have to drag about 25 serial controls onto my ports window using the editor
what happens if i write the program based on there being say 16 ports, and it 
works with all the rs232cards / usb attached, will it function with some usb 
rs232 or rs232 cards not installed, how do i write a program that sometimes 
will have many ports and sometimes only a few..

i am a bit lost with the NEW operator , and how the index function works as a 
parameter of a serial object.

oh and i need to make all the data sending and receiving run in a seperate 
threads to the user interface...!  heaven help me! 

i like flash actionscript because that lets me refer to a variable called 
"my33data" by code like this "my"+counter+"data" = anumber....   
                             Top                Paul Lefebvre          Post 
subject: Re: going round in circles!! trying to make 24 serial portsPosted: Tue 
Apr 16, 2013 3:59 pm                       Site Admin                
Joined: Fri Sep 30, 2005 9:35 am
Posts: 955
Location: South Portland, Maine                That seems like a bit too much 
code for anyone to wade through 

Anyway, if you want a bunch of serial objects, then you can create them and put 
them in an array. You start to do that at the beginning, but then you seem to 
stop using the array.

Property mSerialControllers() As Serial

This create 25 serials objects:

Dim s As Serial
For i As Integer = 1 To 25
  s = New Serial
  mSerialControllers.Append(s)
Next


Now that you have created the serial objects, you just use the array to refer 
to them. You don't to keep recreating them using New:

mSerialController(10).Baud = 9600

You can check how many you have created using the Ubound function:

Dim serialCount As Integer = mSerialControllers.Ubound+1 // 0-based, so add 1 
to the Ubound      
_________________
Paul Lefebvre
Developer Evangelist
Real Software, Inc.

The Real Studio Developer Conference is back: April 23rd-26th, 2013 in Orlando, 
FL.  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to