Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10

Re: Bluetooth stream to read and write to (SPP/Obex)

Me again too :-)

 

Yes, go to this page: https://developer.blackberry.com/blackberry10devalpha/devalpha_update.html

 

Make sure you pick the loader for your model which you can see in Settings-About-General.

 

All the best

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
a-m
Contributor
a-m
Posts: 19
Registered: ‎07-22-2013
My Device: Z10

Re: Bluetooth stream to read and write to (SPP/Obex)

Okay ... now I have a brandnew QNX with 10.2 and on my BB device the firmware is updated to 10.2, too.

I tried my code with "version 1" (ssize_t read (int fildes, void* buf, size_t nbyte) instead of fopen) again, but the outcome is the same as before updating to 10.2.

But I found something out and I have to correct myself a little bit: I wasn't able to read just one byte, I read more than one.
So here again my reading-loop (reduced):

 

int readlen;
char tempbuff[1];

while (m_sppFD>= 0)  // m_sppFD is the file descriptor for my digital pen
{
    readlen = read(m_sppFD, tempbuff, 1);
    if (readlen >0)
    {
       opCode = *tempbuff;
if(opCode == OBEX_OP_CONNECT)
       {
                    handleConnect(length, deviceDesc);
        }
} else { break; } }

 

The handleConnect method (which is called and run through):

 

void ObexSession::handleConnect(int length, int deviceDesc)
{
    	// some more reading -> seems to work

        // now writing -> seems to fail
        int written = write(deviceDesc, (char*) OBEX_SUCCESS, 1);   
// OBEX_SUCCESS defined in header as static const char OBEX_SUCCESS = 0x20; // more writing }

Before, I didn't have the 'written'-variable and therefore didn't know that obviously nothing was written (write returns -1).

There is no error and the app continues, but I strongly suspect, that I can't read any more bytes from the bluetooth stream because the pen is waiting for an answer which is not coming.

How should I call the write method?

Do you have a hint?

Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10

Re: Bluetooth stream to read and write to (SPP/Obex)

I haven't forgotten you.... bear with me and I'll get back to you :-)

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
a-m
Contributor
a-m
Posts: 19
Registered: ‎07-22-2013
My Device: Z10

Re: Bluetooth stream to read and write to (SPP/Obex)

Thank you :-)

