SEROUT - SERIN IN ZBASIC

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.
Post Reply
geocool
Posts: 15
Joined: 04 May 2011, 9:38 AM

SEROUT - SERIN IN ZBASIC

Post by geocool »

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.

I tried the following:

Code: Select all

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
Unfortunately I can't get Channel 3 work.

Code: Select all

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.

Thanks In Advance :)

I Hope
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: SEROUT - SERIN IN ZBASIC

Post by dkinzer »

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.

Code: Select all

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.
- Don Kinzer
geocool
Posts: 15
Joined: 04 May 2011, 9:38 AM

Post by geocool »

First of all thank you very much for your fast answer. I will try the code and I will post the results. And thanks for the note it's good to know !
Post Reply