Bluetooth serial port

Post Reply
User avatar
Jon Munro
Posts: 42
Joined: Sun Oct 09, 2005 11:47 am
Location: Brisbane Australia
Contact:

Bluetooth serial port

Post by Jon Munro »

I need 2-way comms to a Bluetooth 'Flic' scanner (to handle the out of range protocol), but always get a port handle of -1 and no response. For testing I have added a 'read' section to sample program 'bluetoth' using code as earlier posts and am attempting to retrieve each character via Chr(bin2l( ReadByte( hIn ) ) )
The scanner works OK to other programs and also via keyboard wedge s/w.
Antonio, friends, can anyone offer any clues?
thanks
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Jon,

We discussed the bluetooth issue here, and finally got it working using CreateFile() function call. Is that the one you are using too ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Jon Munro
Posts: 42
Joined: Sun Oct 09, 2005 11:47 am
Location: Brisbane Australia
Contact:

Post by Jon Munro »

Antonio,
Yes, I'm using the same method as used by Jose with the printer and in your 'bluetoth' sample. I have a variant 'blueread' :

// BlueRead
#include "FWCE.ch"
#define GENERIC_READ 0x80000000
#define GENERIC_WRITE 0x40000000
#define OPEN_EXISTING 3
#define FILE_ATTRIBUTE_NORMAL 0x00000080

function Main()

local oWnd
local hOut := CreateFile( "COM2:",GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL )

DEFINE WINDOW oWnd TITLE "BlueRead"

@ 2, 2 BUTTON "Read" ;
ACTION ReadText( hOut ) SIZE 80, 20

ACTIVATE WINDOW oWnd

CloseHandle( hOut )

return nil

function ReadText( hOut )

local nChr := 1
local cText := ""
local nLen := 0

msginfo(str(hOut))

do while nChr <> 0
nChr := bin2l( ReadByte( hOut ) )
cText := cText + Chr( nChr )
end do

msginfo( cText )

return nil

The port handle is displayed as -1 and then just blanks. I wondered if anyone has got this running in this mode. I will also need to write a response to the scanner, hence am using 'write' mode. Any help is gratefully received, thanks.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Jon,

Please notice that you should use GENERIC_READ instead of GENERIC_WRITE.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Jon Munro
Posts: 42
Joined: Sun Oct 09, 2005 11:47 am
Location: Brisbane Australia
Contact:

Post by Jon Munro »

Antonio,
Some progress - after re-booting the emulator and using only COM1 I can get a port handle number like 230603634, which I assume is OK and similar to running on an Intermec 700C. I'm not able to retrieve characters from the buffer though and repeatedly only get asc(156). How should I read from the communication buffer and is it possible to clear it (like Telpathy tp_clearin())?
Thanks for any clues :-)

regards, saludos
User avatar
Jon Munro
Posts: 42
Joined: Sun Oct 09, 2005 11:47 am
Location: Brisbane Australia
Contact:

Post by Jon Munro »

Notes for newbies on Emulator Serial Ports (MSDN Forums - Device Emulator General 29 Nov 2005)
Serial Port 0: appears inside the emulator as COM1: that apps can use.
Serial Port 1: reserved for WinCE kernel, doesn't have a driver, do not use it. ie 'com2:' is not available.
Serial Port 2: the IRDA port and assigned the name COM3:

I've grafted fragments of FWPPC 'comm.c' into parts of Harbour Telepathy (port by Luiz Rafael Culik Guimaraes) and have a working FWPPC test program that reads from a barcode scanner and can send acks, etc. Nearly there...
Regards and happy and successful 2006 to all :-)
User avatar
HATHAL
Posts: 77
Joined: Tue Nov 15, 2005 3:38 pm
Location: The Kingdom Saudi Arabia -Riyadh
Contact:

I testing all fwppc sources the available and did not run

Post by HATHAL »

jon
I in need for the contact between the pocket pc from Bluetooth to computer
Sending a file represented or received a file
I testing all fwppc sources the available and did not run
Do there is solution
Best Regards
HATHAL
User avatar
Jon Munro
Posts: 42
Joined: Sun Oct 09, 2005 11:47 am
Location: Brisbane Australia
Contact:

Post by Jon Munro »

Hathal,
Have you considered ActiveSync or other serial comms program with Bluetooth? Possibly less painful. I only need a few basic functions.
regards, saludos
User avatar
HATHAL
Posts: 77
Joined: Tue Nov 15, 2005 3:38 pm
Location: The Kingdom Saudi Arabia -Riyadh
Contact:

