[IronPython] Accessing Serial Port from IronPython driven Webpage

Kurt A. Richardson kurt at kurtrichardson.com
Thu Aug 26 01:02:51 CEST 2010

  Hi All

I wonder if anyone has tried to access the serial port from a web app 
using Iron Python.  I have a simple default webpage which is using 
IronPython as the code behind.  My 'FanOn' function calls a little 
IronPython script that opens up the serial port and sends an ZigBee 
communications packet to a little home made device which would then turn 
a fan on.

I have found a web page that describes how to access the Serial port on 
the server using C#:


But I don't know how to translate this into IronPython.  In my FanOn 
function I have:

sx = SecurityPermission(SecurityPermissionFlag.UnmanagedCode)

after importing System.Security.Permissions

However I don't know how to decorate the function itself with:


Any ideas would be greatly appreciated.

Kind regards,


PS A simplified version of my FanOn script which is containined in a 
Default.aspx.py file behind Default.aspx:

def FanOn(sender, e):
     sx = SecurityPermission(SecurityPermissionFlag.UnmanagedCode)
     sp = serial_ports.port('COM4')
     lblResponse.Text = "Fan successfully turned on"

More information about the Ironpython-users mailing list