AIRcable Logo CompanyProductsTechnologiesSupportOEMsContact Us
BackView CartView Cart
AIRcable Industrial Programming Handbook - Part 11

Support : Industrial : AIRcable AIRmotes Programming Handbook : PART 11

PART 11: AIRcable Serial Tester with the AIRcable Industrial

Since the AIRcable Industrial is a programmable and autonomous Bluetooth device we use it now in our production of the AIRcable Serial male and female devices.

Theory of Operation

The AIRcable Serial is configurable through the UART. It uses a command line interface that is active when no connections are present.

The AIRcable Industrial uses the command line interface to configure the AIRcable Serial.

When the AIRcable Industrial recognizes that an AIRcable Serial is plugged in, it switches the AIRcable Serial into manual mode. Then it sends a connection command to the AIRcable Serial to have it connect via Bluetooth to the AIRcable Industrial. Once a connection is established the AIRcable Industrial sends a string to the UART which should arrive back through Bluetooth at the slave port of the AIRcable Industrial.

When data were exchanged correctly the AIRcable Industrial disconnects the Bluetooth link, and then reconfigures the AIRcable Serial to the factory settings. It then lights up the green LED and waits for the user to plug in a new AIRcable Serial to test and to configure.

The whole process takes 15 seconds.

The AIRcable Serial Tester Program

The program starts with the initialization of the UART. The command line interface of the AIRcable Serial runs at 115200 baud.

Line 23 loads a configuration program that usually contains our factory default settings. For certain customers we can change the configuration so the production can be customized. The master connection in the initialization is for a label printer. Once a test is finished successfully we send the Bluetooth address to the printer which prints a label for the product.

@ERASE

@INIT 10
0 REM RS232_off set
11 A=pioout 5
12 A=pioset 5
0 REM RS232_on set
14 A=pioout 3
15 A=pioset 3
0 REM DTR output clear
17 A=pioout 6
18 A=pioclr 6
0 REM LED output and on
19 A=pioout 2
20 A=pioset 2
0 REM AC1 at 115k
21 T = baud 115
0 REM delete all pairing
22 REM A = unpair 0
0 REM load config from fs
23 A = load "acconf.bas"
0 REM set $4 to addr of printer
24 $4 = "0013105D4CAC"
25 REM A = master $4
0 REM K used for number of readings until connected
26 K = 3
27 RETURN

@MASTER 60
60 PRINTM "connected\n"
61 RETURN

The @IDLE routine runs whenever the slave connection is closed. The lines 100 to 106 actually block the AIRcable Industrial for running any other BASIC program parts. This is ok in our case. We can still upload BASIC programs to the AIRcable Industrial even though the BASIC program is in a loop.

Basically, it sends a reset command to the AIRcable Serial and waits for an "OK" back.

@IDLE 100
0 REM test start
0 REM Reset Z
0 REM Read OK
100 GOSUB 70
101 TIMEOUTU 3
102 PRINTU "\x01Z\r";
103 INPUTU $0
104 IF $0[0] = 0 THEN 100
105 H = strcmp "OK"
106 IF H <> 0 THEN 100

As soon as someone plugs in a correctly working AIRcable Serial into the AIRcable Industrial, it will respond correctly with an "OK" and then resets. This will get the AIRcable Serial into manual mode where we can issue connection commands.

We give it 1 second time to perform the reset dna then configure the AIRcable Serial for testing. We set PIN code and open up our incoming serial slave port. Then we tell the AIRcable Serial to make a connection to ourselves. The build-in function getaddr gets our own address.

The PRINTV instruction builds up a string in $0 which we can send then at once to the UART.

In this code we also use a counter in variable K which allows us to try a command 3 times if for some reason the communication is hampered. Maybe the processing time was a bit longer then expected.

The AIRcable Serial in manual mode tells us too, if a Bluetooth connection was successful. We read the string "CONNECTED" and terminate the @IDLE routine to allow the @SLAVE routine to talk to the AIRcable Serial.

0 REM wait 1 sec for reset
107 WAIT 1

