File: testsuite_serialio_include.kbs

package info (click to toggle)
basic256 2.0.99.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,888 kB
  • sloc: cpp: 17,185; yacc: 4,025; lex: 1,466; java: 1,091; sh: 39; xml: 33; makefile: 20
file content (102 lines) | stat: -rw-r--r-- 2,209 bytes parent folder | download | duplicates (2)
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
# testsuite_serialio_include section for BASIC256

# Modification History
# date		programmer	description
# 20141025	j.m.reneau	split from main testsuite
# 20151206	j.m.reneau	moved do test question to main testsuite

currentsuite = "serialio"

# Serial Port IO

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