[IronPython] Accessing Serial Port from IronPython driven Webpage

Vernon Cole vernondcole at gmail.com
Thu Aug 26 01:44:17 CEST 2010


Kurt:

Have you tried http://pyserial.sourceforge.net/ ?
It is documented to run on IronPython, either dotNet or MONO.

I have a setup similar to what you describe, but using x.10 hardware which
is controlled using a module called x10.py, which in turn calls serial.py.
It controls the air conditioner in my home office/computer room and the
heaters in two iguana cages.  I use OneWire devices to sense the temperature
and a Python program completes the feedback loop.  The iguana cages are
heated by incandescent heat lamps which are connected to x.10 dimmers. The
Python program can hold them to within 0.5 degrees (F) and sets back the
temperature and turns the lights off at night. Fun project! I hope you have
similar success with your ZigBee device.
--
Vernon

On Wed, Aug 25, 2010 at 5:02 PM, Kurt A. Richardson <kurt at kurtrichardson.com
> wrote:

>  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#:
>
>
> http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/a5ff20cf-0bb5-4a3e-aed4-24c6290f66cd/
>
> But I don't know how to translate this into IronPython.  In my FanOn
> function I have:
>
> sx = SecurityPermission(SecurityPermissionFlag.UnmanagedCode)
> sx.Assert()
>
> after importing System.Security.Permissions
>
> However I don't know how to decorate the function itself with:
>
> [SuppressUnmanagedCodeSecurityAttribute()]
>
> Any ideas would be greatly appreciated.
>
> Kind regards,
>
> Kurt
>
> 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)
>    sx.Assert()
>    sp = serial_ports.port('COM4')
>    sp.open()
>    sp.write_packet('7E001017060013A20040645580FFFE024431053B')
>    sp.close()
>    lblResponse.Text = "Fan successfully turned on"
>
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100825/58ea68e8/attachment.html>


More information about the Ironpython-users mailing list