0 REM set PIN code to 1234
0 REM read name
110 K = 3
111 TIMEOUTU 3
112 PRINTU "\x01P1234\r";
113 INPUTU $0
114 K = K - 1
115 IF K = 0 THEN 100
116 H = strcmp "OK"
117 IF H <> 0 THEN 111

0 REM allow incoming connect now
118 A = slave 20
119 WAIT 2

0 REM Connect CS btaddr
0 REM Read CONNECTED
120 $0[0] = 0
121 PRINTV "\x01CS"
122 A = getaddr $0[3]
123 PRINTV "\r"

0 REM wait for CONNECTED message
124 PRINTU $0;
125 K = 3

126 TIMEOUTU 10;
127 INPUTU $0
128 K = K - 1
129 IF K = 0 THEN 70
130 H = strcmp "CONNECTED"
131 IF H <> 0 THEN 126

0 REM connected, done and return
132 RETURN

When a connection from the AIRcable Serial to the AIRcable Industrial was established, the @SLAVE routine starts up. The important thing we do first is that we delete the stored pairing information. First we don't need it later on and the AIRcable Serial will delete the pairing information too after reconfiguration.

The AIRcable Industrial sends a string to the slave port and reads it back on the UART. If this was successful we have a correct data transmission between two Bluetooth devices and the AIRcable Serial works perfectly. We disconnect and configure the AIRcable Serial to a factory default configuration.

0 REM Send HELLO to slave
@SLAVE 148
148 A = getconn $0
149 A = unpair $0

0 REM read HELLO from UART
0 REM try 3 times
151 K = 3
152 TIMEOUTU 2;
153 PRINTS "AIRcable\r";
154 INPUTU $0
155 K = K - 1
156 IF K = 0 THEN 170
157 H = strcmp "AIRcable"
158 IF H <> 0 THEN 152
0 REM state test successful
0 REM disconnect and configure
160 H = disconnect 0
161 WAIT 2
162 GOTO 180

0 REM failed, disconnect and return
170 H = disconnect 0
171 RETURN

0 REM AC1 works

0 REM read disconnect message
180 TIMEOUTU 3
181 INPUTU $0
182 IF $0[0] <> 0 THEN 180

0 REM read bt addr
183 PRINTU "\x01B\r"
184 TIMEOUTU 3
185 INPUTU $0
186 $1 = $0[6]

0 REM do config
189 GOSUB 300

0 REM make message
190 $0[0] = 0
191 PRINTV $1
192 PRINTV " OK\n"
0 REM light LED until disconnected
193 A = pioset 2
194 REM B = message $4
0 REM wait until unplugged

At this point we light up the green LED for the user to see that the test was successful. Then we send commands to the AIRcable Serial and read responses back until someone unplugs the AIRcable Serial and we get a timeout. Then the test program starts again.

0 REM read PIN code until failed

200 K = 3
201 TIMEOUTU 1;
202 PRINTU "\x01D\r";
203 INPUTU $0
204 K = K - 1
205 IF K = 0 THEN 209
206 IF $0[0] = 0 THEN 201
207 GOTO 200

209 A = pioclr 2
0 REM set state test begin
210 RETURN

This is the configuration subroutine that configures the AIRcable Serial to factory default.

0 REM SUBROUTINE configure AC1
0 REM Read OK back
300 K = 3
301 TIMEOUTU 3
302 PRINTU "\x01AR\r";
303 INPUTU $0
304 K = K - 1
305 IF K = 0 THEN 308
306 H = strcmp "OK"
307 IF H <> 0 THEN 301
308 RETURN

This routine can be overwritten by an application called "acconf.bas" from the file system as loaded during startup.

This is the whole code:

@ERASE
@UNPAIR
@INIT 10
0 REM RS232_off set
11 A=pioout 5
12 A=pioset 5
0 REM RS232_on set
14 A=pioout 3
15 A=pioset 3
0 REM DTR output clear
17 A=pioout 6
18 A=pioclr 6
0 REM LED output and on
19 A=pioout 2
20 A=pioset 2
0 REM AC1 at 115k
21 T = baud 115
0 REM delete all pairing
22 REM A = unpair 0
0 REM load config from fs
23 A = load "acconf.bas"
0 REM set $4 to addr of printer
24 $4 = "0013105D4CAC"
25 REM A = master $4
0 REM K used for number of readings until connected
26 K = 3
27 RETURN

