FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour WriteComm()
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: WriteComm()
Posted: Sat Feb 22, 2014 10:04 AM
Jeff,

Jeff Barnes wrote:I wonder if this could be because the COM ports I am working with are Bluetooth Serial Ports??????


I'm with James. I know nothing about Bluetooth, sorry. That could be the problem.

EMG
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: WriteComm()
Posted: Sun Feb 23, 2014 12:30 AM

In device manager the bluetooth com ports are listed as:

"Standard Serial over Bluetooth link (COM4)"

Is there any other way to send data to a serial port?

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: WriteComm()
Posted: Sun Feb 23, 2014 02:59 PM
Jeff,

"Standard Serial over Bluetooth link (COM4)"


This still doesn't answer my question, are these standard serial ports with a bluetooth device plugged into them to send/receive bluetooth, or are they special serial ports?

If they are standard serial ports and when there is nothing plugged into them, then they should act like standard serial ports. And you are trying to test them without anything plugged into them right?

If they are special serial ports that handle bluetooth without anything plugged into them and they also function as standard serial ports with something plugged into them, then they may be a whole different beast.

When I do a Google search it appears that there are both kinds of serial/bluetooth systems, although I could be wrong as the descriptions I found were very vague.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: WriteComm()
Posted: Sun Feb 23, 2014 04:57 PM

As far as I know, they act as standard serial ports.
The device itself, communicates over bluetooth via a typical serial connection.

What I am trying to do is give the user the ability to "search" for the device.

I check windows registry to see what available com ports there are.
Then I want to be able to send the connection command (D8) to the device.
If I get a reply (06) the device has been found. If not, it should "timeout" and then move to the next com port in the list.

It will not "timeout" when it sends the command to a com port that has nothing paired to it.

It would be nice if WriteComm() had a timeout parameter :(

I remember trying HBCOMM before (quite a while ago) but I was not able to get it working.
I'd try it again but I can't locate hbcomm files.

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: WriteComm()
Posted: Sun Feb 23, 2014 06:52 PM
Jeff,

As far as I know, they act as standard serial ports.


Ok, if they are, then the problem has nothing to do with the bluetooth aspect. If I understand you correctly, when you run the program on a standard serial port with nothing connected to it, the program locks up. It doesn't for me or Enrico. So, there is something different about your hardware, OS, or serial port driver. Those are the only possibilities I can think of.

If I were you I would first try on another PC with a known standard serial port.

This comment of yours still bothers me:

Code (fw): Select all Collapse
I will have to try this on a pc with a standard com port and see if it makes any difference although that won't solve my problem


This is indicating that the PC you are using doesn't have a standard serial port. And in another comment you made you said, "As far as I know, they act as standard serial ports." So, are they just standard serial ports, or are they not?

From the searching I did previously, "bluetooth serial" is just a bluetooth adapter that plugs into a serial port. This would be similar to a WiFi adapter plugged into a USB port. I don't know why it is referred to as "bluetooth serial" rather than just a "bluetooth adapter." They don't call it "WiFi USB," it is just a WiFi adapter.

If might help if we could clarify this.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: WriteComm()
Posted: Sun Feb 23, 2014 07:14 PM
Jeff,

Jeff Barnes wrote:It will not "timeout" when it sends the command to a com port that has nothing paired to it.

It would be nice if WriteComm() had a timeout parameter :-)


WriteComm() does time out graciously. :-)

Your problem starts back to SetCommDcb(). It fails, so WriteComm() freezes.

EMG
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: WriteComm()
Posted: Sun Feb 23, 2014 07:32 PM

When I say I want to try it on a pc with a "standard serial port" I mean a physical com port with the DB9 connector.

I say "As far as I know" because I use the same code when connecting to a hardwired device.
When the device is on the com port (either hardwired or bluetooth) WriteComm() works just fine.

The bluetooth serial is not a bluetooth device connected to a serial port (DB9) but rather a bluetooth adapter (USB) that communicates via serial data.
As far as the computer is concerned the bluetooth COM port should be no different than a physical (DB9) COM port.

I hope that clears thing up :)

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: WriteComm()
Posted: Sun Feb 23, 2014 07:46 PM
Enrico,

Now I'm confused...

I was doing the following and if the device is available it worked:
Code (fw): Select all Collapse
BuildCommDcb( "COM4:9600,N,8,1", @cDcb )


