Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Please Help Me

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please Help Me

    I wrote this program so I can use it on my LG KS360 cell phone, so I will be able to control my rc car via thru bluetooth, but i dont know what wrong with it, because it won't work properly on the J2ME program so I can put it on my cell phone. Can someone please tell me what I did and wrong and how I can fix it...

    import appuifw
    # import the module socket
    import socket
    import e32
     
    # function that handles the bluetooth connection:
    def bt_connect():
        global sock
        # create a bluetooth socket
        sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
        target=''# here you can give the bt address of the other mobile if you know it
        if not target:
            # scan for bluetooth devices
            address,services=socket.bt_discover()
            print "Discovered: %s, %s"%(address,services)
            if len(services)>1:
                choices=services.keys()
                choices.sort()
                # bring up a popup menu and show the available bt devices for selection
                choice=appuifw.popup_menu([unicode(services[x])+": "+x
                                            for x in choices],u'Choose port:')
                target=(address,services[choices[choice]])
            else:
                target=(address,services.values()[0])
        print "Connecting to "+str(target)
        # connect to the serial port of the PC
        sock.connect(target)
        return sock
        print "OK."
     
    def recieve():
        data=sock.recv(1)
        if data=="1":
            appuifw.note(u"LED on","info")
        elif data=="0":
    	appuifw.note(u"LED off","info")
     
    def recieve():
        data=sock.recv(2)
        if data=="1":
            appuifw.note(u"Light on","info")
        elif data=="0":
    	appuifw.note(u"Light off","info")
     
     
    def bt_send_data1():
        bt_connect()
        sock.send("1")
        receive()
     
    def bt_send_data2():
        bt_connect()
        sock.send("0")
        receive()
     
    def bt_send_data3():
        bt_connect()
        sock.send("1")
        receive()
     
    def bt_send_data4():
        bt_connect()
        sock.send("0")
        receive()
     
     
    def quit():
        print"socket closed"
        sock.close()
        app_lock.signal()
     
    app_lock=e32.Ao_lock()
     
    appuifw.app.menu=[(u"LED on",bt_send_data1),
    		  (u"LED off",bt_send_data2),
                      (u"Light on",bt_send_data3),
    		  (u"Light off",bt_send_data4),
    		  (u"Exit", quit]
     
    appuifw.app.exit_key_handler = quit
    app_lock.wait()
     
     
    def exit_key_handler():
        script_lock.signal()
        appuifw.app.set_exit()
     
    appuifw.app.title = u"Smart home"
     
    script_lock = e32.Ao_lock()
     
    appuifw.app.exit_key_handler = exit_key_handler()
     
     
    script_lock.wait()
    Last edited by helloworld922; January 24th, 2011 at 03:15 AM.

  2. #2
    Junior Member
    Join Date
    Jan 2011
    Posts
    14
    Thanks
    0
    Thanked 4 Times in 3 Posts

    Default Re: Please Help Me

    Sorry if I'm wrong, but that looks like Python, not Java. You'll need to go elsewhere for help on that.

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help Me

    That is what I was afraid of. I am having a hard time designing a J2ME program that I can use on my LG KS360 that will allow me to control my remote control car via bluetooth... Can anyone please help me with designing the source code. Someone tried helping me and that program above was the result.

    So if anyone could help me please I would be grateful, I really need it...

    Thanks...

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Please Help Me

    The above code is not Java im afraid.

    Wireless Application Programming with J2ME and Bluetooth
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.