While I've been able to communicate with USB connected devices using ImageJ macros, serial extension and RXTX on my Mac (OX 10.6.8), I've not been able to communicate with a Bluetooth device that is paired to the host. Here's the main variant of the macro code I'm trying:
macro "Serial2UBW" { run("serial ext"); portsw = Ext.ports(); print(portsw); waitForUser("Hit OK..."); Ext.open("/dev/tty.RN42-AA9D-SPP", 9600,"DATABITS_8 STOPBITS_1 PARITY_NONE"); waitForUser("Hit OK..."); Ext.write("w"); wait(1000); data = Ext.read(); print(data); } Note that the first argument to Ext.open() (line 3) matches a previously paired item that lists in /dev. After this command, I see various devs being enumerated in the ImageJ status bar, followed by an "RN42-AA9D connected" indication in a Growl notification (even before issuance of the Ext.open() command. Once the Ext.open() command is issued (line 6), I get notification of a connection exception in the ImageJ status bar, even if I comment out the print(portsw) command (which only prints after a lengthy period). Subsequent Ext.anything() commands also result in further exceptions being displayed. I've yet to succeed in receiving (and probably sending) any data, even though this code is comparable to code that works in communicating with USB-connected devices (e.g. Arduino). The "waitForUser()" commands are an attempt to introduce various delays, in the hope that this would allow time for the connection to be made. Being a complete Bluetooth newbie, I don't have a good feel for how things should go. Any suggestions? Thanks. Bill Christens-Barry |
In my original posting on this topic, I meant to refer to the line
run("serial ext"); when I mentioned line 3 of my example code. Also, this line is actually line 2, not line 3. This is the command that seems to establish a connection. Sorry to have created confusion. Bill Christens-Barry |
In reply to this post by Bill Christens-Barry
Bill,
I would advise that you run a first macro that discovers ports and opens the serial port you need, and a second macro that reads or write to it. If you run the posted macro twice or more and never close your port then the Ext.open command fails because the port is already opened. The second macro also needs the run('serial ext'); statement. Jerome On Tue, Aug 16, 2011 at 5:04 AM, Bill Christens-Barry < [hidden email]> wrote: > While I've been able to communicate with USB connected devices using ImageJ > macros, serial extension and RXTX on my Mac (OX 10.6.8), I've not been able > to communicate with a Bluetooth device that is paired to the host. Here's > the main variant of the macro code I'm trying: > > macro "Serial2UBW" { > run("serial ext"); > portsw = Ext.ports(); > print(portsw); > waitForUser("Hit OK..."); > Ext.open("/dev/tty.RN42-AA9D-SPP", 9600,"DATABITS_8 STOPBITS_1 > PARITY_NONE"); > waitForUser("Hit OK..."); > Ext.write("w"); > wait(1000); > data = Ext.read(); > print(data); > } > > Note that the first argument to Ext.open() (line 3) matches a previously > paired item that lists in /dev. After this command, I see various devs being > enumerated in the ImageJ status bar, followed by an "RN42-AA9D connected" > indication in a Growl notification (even before issuance of the Ext.open() > command. > > Once the Ext.open() command is issued (line 6), I get notification of a > connection exception in the ImageJ status bar, even if I comment out the > print(portsw) command (which only prints after a lengthy period). Subsequent > Ext.anything() commands also result in further exceptions being displayed. > > I've yet to succeed in receiving (and probably sending) any data, even > though this code is comparable to code that works in communicating with > USB-connected devices (e.g. Arduino). The "waitForUser()" commands are an > attempt to introduce various delays, in the hope that this would allow time > for the connection to be made. > > Being a complete Bluetooth newbie, I don't have a good feel for how things > should go. Any suggestions? > > Thanks. > > Bill Christens-Barry > |
In reply to this post by Bill Christens-Barry
Jerome,
Thanks for your idea of splitting the serial functions into two macros. I have been using an Ext.close() command paired with each Ext.open() command, as you suggest, but didn't show it in the faultily edited listing I gave. Otherwise, I see that /var/lock/LK* files accumulate and interfere with further attempts. Splitting the macro into two separate macros, which each include run("serial ext"), allowed me to see that the serial connection remains open after the Ext.open(theDetails) command in a first macro that isolates this functionality. Still, I'm getting no evidence of successful comms via the Ext.write() and Ext.read() commands in what is now the second macro. Time to check using an oscilloscope. Bill > > Bill, > I would advise that you run a first macro that discovers ports and opens the > serial port you need, and a second macro that reads or write to it. If you > run the posted macro twice or more and never close your port then the > Ext.open command fails because the port is already opened. The second macro > also needs the run('serial ext'); statement. > > Jerome > > On Tue, Aug 16, 2011 at 5:04 AM, Bill Christens-Barry < > [hidden email]> wrote: > > > While I've been able to communicate with USB connected devices using ImageJ > > macros, serial extension and RXTX on my Mac (OX 10.6.8), I've not been able > > to communicate with a Bluetooth device that is paired to the host. Here's > > the main variant of the macro code I'm trying: > > > > macro "Serial2UBW" { > > run("serial ext"); > > portsw = Ext.ports(); > > print(portsw); > > waitForUser("Hit OK..."); > > Ext.open("/dev/tty.RN42-AA9D-SPP", 9600,"DATABITS_8 STOPBITS_1 > > PARITY_NONE"); > > waitForUser("Hit OK..."); > > Ext.write("w"); > > wait(1000); > > data = Ext.read(); > > print(data); > > } > > > > Note that the first argument to Ext.open() (line 3) matches a previously > > paired item that lists in /dev. After this command, I see various devs being > > enumerated in the ImageJ status bar, followed by an "RN42-AA9D connected" > > indication in a Growl notification (even before issuance of the Ext.open() > > command. > > > > Once the Ext.open() command is issued (line 6), I get notification of a > > connection exception in the ImageJ status bar, even if I comment out the > > print(portsw) command (which only prints after a lengthy period). Subsequent > > Ext.anything() commands also result in further exceptions being displayed. > > > > I've yet to succeed in receiving (and probably sending) any data, even > > though this code is comparable to code that works in communicating with > > USB-connected devices (e.g. Arduino). The "waitForUser()" commands are an > > attempt to introduce various delays, in the hope that this would allow time > > for the connection to be made. > > > > Being a complete Bluetooth newbie, I don't have a good feel for how things > > should go. Any suggestions? > > > > Thanks. > > > > Bill Christens-Barry > >> > > Bill, > > I would advise that you run a first macro that discovers ports and opens the > > serial port you need, and a second macro that reads or write to it. If you > > run the posted macro twice or more and never close your port then the > > Ext.open command fails because the port is already opened. The second macro > > also needs the run('serial ext'); statement. > > > > Jerome > > > > On Tue, Aug 16, 2011 at 5:04 AM, Bill Christens-Barry < > > [hidden email]> wrote: > > > > > While I've been able to communicate with USB connected devices using ImageJ > > > macros, serial extension and RXTX on my Mac (OX 10.6.8), I've not been able > > > to communicate with a Bluetooth device that is paired to the host. Here's > > > the main variant of the macro code I'm trying: > > > > > > macro "Serial2UBW" { > > > run("serial ext"); > > > portsw = Ext.ports(); > > > print(portsw); > > > waitForUser("Hit OK..."); > > > Ext.open("/dev/tty.RN42-AA9D-SPP", 9600,"DATABITS_8 STOPBITS_1 > > > PARITY_NONE"); > > > waitForUser("Hit OK..."); > > > Ext.write("w"); > > > wait(1000); > > > data = Ext.read(); > > > print(data); > > > } > > > > > > Note that the first argument to Ext.open() (line 3) matches a previously > > > paired item that lists in /dev. After this command, I see various devs being > > > enumerated in the ImageJ status bar, followed by an "RN42-AA9D connected" > > > indication in a Growl notification (even before issuance of the Ext.open() > > > command. > > > > > > Once the Ext.open() command is issued (line 6), I get notification of a > > > connection exception in the ImageJ status bar, even if I comment out the > > > print(portsw) command (which only prints after a lengthy period). Subsequent > > > Ext.anything() commands also result in further exceptions being displayed. > > > > > > I've yet to succeed in receiving (and probably sending) any data, even > > > though this code is comparable to code that works in communicating with > > > USB-connected devices (e.g. Arduino). The "waitForUser()" commands are an > > > attempt to introduce various delays, in the hope that this would allow time > > > for the connection to be made. > > > > > > Being a complete Bluetooth newbie, I don't have a good feel for how things > > > should go. Any suggestions? > > > > > > Thanks. > > > > > > Bill Christens-Barry > > > |
In reply to this post by Bill Christens-Barry
I found that adding explicit \r\n terminators to string commands sent to the device attached via BlueTooth did the trick. While I'm not sure why I didn't need to do this when I made a direct serial connection, this is a detail I can sort out later. If anyone finds it useful, here's some macro code that works with a Roving Networks RN-42 Bluetooth device and modified Sparkfun UBW device:
macro "BT-opener [n4]" { run("serial ext"); //portsList = Ext.ports(); Ext.open("/dev/tty.RN42-AA9D-SPP", 115200,"DATABITS_8 STOPBITS_1 PARITY_NONE"); // modify to match an available port in portsList wait(100); //YWMV alive = Ext.alive(); if (alive == 1) btcs = "Connected"; else btcs = "Not connected"; print("BT connection status: " + btcs); } macro "BT-id [n5]" { run("serial ext"); alive = Ext.alive(); if (alive == 0) exit("BT not connected; unable to send; exiting."); Ext.write("V\r\n"); // "v" is device specific wait(100); data = Ext.read(); print("\"V\" response: " + data); Ext.write("W\r\n"); // "w" is device specific wait(100); data = Ext.read(); print("\"W\" response: " + data); } macro "BT-arbitDataOut [n6]" { run("serial ext"); wait(100); alive = Ext.alive(); if (alive == 0) exit("BT not connected; unable to send; exiting."); outmsg = getString("Enter text to send: ", "w"); Ext.write(outmsg + "\r\n"); wait(100); data = Ext.read(); print("\"" + outmsg + "\"" + " response: " + data); } macro "BT-closer [n7]" { run("serial ext"); wait(100); waitForUser("Hit OK to close BT connection"); wait(100); Ext.close; wait(100); alive = Ext.alive(); if (alive == 1) btcs = "Connected"; else btcs = "Not connected"; print("BT connection status: " + btcs); } Bill Christens-Barry |
Free forum by Nabble | Edit this page |