Page 1 of 1

Bluetooth serial port

Posted: Fri Dec 02, 2005 1:31 am
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

Posted: Fri Dec 02, 2005 12:31 pm
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 ?

Posted: Fri Dec 02, 2005 2:02 pm
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.

Posted: Fri Dec 02, 2005 2:33 pm
by Antonio Linares
Jon,

Please notice that you should use GENERIC_READ instead of GENERIC_WRITE.

Posted: Mon Dec 05, 2005 12:32 pm
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

Posted: Fri Jan 06, 2006 2:58 pm
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 :-)

I testing all fwppc sources the available and did not run

Posted: Fri Jan 06, 2006 5:00 pm
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

Posted: Sat Jan 07, 2006 1:41 pm
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

Posted: Sat Jan 07, 2006 8:14 pm
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

Posted: Sun Jan 08, 2006 3:22 pm
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

Posted: Mon May 01, 2006 7:06 pm
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.

Posted: Tue May 02, 2006 12:50 pm
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

Posted: Tue May 02, 2006 1:40 pm
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

Posted: Wed May 10, 2006 9:42 am
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,

Posted: Wed May 10, 2006 9:44 am
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