I found out today that some documentation sites have disappeared from the BlackBerry Developer Website (for example information about ssize_t read (int fildes, void* buf, size_t nbyte)).
But there was something new(?): The QBluetoothSocket (http://developer.blackberry.com/native/reference/cascades/qbluetoothsocket.html#function-readdata-da...
Should I try using that?
But I haven't found any code samples or more documentation on that. So I would be glad if you'd have something for me (either using the read-method or the new QBluetoothSocket).

In the meantime I will experiment with QBluetoothSocket.

Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10

Re: Bluetooth stream to read and write to (SPP/Obex)

I haven't used it myself (yet) but the new Qt class looks really nice. If I were you and my application was not needed before 10.2 then I would use it too.

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10

Re: Bluetooth stream to read and write to (SPP/Obex)

[ Edited ]

If write returns -1 then there has been an error.

 

See http://pubs.opengroup.org/onlinepubs/000095399/functions/write.html

 

You should be able to find out why by looking at the errno value and its associated description.

 

    // set errno to 0 before your call
    errno= 0;
    
    // make your call
    int written = write(deviceDesc, (char*) OBEX_SUCCESS, 1);
    
    // log the result
    qDebug() << "XXXX errno=(" << errno<< ") :" << strerror(errno);

 

Give this a try and let me know what you discover.

 

By the way I tested the bluetoothsppchat application that you've used as the basis for your code just in case there was a problem with it and it worked perfectly for me from a Bluetooth SPP point of view. I did find what I consider a small bug in that the Send key did not work (you had to touch the screen away from the Text Field to trigger the writing of the text you had entered) so I've fixed this and submitted a pull request to Git Hub and so you should see this new code there soon.

 

In case you need this change for your testing, all I did was change the SPPChat.qml file and add the onSubmitted event handler inside the input element of the TextField control:

 

                input {
                    submitKey: SubmitKey.Send
                    
                    onSubmitted: {
                        if (text.length > 0) {
                            _btController.chatManager.sendSPPMessage(text);
                            textInput.text = ""
                        }
                    }
                }

 

 Also I was wondering how you are setting the deviceDesc variable which should presumably contain the same file descriptor as you are using when reading.

 

Let me know how this goes.

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
a-m
Contributor
a-m
Posts: 19
Registered: ‎07-22-2013
My Device: Z10

Re: Bluetooth stream to read and write to (SPP/Obex)

I am feeling very stupid - but again I'm stuck.

 

As I said, I wanted to try out the QBluetoothSocket, but if I'm doing that

 

#include <QtConnectivity/QBluetoothSocket>

 I get the following error message:

 

../../../../bbndk_10_2/target_10_2_0_339/qnx6/usr/include/qt4/QtConnectivity/qbluetoothsocket.h:45:29: fatal error: qmobilityglobal.h: No such file or directory

 

Am I missing some library include or am I building for the wrong target (tried out both BB Native SDK 10.2 Beta 1 and Use Global (BB Native SDK 10.2))?

 

Now I'll give up trying bluetooth connection via app for the moment since we need something working and I'll try out picking the bluetooth files directly from the download folder. It's kind of ugly because you always have to accept the incoming file manually but I can't think of a better solution.

I saw that the documentation sites about accessing the filesystem on BB10 have also disappeared but maybe I find some information elsewhere.

 

Anyway - if there is something you could tell me about reading from a bluetooth stream directly, I would be glad.

Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10

Re: Bluetooth stream to read and write to (SPP/Obex)

Don't feel stupid. I reserve that right for myself :-)

 

It's not obvious. You need to add the following to the project's .pro file:

 

CONFIG += mobility
MOBILITY += connectivity

This is documented here:

http://developer.blackberry.com/native/documentation/cascades/getting_started/tools/build_and_run.ht...

 

You'll see it in the table entry for QtConnectivity.

 

Meanwhile I did respond to the original question about reading/writing with the FD.

 

 

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
a-m
Contributor
a-m
Posts: 19
Registered: ‎07-22-2013
My Device: Z10

Re: Bluetooth stream to read and write to (SPP/Obex)

Ok - thanks. I thought I was missing something like that but couldn't find it out ...

 

So now I have two more things to investigate ... I keep trying and thank you very much so far!

Please use plain text.
a-m
Contributor
a-m
Posts: 19
Registered: ‎07-22-2013
My Device: Z10

Re: Bluetooth stream to read and write to (SPP/Obex)

It's me again :-)

I didn't work on that project a long time due to different reasons. But a few weeks ago it became important once more. I order to have a working "router" for pendata as quickly as possible, I implemented an app which doesn't receive the bluetoothstream directly but picks the pendata-files from the phone folder in which they are stored by default.

But still our goal is to implement a way to receive the bluetoothstream directly. So I updated my NDK and my Z10 and debugged my code from last year again - with the same results like then.

 

I am not sure, if I tested the above mentioned errno thing then, but now I did -> errno = 14 (which apparently means "bad address").

 

Here comes the relevant code again:

 

void ObexSession::handleConnect(int length, int deviceDesc)
{
    	char tempbuff[1];
    	read(deviceDesc, tempbuff, 1);

        // more reading

        // now writing -> failing
        int written = write(deviceDesc, (char*) OBEX_SUCCESS, 1);   
        // OBEX_SUCCESS defined in header as static const char OBEX_SUCCESS = 0x20;

        // more writing
}

 

Obviously deviceDesc is a "bad address", if written to, but is working properly if read from? But why? I thought that reading from and writing to the same address (deviceDesc) would make sense. Am I wrong?

 

Please use plain text.