Hi,

I have done something similar with an Arduino and a cheap BT serial
module linked back to my laptop.  It was surprisingly easy, but here
are some observations.

Firstly, does it work at all?  It could be broken.

Make sure you have paired the device properly.  Next, try getting data
using a serial terminal (I use gtkterm).  If you can't get any data
that way then you need to sort that out first.  Check baud rates and
any special control characters that you might need.

Finally, in your own code, don't overlook the setup time to establish
the BT link.  The link will only come up when the rfcomm port is
opened.  So, you have to do that and wait.  Once you are done reading
data and close the port then the link is dropped.  There is probably
an LED on the barcode device to indicate the status of the link.
Maybe your software is timing out too soon after opening the port.

Best wishes,

Andrew



On 22/08/2013, dave <[email protected]> wrote:
> hi folks,
>
> I've been trolling the net looking for something to show me either as a
> complete app or as a howto so I can get a C/C++ program to download data via
>
> BT SPP (the device is a OPTICON 2002 barcode scanner).
>
> am happy for it to dump the barcodes to a file or have it redirected via a
> pipe so I can then read in the barcodes and once validated put them into a
> DB.
>
> I've found 1 app that does what I want via a USB connection and am thinkign
> I
> should be able to get a rfcomm setup and point the program to the port and
> have the same action happen, But as yet all attempts have failed.
>
> from all my reading this is the sequence needed to get a rfcomm up and
> running.
>
> from a terminal....
>
> sudo rfcomm connect/listen/watch/bind 0 <device mac address> channel
>      Found that for me thigns don't happen without using sudo.
>
> The I run my c app pulled from the web (which fails might i say).
>
> I type cs1504 /dev/rfcomm0 (using /dev/USB0 works by the way).
>
> I've found references to linking the rfcomm to a ttyS port and this has
> failed
> also.
>
> above mentioned app is a C++ app from https://github.com/dudochkin-
> victor/cs1504
>
> also got from a seperate website this tutorial program...
>
>
> gcc#include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/socket.h>
> #include <bluetooth/bluetooth.h>
> #include <bluetooth/hci.h>
> #include <bluetooth/hci_lib.h>
>
> int main(int argc, char **argv)
> {
>     inquiry_info *ii = NULL;
>     int max_rsp, num_rsp;
>     int dev_id, sock, len, flags;
>     int i;
>     char addr[19] = { 0 };
>     char name[248] = { 0 };
>
>     dev_id = hci_get_route(NULL);
>     sock = hci_open_dev( dev_id );
>     if (dev_id < 0 || sock < 0) {
>         perror("opening socket");
>         exit(1);
>     }
>
>     len  = 8;
>     max_rsp = 255;
>     flags = IREQ_CACHE_FLUSH;
>     ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));
>
>     num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
>     if( num_rsp < 0 ) perror("hci_inquiry");
>
>     for (i = 0; i < num_rsp; i++) {
>         ba2str(&(ii+i)->bdaddr, addr);
>         memset(name, 0, sizeof(name));
>         if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name),
>             name, 0) < 0)
>         strcpy(name, "[unknown]");
>         printf("%s  %s\n", addr, name);
>     }
>
>     free( ii );
>     close( sock );
>     return 0;
> }
>
> this app was an attempt for me to _TRY_ and figure out how i could actually
>
> connect to the BT device via SPP.
>
> I am sure I'm not understanding something very simple and what adds to the
> frustration is that I'm not a C/C++ programmer although I can get he gist of
>
> what is happening in places.
>
> if anyone could help me i'd appreciate it.
>
> Dave.
> _______________________________________________
> Linux-users mailing list
> [email protected]
> http://lists.canterbury.ac.nz/mailman/listinfo/linux-users
>
_______________________________________________
Linux-users mailing list
[email protected]
http://lists.canterbury.ac.nz/mailman/listinfo/linux-users

Reply via email to