Author Topic: How to create an incoming port  (Read 7434 times)

Offline vuelti

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
How to create an incoming port
« on: November 19, 2012, 01:23:53 PM »
Hi, my name is Jose Luis from Spain. I'm using wcl free edition to communicate with a robot that I'm building, using Spp. To communicate with it I'm using a bluetooth master module that uses SPP protocol in the robot side, and a SMC USB bluetooth dongle in the PC side, creating an incoming serial port using MS stack user interface. 

This is the main procedure (obviously simplified, I removed message dialogs and another things to make it more friendly). There are also the event handlers for wclauthenticator, send and receive handlers that I think are not necessary to show.

procedure TfmMain.btConnectClick;
 var   Radio: TwclBluetoothRadio;
begin
 Radio := GetSelectedRadio;
 if Assigned(Radio) then
 begin
  if wclClient.State <> csDisconnected then
    MessageDlg('Client is active', mtWarning, [mbOK], 0)
  else
      wclAuthenticator.Radio := Radio;
      wclShowError(wclAuthenticator.Open);
      wclClient.Transport := ctSerial;
       wclClient.SerialParams.Port :=17;  // This is the port that

Online Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3053
  • Karma: 1000
    • Soft Service Company
Re: How to create an incoming port
« Reply #1 on: November 19, 2012, 01:57:37 PM »
Hello,

With WCL you do not need any COM ports to communicate with Bluetooth device. Please, refer to BluetoothConnect (BluetoothClient) demo to find out how to use SPP over Bluetooth.

Offline vuelti

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: How to create an incoming port
« Reply #2 on: November 19, 2012, 02:47:59 PM »
Thanks, Mike. I have tried the demo, changing  wclClient.Transport := ctserial instead ctbluetooth; (with ctbluetooth the message popup shows "unable connect:error 43") . Clicking connect after selecting the robot MAC , popup window shows "Connected", but nothing more happens. The window that asks for PIN for pairing does not appear, and the remote module remains unpaired.

But the demo shows also a strange behaviour, when I click discover button, it discovers the robot bluetooth module, EVEN WITH THE ROBOT DISCONNECTED (??????), even the connect button shows "connected" when I click on it (that is impossible, the robot and the remote module are "OFF"). It also discovers my mobile phone after switching it of (??).

 PD: my last (and first) post was cutted, I don't know the reason. In that first post I told that I was able to connect, authenticate and communicate with the robot creating a virtual incoming port using the settings of the MS stack, setting this port with wclClient.SerialParams.Port  and then using wclauthenticate component with the PIN.

Thanks and regards.

Online Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3053
  • Karma: 1000
    • Soft Service Company
Re: How to create an incoming port
« Reply #3 on: November 19, 2012, 03:04:39 PM »
If you use ctSerial then WCL will work with COM ports instead of Bluetooth. Error 43 means WCL_E_TIMEOUT (Timeout appeared). MS remembers paired devices and shows them as discovered. To make sure device is available use IsInRange method of TwclBluetoothDevice class.

ctSerial forces serial port usage and of course it doesn't know about Bluetooth and about PIN and other BT things. To communicate with device use wclClient with ctBluetooth. Make sure you use valid service UUID to connect to your device. Pair with device (with calling Pair or TwclAuthenticator).

P.S. By the way, there is no Free WCL Edition. There is only Demo WCL which can be used for test purpose only.

Offline vuelti

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: How to create an incoming port
« Reply #4 on: November 20, 2012, 01:20:23 PM »
Ok, problem solved. First time, wclclient did not work because BT module in the robot side was configured as a "Master" (client), so I decided to use WCLserver instead, based on the bluetoothchatserver demo, and adding wclauthenticator . Now communication works like a charm. Last question: can I "read" data in the input buffer without using "ondata" event? I mean, can I poll the amount of data that is in the input buffer and then retrieve that data, using something like a "read" method? Thanks in advance.

 PD: I was wrong, I'm using demo version, not free version. My application is for hobbist purposes, nothing commercial. Thanks again.

Online Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3053
  • Karma: 1000
    • Soft Service Company
Re: How to create an incoming port
« Reply #5 on: November 20, 2012, 01:33:11 PM »
Hello,

Unfortunately no, WCL supports only async OnData when works as a server. However, WCL includes wclSyncClient which has Read method but only when WCL works as a client.

 

Sitemap 1 2 3 4 5 6 7 8 9