[Mono-osx] IOKit Enumeration

Joshua Perry josh at 6bit.com
Tue Apr 15 10:49:05 EDT 2008


Thanks for the input Geoff,

I wish I would have asked before I wrote the P/Invoke code, calling  
into CoreFoundation/IOKit is sure easier from C than P/Invoking it in  
C#!

This is my first contrib to mono so I'm trying to learn how things are  
done.  I need to shift my mindset from Usermode to Kernelmode if you  
will; since the code is going to be built as part of the framework it  
makes sense to use unmanaged code when appropriate.

The current SerialPort chooses between two ISerialStream  
implementations SerialPortStream and WinSerialStream.   
SerialPortStream is implemented by P/Invoking into MonoPosixHelper  
functions like serial_read and serial_write.  WinSerialStream is  
implemented by P/Invoking the Win32 API serial port and IO functions.   
Outside of enumerating IOKit objects to find the port /dev/ nodes, I  
believe that OSX is compatible with standard posix callsl though I'm  
not happy with the current Posix stream as Async operations are not  
implemented.  I would like to implement the async functionality and,  
from the look of things, moving the serial specific functions into io- 
layer would be the right thing to do.

In XplatUI.cs are you talking about the call to uname to check for  
"Darwin"?


We currently have 1 product for sale, an IO board with six 10Amp relay  
outputs and 12 ground-triggered inputs.  We are working on a few other  
products right now that we hope to release in the next couple of  
months.  These products will be 802.15.4 (ZigBee) wireless devices  
connected to a computer via a wireless gateway which will have an FTDI  
Serial to USB chip.  We are looking to provide low-cost Proximity card  
access hardware so that people can put them in their homes and small  
businesses; the wireless capabilities will let you retrofit doors  
without running any wires.

Josh

On Apr 14, 2008, at 9:21 PM, Geoff Norton wrote:

> Josh,
>
> On 14-Apr-08, at 8:20 PM, Joshua Perry wrote:
>
>> Hey guys,
>>
>> I haven't had much time to work on this the last few months, but this
>> weekend I was finally able to enumerate RS232 ports using P/Invoke to
>> IOKit/CoreFoundation.  This would work for enumerating any items in  
>> the
>> IOKit database but I want to add support for
>> System.IO.Ports.SerialPort.GetPortNames() to Mono for OSX.  This  
>> works
>> quite well with any FTDI type chips that provide a virtual com-port  
>> for
>> communication, which is a common method of USB enabling devices.
>>
>
> Great.
>
>> I do a lot of embedded development and talking to our hardware is
>> important, and in future products we would like to ship software  
>> for OSX
>> on Mono.
>>
>
> What do you guys make (for my personal curiousity) ?
>
>> So before I start integrating this code into my local checkout, I  
>> wanted
>> to ask what the best method is for adding this to the Mono  
>> codebase.  Is
>> there a define for managed code on OSX builds?  I've noticed that a  
>> lot
>> of places a runtime check is used against  
>> Environment.OSVersion.Platform
>> to decide which logic to execute, is this the preferred method in
>> managed code as opposed to conditional compilation?
>>
>
> There is a check you can lift in XplatUI.cs from  
> Managed.Windows.Forms.
>
>> Also, I have made some base classes that I use to manage reference
>> counting and to make the P/Invoke to CoreFoundation objects and IOKit
>> objects easier (e.g. CFString, CFMutableDictionary, IOObject).  Is  
>> there
>> an OSX helper library similar to PosixHelper that this code would  
>> go in?
>>
>
> Generally we'd push stuff like that down into unmanaged code, I'm  
> pretty sure the existing serial implementation has some unmanaged  
> code so cleaning up the interface to be generic icalls and then  
> implementing platform specific stuff in io-layer is (probably)  
> better.  Note I havn't looked at the code yet, so this may not hold  
> true.
>
> -g
>



More information about the Mono-osx mailing list