.NET Components for Mobility

Connect to mobile by serial port

Last post 09-17-2008 7:20 AM by Andy Hume. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 09-12-2008 2:39 PM

    Connect to mobile by serial port

    Hello,

    I have a mobile phone and I can connect to it using bluetooth and browse its directorys using brecham.obex

    However, when I connect mobile phone to my computer using usb and try to connect to it, I receivethis: Unexpected OBEX response code: 0x00 (0).

     Brecham.Obex.ObexResponseException was unhandled
      Message="Unexpected OBEX response code: 0x00 (0)."
      Source="Brecham.Obex"
      StackTrace:
           at Brecham.Obex.ObexClientSession.CheckResponseCode(ObexResponseCode responseCode, ObexHeaderCollection headers, ObexResponseCode expected, ObexResponseCode[ acceptableExpected)
           at Brecham.Obex.ObexClientSession.WriteOneReadOneResponseIs(ObexCreatedPdu writePdu, Boolean isResponseToConnect, ObexResponseCode expected, ObexResponseCode[ acceptableExpected)
           at Brecham.Obex.ObexClientSession.WriteOneReadOneConnectResponseIs(ObexCreatedPdu writePdu, ObexResponseCode expected, ObexResponseCode[ acceptableExpected)
           at Brecham.Obex.ObexClientSession.Connect(ObexHeaderCollection headers)
           at Brecham.Obex.ObexClientSession.Connect(Byte[ target)

    Here is my code:

    port = new SerialPort("COM4");
    port.Open();

    Stream bs = port.BaseStream;
    session = new ObexClientSession(bs, UInt16.MaxValue);
    session.Connect(ObexConstant.Target.FolderBrowsing);  //This throws exception.

    COM4 description is: Sony Ericsson Device 116 USB WMC Data Modem

    I have tried it with COM6 (Sony Ericsson Device 116 USB WMC OBEX Interface

    but I'm getting IOException: System.IO.IOException: A device attached to the system is not functioning.

       at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
       at System.IO.Ports.SerialStream.EndWrite(IAsyncResult asyncResult)
       at System.IO.Ports.SerialStream.Write(Byte[ array, Int32 offset, Int32 count, Int32 timeout)
       at System.IO.Ports.SerialStream.Write(Byte[ array, Int32 offset, Int32 count)
       at Brecham.Obex.ObexClientSession.write(ObexCreatedPdu pdu)
       at Brecham.Obex.ObexClientSession.WriteOneReadOne(ObexCreatedPdu writePdu, Byte[& buffer, Int32& pduLength)
       at Brecham.Obex.ObexClientSession.WriteOneReadOneResponseIs(ObexCreatedPdu writePdu, Boolean isResponseToConnect, ObexResponseCode expected, ObexResponseCode[ acceptableExpected)
       at Brecham.Obex.ObexClientSession.WriteOneReadOneConnectResponseIs(ObexCreatedPdu writePdu, ObexResponseCode expected, ObexResponseCode[ acceptableExpected)
       at Brecham.Obex.ObexClientSession.Connect(ObexHeaderCollection headers)
       at Brecham.Obex.ObexClientSession.Connect(Byte[ target) 

     Any ideas?

    Thanks

     

    Filed under: , , ,
  • 09-14-2008 5:35 AM In reply to

    Re: Connect to mobile by serial port

    Well, for the first issue, a normal serial port to modem connection uses v.25ter, or is called v.250 these days?  Anyway, it's what we all know as the Hayes Compatible interface; using AT commands, ATDT 1234, ATH, and all that jazz.  So it won't speak OBEX then.  Some phones have a command that switches the connection to OBEX however, see http://www.alanjmcf.me.uk/comms/infrared/IrDA%20uses%20(brief).html#_Toc71546540  So try sending either “AT +CPROT=0” or “AT *EOBEX”, and on success start the OBEX session.

    As to the "OBEX" COM port, I don't know what's wrong there.  Perhaps the other COM port was open and it can only cope with one at a time?

    Andy 

  • 09-14-2008 7:25 AM In reply to

    Re: Connect to mobile by serial port

     Thank you Andy for your response. Sending “AT +CPROT=0” helped and I can connect to mobile phone.

    Let me ask you two more questions:

    Lets say a mobile phone is connected. How can I find out port number that it uses? (e.g COM4 in my previous post) In my post I used wmi to find the port but is it reliable? I think port description may contain words like Data, Modem and might not be mobile phone.

     Secondly, lets say a device that supports obex is connected to pc with usb. It might be any device such as mobile phone, mp3 player or even digital camera. How can I put arbitrary device into obex mode so that I explore it with your library? Will the above command work of all kind of device?

     Thanks.

  • 09-17-2008 7:20 AM In reply to

    Re: Connect to mobile by serial port

    I'm not an expert in that. :-')  OBEX yes, virtual serial ports on PCs no.  WMI sounds OK.  There's SerialPorts.GetPortNames(); I never remember whether (or when?) it returns a COMx name or a longer name, WMI's probably more useful.

    I don't know if you're aware of the new-ish USB CDC standards however.  That's the specifications for the way the serial ports were presented by your phone (USB WMC Data Modem, USB WMC OBEX Interface), USB WMC is a subset of the CDC spec.  See

    Maybe you can connect to the OBEX USB connection somehow with out the virtual serial port...

    Let me know what you find out.  I'll add a few words to the programmer's guide on serial ports/modem now, and could add something on USB if there's anything useful.

     

    On the second I don't know either.  I've only really played with phones and PDAs over Bluetooth and IrDA I've not much experience with other device types.  I never get to see enough non-MSFT mobile phones either to see how they are set up.   Maybe now they'll implement the WMC spec...  Previously I don't know.  Just use your favourite USB diagnostic software to see what enpoints the device has.  They generally all present themselves as a storage device (hard-drive), I don't know what other forms they implement too.

Page 1 of 1 (4 items)
Copyright © 2001-2008 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.