Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
I've been searching for how to Communicate With Easy Bluetooth Module all day but I can't make it work.In Basic Stamp I was working with SERIN AND SEROUT with success.
What I want to do is send some bytes to the module and after that receive some more bytes. The Modules RX pin is 5 And the TX pin is 7.
Function SetupConnection() as bit
Call DefineCom(3,PIN_RX,PIN_TX,0,&H1F)
Call OpenQueue(inQueue,SizeOf(inQueue))
Call OpenQueue(outQueue,SizeOf(outQueue))
Call OpenCom(3,9600,inQueue,outQueue)
if ((StatusCom(3) AND &H02) = &H02) then
SetupConnection = 0
else
SetupConnection = 1
End if
'On Error Return 1
End Function
Function SearchDevice() as bit
'Send Search Request
Call PutQueueByte(outQueue,B_STX)
Call PutQueueByte(outQueue,B_REQ)
Call PutQueueByte(outQueue,GAP_INQUIRY)
Call PutQueueByte(outQueue,&H03)
Call PutQueueByte(outQueue,&H00)
Call PutQueueByte(outQueue,B_REQ+GAP_INQUIRY+&H03)
Call PutQueueByte(outQueue,&H03)
Call PutQueueByte(outQueue,&H00)
Call PutQueueByte(outQueue,&H00)
Call PutQueueByte(outQueue,B_ETX)
'Get Comfirm And Devices
'Wait Until Transmit Ends
Do while ((StatusCom(Channel) AND &H04) = &H04)
Delay(0.2)
Loop
Call GetQueue(inQueue, rByte, 1)
SearchDevices = 0
End Function
After Setting Up Com I want to send a request message to module as above then wait until transmiting and recieving bytes end and read the inQueue array.
geocool wrote:Unfortunately I can't get Channel 3 work.
It looks like you're using an incorrect invocation of DefineCom(). Try the program below. It should print True. The main difference is that the fourth parameter to DefineCom() is &H08 indicating that 8-bit, non-inverted mode is desired. Perhaps you can describe your thought process that arrived at using 0 for the fourth parameter and &H1f for the fifth (optional) parameter.
Const rxPin as Byte = 5
Const txPin as Byte = 7
Const chan as Byte = 3
Dim rxQueue(1 to 20) as Byte
Dim txQueue(1 to 20) as Byte
Sub Main()
Dim flag as Boolean
flag = SetupConnection()
Debug.Print flag
End Sub
Function SetupConnection() as Boolean
Call OpenQueue(rxQueue)
Call OpenQueue(txQueue)
Call DefineCom(chan, rxPin, txPin, &H08)
Call OpenCom(chan, 9600, rxQueue, txQueue)
If ((StatusCom(chan) And &H02) = &H02) Then
SetupConnection = True
Else
SetupConnection = False
End If
End Function
As a side note, functions that return a Bit type are actually implemented as if they return a Byte or Boolean so there is no savings as you might have expected. Defining variables as Bit types, on the other hand, does save RAM space at the expense of additional code size and execution time.