Author Topic: SmartBasic programming for Laird bluetooth radio  (Read 1851 times)

0 Members and 1 Guest are viewing this topic.

Offline LukeWTopic starter

  • Frequent Contributor
  • **
  • Posts: 686
SmartBasic programming for Laird bluetooth radio
« on: January 21, 2015, 05:26:25 am »
Could somebody give me some help or advice with this code please?

This is a "SmartBasic" program for a Laird BL600 Bluetooth device.
It is saved in the device as the $autorun$ file. When the device is powered up in autorun mode, I'd like to be able to open a serial terminal and talk to it, type in a string terminated with a carriage return and get the appropriate response, but it does not seem to give me that expected output, after the carriage return.

If you look at the attached image, the first PRINT expression works, and we have some characters typed in followed by a carriage return, but we're not getting the expected behavior.

Eventually what I'd actually like to accomplish is to be able to send in a custom AT-like command over the serial link, of the form "AT+ GIOij" or something like that, for compatibility with an existing system with a different chipset which is receiving AT-like commands to control the GPIOs but which Laird devices don't support, and parse out the appropriate cases using UartReadMatch to turn on or off GPIOs, where i is the GPIO pin number and j is the desired Boolean output state.

That's ultimately what I want, but I'm just getting there (or not getting there) one piece at a time, and this is really just a basic test of being able to read and parse basic expressions out of the UART.

Code: [Select]
//==========================================

//Example :: UartReadMatch.sb (See in BL600CodeSnippets.zip)
DIM rc,str$,ret,char,str2$
ret=1 //Function return value
char=13 //ASCII decimal value for 'carriage return'
str$="Your name is "
str2$="\n\nMatch character ' ' not found \nExiting.."
FUNCTION HndlrUartRx()
 TimerStart(0,10,0) //Allow time for data to reach rx buffer
ENDFUNC 1
FUNCTION HndlrTmr0()
 rc = UartReadMatch(str$,char)
 PRINT "\n";str$
 IF rc==0 THEN
 rc=StrSetChr(str2$,char,19) //Insert 'char', the match character
 PRINT str2$
 str2$="\n\nMatch character not found \nExiting.." //reset str2$
 ret=0
 ELSE
 PRINT "\n\n\nNow type something without the letter 'a'\n"
 str$="You sent " //reset str$
 char=97 //ASCII decimal value for 'a'
 ret=1
 ENDIF
ENDFUNC ret

rc = UartOpen(9600,0,0,"CN81H")
IF rc!= 0 THEN
 PRINT "\nFailed to open UART interface with error code ";INTEGER.H' rc
ELSE
// Successful UartOpen condition is silent.
ENDIF
 
ONEVENT EVTMR0 CALL HndlrTmr0
ONEVENT EVUARTRX CALL HndlrUartRx
PRINT "\nWhat is your name?\n"
WAITEVENT

//==========================================
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf