// ASI - Serial functions, these are here for the ASI type devices // that are addressable and attache to the serial bus. // // UART 1 is used for communication and no handshaking is used. AS // this is a UART then the devices will need the invert command // in order for them to be read correctly // ******************************************************************* // gets keys in buffer, normally inp would be used but when // multiple devices are connected there is no unique terminating // character // ******************************************************************* function asi_in$ dim a$="" while key?(1) <> 0 a$=a$+chr$(key(1)) wend endf // ******************************************************************* // returns a string containing the addresses of all of the devices // separated by '>'. If 3 devices are connected say j,p and b then // the string returned will be a>j>p>. There is no CR on the end // of the string -- use split to get the individual addresses // ******************************************************************* function asi_find$(baud) dim a$ opencom 1 baud 0 // open com port out 1 13:wait 100 // delay needed to establish baud rate out 1 13:wait 100 // send initialisation out 1 4 // invert out 1 13:wait 50 out 1 1 // devices id out 1 13:wait 50 // device 'z' will take up to 780ms to respond wait 800 result asi_in$ endf // ******************************************************************* // writing to a device. Address must be embedded in the s$ string // this will wait for the '>' before returning. A sucessful // write returns a sting // ******************************************************************* function asi_write$(s$) dim rv, a$[:4] out$ 1 s$+*13 // write followed by CR rv=inp(1,a$,50,'>') result a$ endf // ******************************************************************* // Reading a value n...> Values are sent as tect so this will translate // and return the value in binary, example: // print asi_send("av") // returns BV4113 analogue input value // ******************************************************************* function asi_read(s$) dim in$[:5], rv=0, length, digit=1, v out$ 1 s$+*13 // send commad length = inp(1,in$,10,'>') if length > 0 then // something recieved while length > 1 // dont want terminating '>' length=length-1 v=asc(in$,digit)-48 // convert ascii to number rv=(rv*10)+v digit=digit+1 wend endif result rv endf function xx // print asi_find$(9600) asi_change_address print "inpbuf$=";inpbuf$(1) endf