@MASTER 60
60 PRINTM "connected\n"
61 RETURN

0 REM blink routine
70 A = pioset 2
71 A = pioclr 2
72 K = 5
73 RETURN

@IDLE 100
0 REM test start
0 REM Reset Z
0 REM Read OK
100 GOSUB 70
101 TIMEOUTU 3
102 PRINTU "\x01Z\r";
103 INPUTU $0
104 IF $0[0] = 0 THEN 100
105 H = strcmp "OK"
106 IF H <> 0 THEN 100
0 REM wait 1 sec for reset
107 WAIT 1

0 REM set PIN code to 1234
0 REM read name
110 K = 3
111 TIMEOUTU 3
112 PRINTU "\x01P1234\r";
113 INPUTU $0
114 K = K - 1
115 IF K = 0 THEN 100
116 H = strcmp "OK"
117 IF H <> 0 THEN 111

0 REM allow incoming connect now
118 A = slave 20
119 WAIT 2

0 REM Connect CS btaddr
0 REM Read CONNECTED
120 $0[0] = 0
121 PRINTV "\x01CS"
122 A = getaddr $0[3]
123 PRINTV "\r"

0 REM wait for CONNECTED message
124 PRINTU $0;
125 K = 3

126 TIMEOUTU 10;
127 INPUTU $0
128 K = K - 1
129 IF K = 0 THEN 70
130 H = strcmp "CONNECTED"
131 IF H <> 0 THEN 126

0 REM connected, done and return
132 RETURN

0 REM Send HELLO to slave
@SLAVE 148
148 A = getconn $0
149 A = unpair $0

0 REM read HELLO from UART
0 REM try 3 times
151 K = 3
152 TIMEOUTU 2;
153 PRINTS "AIRcable\r";
154 INPUTU $0
155 K = K - 1
156 IF K = 0 THEN 170
157 H = strcmp "AIRcable"
158 IF H <> 0 THEN 152
0 REM state test successful
0 REM disconnect and configure
160 H = disconnect 0
161 WAIT 2
162 GOTO 180

0 REM failed, disconnect and return
170 H = disconnect 0
171 RETURN

0 REM AC1 works

0 REM read disconnect message
180 TIMEOUTU 3
181 INPUTU $0
182 IF $0[0] <> 0 THEN 180

0 REM read bt addr
183 PRINTU "\x01B\r"
184 TIMEOUTU 3
185 INPUTU $0
186 $1 = $0[6]

0 REM do config
189 GOSUB 300

0 REM make message
190 $0[0] = 0
191 PRINTV $1
192 PRINTV " OK\n"
0 REM light LED until disconnected
193 A = pioset 2
194 REM B = message $4
0 REM wait until unplugged

0 REM read PIN code until failed

200 K = 3
201 TIMEOUTU 1;
202 PRINTU "\x01D\r";
203 INPUTU $0
204 K = K - 1
205 IF K = 0 THEN 209
206 IF $0[0] = 0 THEN 201
207 GOTO 200

209 A = pioclr 2
0 REM set state test begin
210 RETURN

0 REM SUBROUTINE configure AC1
0 REM Read OK back
300 K = 3
301 TIMEOUTU 3
302 PRINTU "\x01AR\r";
303 INPUTU $0
304 K = K - 1
305 IF K = 0 THEN 308
306 H = strcmp "OK"
307 IF H <> 0 THEN 301
308 RETURN

www.aircables.net/support-ind-program-manual-serialtester.html
 
company info | products | technologies | support | applications | contact us | site map
© 2005 Wireless Cables Inc. All Rights Reserved. Wireless Cables, Inc., Santa Cruz, California, U.S.A.
privacy policy | terms of use | site design by macdonald design, inc.