.NET Components for Mobility

WinCE serial port problem

Last post 07-05-2009 2:41 PM by alanjmcf. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 04-28-2009 7:37 AM

    • drjoju
    • Top 500 Contributor
    • Joined on 04-28-2009
    • Posts 5

    WinCE serial port problem

     Hello,

    I have Wince 6 device that connects with medical devices with bluetooth and SPP.

    I do the DiscoverDevices and I can see all of them. The next step is make the pairing but all the medical devices has pin "0000". I select one of the devices and I do the next code:

    BluetoothDeviceInfo ba = (BluetoothDeviceInfo)listBox3.SelectedItem;
    BluetoothClient client = new  BluetoothClient();

    client.Authenticate = true;
    client.Encrypt = true;
    client.SetPin(ba.DeviceAddress, "0000");

    BluetoothEndPoint BTEndPoint;
    Guid spguid = BluetoothService.SerialPort;
    BluetoothAddress BTAddress;
    BTAddress = ba.DeviceAddress;
    BTEndPoint = new BluetoothEndPoint(BTAddress, spguid);

    client.Connect(BTEndPoint);

     

    The device blue light says me that I'm connected but after some time waiting a message says me "No connection could be made because the target machine actively refused it"

     I know the devices works well because I read data from an application in the PC and from a mobile application in J2ME and now I want to port the code to Wince.

     Please can anyone says me what I doing wrong?

     Thanks in advance.

    drJoju
  • 04-28-2009 8:45 AM In reply to

    Re: WinCE serial port problem

    Try BluetoothSecurity.PairRequest and then the connect separately.  Does it work then?
    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 04-28-2009 1:23 PM In reply to

    • drjoju
    • Top 500 Contributor
    • Joined on 04-28-2009
    • Posts 5

    Re: WinCE serial port problem

     Hi,

     thanks for the response. I have some news. In fact I resolve the problem but I don't know why.

     In my WinCE device I have a Belkin bluetooth dongle and I do all the application development with it but as I say it doesn't work. Today after send the post I change the Belkin dongle for another one (Vivancos bluetooth dongle) and IT WORKS!!.

    I think the stack suported for both dongles are different. Is this possible?

    My next step is send commands with a virtual serial port. Any suggestions?

     

    Thanks in advance

     

     

    drJoju
  • 04-29-2009 4:11 AM In reply to

    Re: WinCE serial port problem

    Do you really need the virtual serial port??  Just use the connection you've just made:

       ... ...
       client.Connect(BTEndPoint);
       //
       Stream peer = client.GetStream(); // NetworkStream really
       peer.Read/Write... ...
       peer.Close();

    For more see the "Bluetooth Serial Ports" section in the user's guide (in the release or at http://www.alanjmcf.me.uk/comms/bluetooth/32feet.NET%20—%20User’s%20Guide.html)

    Note if you do need to use a virtual serial port, then remember to close that connection first or it'll block the serial port -- Bluetooth allows only one connection to each service.

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 04-29-2009 4:24 AM In reply to

    • drjoju
    • Top 500 Contributor
    • Joined on 04-28-2009
    • Posts 5

    Re: WinCE serial port problem

     Hi Alan,

     

    thanks. Yes you are right. I test both solutions and now all works!

     

    Another question. I see in the forum that some people has a problem when the serial port is not closed properly. No  I have the same problem and I don't see a good solution. For example when I do the CreateClient I recover the COM9 them I debug the application and close abruptly the connection. I see that the COM9 remains opened. Them I execute another time the application and I can't recover any port. I read in the forum that I need to reset the device. Is this necessary? Exists another solution for example cleaning the registry or something like this?

     

    Thanks another time

    drJoju
  • 07-03-2009 7:58 PM In reply to

    • JCosta
    • Not Ranked
    • Joined on 07-03-2009
    • Posts 1

    Re: WinCE serial port problem

     That is my question too!!

     Alan, please can you answer that?

     And thank you for all your work =)

  • 07-05-2009 2:41 PM In reply to

    Re: WinCE serial port problem

    What was the question?  About the port staying open?  I very very rarely use virtual serial ports so I'm not really an expert.  So this is "open" as in using System.IO.Ports.SerialPort and you COM9 still exists but can't be opened because the old SerialPort is still active?

    That's a problem in that class I suppose.  Have you checked the list of bugs at http://connect.microsoft.com (NETCF doesn't have the SafeHandle/CriticalFinalizerObject that the full CLR has so that maybe the reason, but I though the native HANDLE to the port would have been closed when the process exited however...)

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
Page 1 of 1 (7 items)
Copyright © 2001-2010 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.