Macintosh / FTDI-Friend / XBee setup, need help on the Macintosh side ...
Jay_Reynolds_Freeman
Posts: 1
I am trying to drive an XBee Series 1 (not the pro) that is mounted on an AdaFruit XBee adapter board, which is in turn connected to a USB port of my Macintosh via an FTDI Friend USB/TTL-232 cable. This is for a robotics project in which the remote is an XBee on a Parallax Stingray.
All the hardware and drivers seem to work; I can talk from a serial monitor on the Mac, through to the XBee and thence to the Stingray XBee, and receive reply communications back to the serial monitor.
The problem is that I don't want to use a serial monitor on the Mac, I want to be able to talk through the USB port to the XBee from a C++ program, and I do not know how to do that. I am sure it can be done -- the serial ports all do it -- but I can't find any open-source code for them.
I would say that I am a very experienced C++ coder in general, but haven't used hardware ports under Unix at all, ever. I am hoping there is some way to open the port MacOS creates for me -- something of the form /dev/tty.usbserial-ABCD1234 -- and use the likes of fgetc and fputc to do what I want, perhaps using ioctl to configure the port, but I am not sure how to do that and could use pointers to some tutorials or sample code, if it is indeed possible to do it that way, or some other form of guidance if it is not.
Thanks much ...
All the hardware and drivers seem to work; I can talk from a serial monitor on the Mac, through to the XBee and thence to the Stingray XBee, and receive reply communications back to the serial monitor.
The problem is that I don't want to use a serial monitor on the Mac, I want to be able to talk through the USB port to the XBee from a C++ program, and I do not know how to do that. I am sure it can be done -- the serial ports all do it -- but I can't find any open-source code for them.
I would say that I am a very experienced C++ coder in general, but haven't used hardware ports under Unix at all, ever. I am hoping there is some way to open the port MacOS creates for me -- something of the form /dev/tty.usbserial-ABCD1234 -- and use the likes of fgetc and fputc to do what I want, perhaps using ioctl to configure the port, but I am not sure how to do that and could use pointers to some tutorials or sample code, if it is indeed possible to do it that way, or some other form of guidance if it is not.
Thanks much ...
Comments
The catch is going to be making sure you're always prepared to read data, because some stuff can arrive unexpectedly (such as the modem status packet in API mode). Also, for robustness, you'll want timeouts when expecting data from the XBee. That implies threads or an event loop, or something equivalent.
I could provide some sample code but it would be written in Tcl, which might not be so helpful to you.