Now I try it this way and BuildCommDcb will show the error message but still connects when the device is available.
How can it fail but still read/write to the com port ????
Code (fw): Select all Collapse
IF ! BuildCommDcb( "COM4:9600,N,8,1", @cDcb ) 
    MsgInfo("BuildCommDCB Error")
ENDIF


I realize that if I use the "IF ! BuildCommDcb....." I should exit the routine but why does it work if BuildCommDcb fails?????

Is there something wrong with my BuildCommDcb statement?
Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: WriteComm()
Posted: Sun Feb 23, 2014 09:28 PM

Jeff,

Sorry, I meant:

"Your problem starts back to SetCommState(). It fails, so WriteComm() freezes."

EMG

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: WriteComm()
Posted: Sun Feb 23, 2014 09:30 PM
Jeff,

Jeff Barnes wrote:Now I try it this way and BuildCommDcb will show the error message but still connects when the device is available.
How can it fail but still read/write to the com port ????
Code (fw): Select all Collapse
IF ! BuildCommDcb( "COM4:9600,N,8,1", @cDcb ) 
    MsgInfo("BuildCommDCB Error")
ENDIF


I realize that if I use the "IF ! BuildCommDcb....." I should exit the routine but why does it work if BuildCommDcb fails?????

Is there something wrong with my BuildCommDcb statement?


This is strange indeed. Are you using a very old version of FWH?

EMG
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: WriteComm()
Posted: Sun Feb 23, 2014 09:36 PM

Enrico,

According to his signature line, he is using:

(FWH 12.01, xHarbour 1.2.1, Bcc582)

So, it is two years old.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: WriteComm()
Posted: Sun Feb 23, 2014 09:54 PM

Jeff,

OK, now I get it. You are checking USB ports NOT serial ports.

I didn't even know you could use COM addresses for that. I have never done any communication with USB ports via FWH before, so can't be of much help with this.

I do note that my two USB ports show under a different category than my single comm port in the Control Panel. If my USB ports have a COM address, how would I find out what they are. My serial port is listed as COM1. Do I assume that the USB ports are COM2 and COM3?

OK, I tried the test program on COM2 and COM3 it gives the "SetCommState Error" on both attempts. Note that I have a wireless mouse adapter on one of the USB ports. The other USB port is empty. So, I am still not getting a hang.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: WriteComm()
Posted: Sun Feb 23, 2014 10:04 PM

Jeff,

Here is an old thread discussing issue with USB comms which may be of help.

viewtopic.php?f=3t=20028p=106071hilit=usb#p106071

James

&&&

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: WriteComm()
Posted: Sun Feb 23, 2014 10:16 PM
James, Jeff,

James Bott wrote:Enrico,

According to his signature line, he is using:

(FWH 12.01, xHarbour 1.2.1, Bcc582)

So, it is two years old.

James


Older, but probably not so old.

EMG
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: WriteComm()
Posted: Sun Feb 23, 2014 10:22 PM
James,

I'm not trying to connect to a usb port.

Some laptops have built-in bluetooth and some use a usb bluetooth adapter. Similar idea to a usb wifi adapter.
As in the case of a usb wifi adapter, the wifi is seen as a regular wifi connection. Same applies to the com ports via bluetooth.

You are correct with my version of FWH ... 1201.
What version are you running?

James, when you have a chance, could you please compile the following with your version of FWH.
Also, can you compile the same thing with COM3 as well.

Code (fw): Select all Collapse
#include "Fivewin.ch"

Function FindCom()
   LOCAL cDCB, nComm, cInit

   nComm:= OpenComm("COM4", 16384,16384 )

   IF nComm < 0
        MsgInfo("Error opening port")
        RETURN NIL
   ENDIF

   cInit := "COM4:9600,N,8,1"
   IF BuildCommDcb( cInit, @cDcb )
       MsgInfo("BuildCommDcb Error")
       CloseComm(nComm)
       Return Nil
   ENDIF
    
   IF ! SetCommState(  nComm, cDcb )
       MsgInfo("SetCommState Error")
       CloseComm(nComm)
       RETURN NIL
   ENDIF

   MsgInfo("Just before writing to com port")
   IF ! SendStr( nComm, "D8" )
      MsgInfo("No Connection but passed problem with locking up")     //never gets this far
   ENDIF
   MsgInfo("After writing to com port")
Return Nil

STATIC FUNCTION SendStr( nComm, cString )
RETURN WriteComm( nComm, cString ) = LEN(cString)
Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)