Post by HATHAL »

Jon Munro wrote:Hathal,
Have you considered ActiveSync or other serial comms program with Bluetooth? Possibly less painful. I only need a few basic functions.
regards, saludos
jon
I want function with Fwppc source
Best Regards
HATHAL
User avatar
Jon Munro
Posts: 42
Joined: Sun Oct 09, 2005 11:47 am
Location: Brisbane Australia
Contact:

Post by Jon Munro »

Hathal,
Define a single port with mode 0xC0000000 to get 'read-write'. You may find that 'nChr := bin2l( ReadByte( hIn ) )' will return single characters (as asc value) from data received. 'BillSerialMonitor' (freeware) from www.symcod.com is very useful for testing. Still testing comms functions...
regards
User avatar
Raymond Fischbach
Posts: 48
Joined: Sun Oct 30, 2005 9:29 am
Location: Belgium
Contact:

Post by Raymond Fischbach »

Jon Munro wrote: I've grafted fragments of FWPPC 'comm.c' into parts of Harbour Telepathy (port by Luiz Rafael Culik Guimaraes) and have a working FWPPC test program that reads from a barcode scanner and can send acks, etc. Nearly there...
Regards and happy and successful 2006 to all :-)
Hello Jon,

I need to read a bluetooth GPS receiver from a pocket PC.
Having used the sample code that you posteed earlier, i reach the same point as you were : I get a handle but cannot receive any message.

Could you please share your experience and tell me what I still need to do. A code snippet would be greatly appreciated.

Many thanks in advance.
Raymond Fischbach
www.mouches.org
User avatar
Jon Munro
Posts: 42
Joined: Sun Oct 09, 2005 11:47 am
Location: Brisbane Australia
Contact:

Post by Jon Munro »

Raymond,
The FWPPC comms functions work well, for example:

#define GENERIC_READ 0x80000000
#define GENERIC_WRITE 0x40000000
#define GENERIC_REWRITE 0xC0000000
#define OPEN_EXISTING 3
#define FILE_ATTRIBUTE_NORMAL 0x00000080
...
...
...
STATIC FUNCTION OPENCOMM( nPort )
// Open port for read/write
local hPort
hPort := CreateFile( "COM"+ltrim(str(nPort))+":",;
GENERIC_REWRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL )
if hPort == -1
MSGALERT("Cannot open port")
return -1
endif
Return hPort

...
...
// Read a character from comm port handle hPort
cChr := Chr(ReadByte( hPort ))

...
...
// Write a character to comm port handle hPort
WriteByte( hPort, Asc(cChr))

Please see my other posts on related issues with available ports via the emulator and faults with PPC2003 emulator. Antonio's code is the best! I use it to read and talk to a bluetooth barcode and possibly RFID scanners.
Just one character at a time.
hth
User avatar
Raymond Fischbach
Posts: 48
Joined: Sun Oct 30, 2005 9:29 am
Location: Belgium
Contact:

Post by Raymond Fischbach »

Many thanks, I will give it a try.
I need to read complete messages but I am sure this is not a problem as long as I can read a character.


Best Regards,
Raymond
Raymond Fischbach
www.mouches.org
User avatar
Raymond Fischbach
Posts: 48
Joined: Sun Oct 30, 2005 9:29 am
Location: Belgium
Contact:

Post by Raymond Fischbach »

Thanks for the info.
Based on it I have been able to get the data from a Btooth GPS.

I still have a problem to get the data from a serial one. I can read the serial GPS but I only get invalid data.

Here is my com port opening :

Code: Select all

STATIC FUNCTION OPENCOMM(nPort)
// Ouvrir le port en lecture
LOCAL hPort

hPort := CreateFile( "COM"+ltrim(str(nPort))+":",;
            GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL )
IF hPort == -1
   MSGALERT("Impossible d'ouvrir le port")
ENDIF

RETURN hPort
nPort comtains 8 for a Btooth and 1 or 2 for the serial port.

I wonder if the problem is not due to a bad com port setting (like a bad baud rate).

I could not find the documentation of the "CreateFile" function. Can you tell me where to look ?

Many thanks,
Raymond Fischbach
www.mouches.org
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

Raymond Fischbach wrote:I could not find the documentation of the "CreateFile" function. Can you tell me where to look ?
On the MSDN.

EMG
Post Reply