wxCTB : cross-platform serial (OSX project)
BlitzMax Forums/Brucey's Modules/wxCTB : cross-platform serial (OSX project)
| ||
wxCTB is a common API for using serial (com) ports cross-platform. Currently it is only for Linux/Win32, but I'm keen to get it working for OS X, since I'd like to be able to use it in BlitzMax on my Mac with a usb-serial adapter. I'm hoping that since OS X is getting more POSIXy all the time that the Linux drivers might work with a bit of tweaking... If anyone is interested in helping out, here's the place to do it ! Links of possible interest : * http://developer.apple.com/documentation/DeviceDrivers/Conceptual/IOKitFundamentals/Introduction/chapter_1_section_1.html * http://developer.apple.com/documentation/DeviceDrivers/Conceptual/WorkingWSerial/WWSerial_Intro/chapter_1_section_1.html * http://www.tigoe.net/pcomp/resources/archives/avr/000749.shtml More stuff to follow... |
| ||
I can confirm that an Apple MacBook Pro was today connected to a WaterRower using a PL2303 USB to serial adapter. As I sat and watched valid data was sent between the devices, I can therefore confirm the first successful transfer of serial data using wxCTB. |
| ||
Ah, the wonder of it all :-) Still much to do Mac-wise though. This Ioctl() stuff is a bit under-documented. |
| ||
A small snippet to get people started:Const baudrate:Int = wxBAUD_1200 Const devname:String = "/dev/tty.PL2303-0000101D" Const timeout:Int = 1000 Global dev:wxSerialPort = New wxSerialPort.Create() ' Try To open the given port If dev.Open(devname) < 0 ' wxMessageBox("Cannot open " + devname ) dev.free() Else ' set the baudrate dev.SetBaudRate(baudrate) Global buffer:Byte[1024] For Local i:Int=0 To 1000 dev.Read(buffer,2) Delay(250) DebugLog "data = " + Hex(buffer[0]) + " : " + Hex(buffer[1]) Next dev.Close() dev.free() EndIf |
| ||
I've added a couple of new Functions for Mac (only). wxChooseSerialPort:String() and wxListSerialPorts:String[]() wxChooseSerialPort pops up a choice dialog asking which serial port to choose from, returning the tty string back to the app - which you can then use to open a connection to. wxListSerialPorts simply returns a list of all currently available serial ports. These are useful on Mac since "real" serial is only usually available through a USB-Serial adapter, and appear as unique ports, rather than like on Linux which has things like /dev/tty0. :o) |
| ||
on osx mountain lion I get: wxListSerialPorts:String[]() doesn't return the full list just the top entry - so it's not very useful Also any attempt to use dev.write() doesn't seem to actually transfer data? Documents or example would be great But for full marks, being able to strip wxctb away entirely from wx so it is standalone "simple" code without ANY wx dependancies? anyone?? |
| ||
There is a newish cross-platform BaH.Serial module which isn't dependent on wx, and has been working fine (read/write in a threaded Max app) for me on OS X. |