# testsuite_serialio_include section for BASIC256

# Modification History
# date		programmer	description
# 20141025	j.m.reneau	split from main testsuite

# Serial Port IO

if yn("Do Serial Port Testing?") then
   
   call q("Check to make sure that a loopback plug has been placed in the serial port on your computer.  Click Yes.")
   
   port$ = prompt("What is your serial port called?","com1")
   testbaud$ = prompt("What baud rate do you want to test?","9600")
   
   
   fn = freefile
   print "file=" + fn
   
   openserial fn, port$, int(testbaud$)
   
   # create a stream of random 8 bit numbers
   # send to loopback and check that they came back
   # using the method of reading bytes until we get one
   ck = 0 # checksum out
   for a = 1 to 100
      b = int(rand*256)
      print b + " ";
      ck=ck+b*a
      writebyte fn,b
   next a
   print "->";
   ck2 = 0 # checksum in
   for a = 1 to 100
      b = readbyte(fn)
      while b=-1
         pause .01
         b = readbyte(fn)
      end while
      print b + " ";
      ck2=ck2+b*a
   next a
   call n("serial - random stream (readbyte -1)", ck, ck2)
   
   # create a stream of random 8 bit numbers
   # send to loopback and check that they came back
   # using the method of waiting until not eof
   ck = 0 # checksum out
   for a = 1 to 100
      b = int(rand*256)
      print b + " ";
      ck=ck+b*a
      writebyte fn,b
   next a
   print "->";
   ck2 = 0 # checksum in
   for a = 1 to 100
      while eof(fn)
         pause .01
      end while
      b = readbyte(fn)
      print b + " ";
      ck2=ck2+b*a
   next a
   call n("serial - random stream (EOL)", ck, ck2)
   
   # send a string to loopback - wait for it to come back in
   # and see if it came back correctly
   a$ = "this is a test of readline wait until it all come in"
   write fn, a$
   print "waiting ";
   while size(fn)<length(a$)
      pause .1
      print '.';
   end while
   print
   b$ = readline(fn)
   print b$
   call s("serial - readline", a$, b$)
   
   # send a string with numbers seperated by space(s) and tabs
   # will read read the numeric tokens once we receive it
   a$ = '99 88 77	98	876	32434'
   writeline fn,a$
   print "waiting ";
   while size(fn)<length(a$)
      pause .1
      print '.';
   end while
   print
   ck = 0
   for t = 1 to 6
      b = int(read(fn))
      print b
      ck+=b*t
   next t
   
   call n("serial - read", ck, 199882)
   
   close fn
   
endif
