×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    15

    bluetooth printing... wad's wrong with my code? pls help..

    import javax.bluetooth.*;
    import javax.microedition.io.*;
    import java.io.*;

    class printing implements DiscoveryListener {
    private DiscoveryAgent discoveryAgent;
    private RemoteDevice[] remoteDevices;
    private UUID[] uuidSet;
    private String serviceUrl;

    public printing() {
    try {
    LocalDevice localDevice = LocalDevice.getLocalDevice();
    discoveryAgent = localDevice.getDiscoveryAgent();
    discoveryAgent.startInquiry(DiscoveryAgent.GIAC, this);
    } catch (Exception e) {
    System.out.println(e);
    }
    }

    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
    try {
    // Get Device Info
    System.out.println("Device Discovered");
    System.out.println("Major Device Class: " + cod.getMajorDeviceClass() + " Minor Device Class: " + cod.getMinorDeviceClass());
    System.out.println("Bluetooth Address: " + btDevice.getBluetoothAddress());
    System.out.println("Bluetooth Friendly Name: " + btDevice.getFriendlyName(true));

    // Search for Services
    uuidSet = new UUID[1];
    uuidSet[0] = BtPrinting.RFCOMM_UUID;
    int searchID = discoveryAgent.searchServices(null,uuidSet,btDevice,this);
    } catch (Exception e) {
    System.out.println("Device Discovered Error: " + e);
    }
    }

    public void inquiryCompleted(int discType) {
    System.out.println("InquiryCompleted");
    }

    public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
    System.out.println("ServicesDiscovered");

    // in this example there is only one service
    for(int i=0;i<servRecord.length;i++) {
    serviceUrl = servRecord[i].getConnectionURL(0,false);
    }
    }

    public void serviceSearchCompleted(int transID, int responseCode) {

    if(responseCode == SERVICE_SEARCH_ERROR)
    System.out.println("SERVICE_SEARCH_ERROR\n");

    if(responseCode == SERVICE_SEARCH_COMPLETED) {
    System.out.println("SERVICE_SEARCH_COMPLETED\n");
    System.out.println("Service URL: " + serviceUrl);

    StreamConnection conn = null;
    try {
    String msg = "hello";
    conn = (StreamConnection)Connector.open(serviceUrl);
    OutputStream output = conn.openOutputStream();
    // output.write(msg.length());
    output.write(msg.getBytes(),0,msg.length());
    output.flush();
    output.close();

    System.out.println(msg);
    System.out.println(BtPrinting.readData(conn));


    } catch (Exception ex) {
    System.out.println(ex);
    } finally {
    try {
    conn.close();
    } catch (IOException ioe) {
    System.out.println("Error Closing connection " + ioe);
    }
    }
    }

    if(responseCode == SERVICE_SEARCH_TERMINATED)
    System.out.println("SERVICE_SEARCH_TERMINATED\n");

    if(responseCode == SERVICE_SEARCH_NO_RECORDS)
    System.out.println("SERVICE_SEARCH_NO_RECORDS\n");

    if(responseCode == SERVICE_SEARCH_DEVICE_NOT_REACHABLE)
    System.out.println("SERVICE_SEARCH_DEVICE_NOT_REACHABLE\n");
    }
    }


    It seems that i am able to make the connection with the bluetooth printer, as
    there is message prompt me yes/no to make allow application to make a client
    bluetooth connection, but the message i sent is not printed out

  2. #2
    Regular Contributor
    Join Date
    Jul 2005
    Location
    Omaha, US
    Posts
    129

    Re: bluetooth printing... wad's wrong with my code? pls help..

    Even I am new to such kind of programs. It sounds interesting... How r u requesting the printer to print the text sent?? May be the pairing successfull but printer may not know that it has to print the text you have sent.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    15

    Re: bluetooth printing... wad's wrong with my code? pls help..

    the text is sent through outputstream.. so i suppose the printer should print the text in the outputstream... am i wrong? or how can i call the printer to print the text?

  4. #4
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: bluetooth printing... wad's wrong with my code? pls help..

    Hi Jazsh,

    I don't know which printer you're using but i just wanted to let you know that the resource below may help you. I haven't had the opportunity to implement that yet, though.

    Java Driver for Brother MW-140BT mobile bluetooth printer
    http://www.hcilab.org/documents/tuto...her/index.html

    Please let's know your findings, ok?

    BR,

    Juarez Jr

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    15

    Re: bluetooth printing... wad's wrong with my code? pls help..

    Hi Juarez Jr,

    Thks for the example link, it is very useful..
    From the example u have give, i know tt the i have to send the data in packet format which is recognised by the printer. I have successfully send the inquiry status packet data from printer and get a response.. But when i trying to send printing data, the printer never prints..

    any idea what would be the problem?

  6. #6
    Registered User
    Join Date
    Jan 2007
    Posts
    6

    Re: bluetooth printing... wad's wrong with my code? pls help..

    hi ,
    could anyone tell me . which UUID i hv to pass to find the printer services.
    i can find any bluetooth device from my application.
    i m using nokia 6670. by looking jazch code snippet i got much idea.
    but i cant get uuidSet[0] = BtPrinting.RFCOMM_UUID;

    from whr did he get UUId.
    i hv already tried for uuids[0] = new UUID(0x1002);
    uuids[0] = new UUID(0x0003);
    uuids[0] = new UUID(0x0001);
    and even if i get the service , how would printer came to know that he has to print data passed by 6670. my printer is epson - lq- 1070 ,i m using BT-PRT-E03F523 USB Bluetooth Adaptor . onemore thing - i hv download & install Nokia S60 emulator sdk for 2nd edition with feature pack 1. but my Netbeans 5.0 unable to find S60 platform so i cant work on these emulators.
    i m working on WinXp SP2.
    please Reply....

    thanks..
    Sonia

  7. #7
    Registered User
    Join Date
    Jul 2005
    Location
    Bengaluru, India
    Posts
    747

    Re: bluetooth printing... wad's wrong with my code? pls help..

    First of all I'm not much aware of how the Java code will work with your BT stubs, basically I'm a Symbian C++ developer.

    Now if your doubts is on BT Service UUIDs, here are they:

    DirectPrinting - 0x1118
    ReferencePrinting - 0x1119
    DirectPrintingReferenceObjectsService - 0x1120
    ReflectedUI - 0x1121
    BasicPrinting - 0x1122
    PrintingStatus - 0x1123

    Get more information from here (may be a registration required to access):
    - Service discovery
    - Bluetooth specifications

  8. #8
    Super Contributor
    Join Date
    Dec 2005
    Location
    England,UK
    Posts
    1,600

    Re: bluetooth printing... wad's wrong with my code? pls help..

    Hi,
    The codes for BPP (Basic Print Profile) is at:-
    http://www.bluetooth.com/NR/rdonlyre...P_SPEC_V10.pdf

    Extending OBEX Object Push to Create a Minimal Basic Printing Profile Client
    http://whitepapers.silicon.com/0,390...000783q,00.htm

    There are several examples of programs but mainly require major re-write of the code and these examples may not work as they are untested.
    Jim

Similar Threads

  1. Bluelet - Rapid Bluetooth App Development (Free source)
    By huiben in forum Mobile Java General
    Replies: 4
    Last Post: 2008-07-25, 15:52
  2. Anybody know What´s wrong in the code below:
    By Léo in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2006-06-12, 07:16
  3. Help on Bluetooth Printing APIs
    By rajeshwari in forum Bluetooth Technology
    Replies: 2
    Last Post: 2006-01-17, 07:13
  4. What´s wrong with the code - Get Cellid
    By Léo in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2005-10-14, 07:57
  5. Bluetooth problem in Symbian C++ code
    By vardhman in forum Bluetooth Technology
    Replies: 0
    Last Post: 2005-01-02, 08:17

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×