[PythonCE] serial port access

2006-06-20 Thread Benjamin McBride
 Hi All,

 I need to access the serial port for my PPC application.  I have been
 unable to locate information on this.  I'm using Python 2.4.3 and PPC
 2003.  Previously I've used pyserial, but it appears that pyserial does
 not work on Windows CE.

 Thanks for any suggestions,

 Ben McBride
 [EMAIL PROTECTED]
___
PythonCE mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pythonce


Re: [PythonCE] serial port access

2006-06-20 Thread Benjamin McBride
I've got ctypes installed.  However, I have not been able to find any
examples of how I might use ctypes for serial port access.  Any
suggestions would be appreciated.

Thanks,

Ben

On 6/20/06, Gonzalo Monzón <[EMAIL PROTECTED]> wrote:
> Hi Benjamin,
>
> You can use ctypes for direct access to serial ports via windows apis
> (openfile, readfile, writefile...)
>
> Note that manufacturers can have specific implementations, even they
> must agree to PPC implementation, but you can found small differences.
>
> http://www.codeproject.com/system/simpleserialcomm.asp
>
> Regards,
> Gonzalo
>
>
> Benjamin McBride escribió:
>
> > Hi All,
> >
> > I need to access the serial port for my PPC application.  I have been
> > unable to locate information on this.  I'm using Python 2.4.3 and PPC
> > 2003.  Previously I've used pyserial, but it appears that pyserial does
> > not work on Windows CE.
> >
> > Thanks for any suggestions,
> >
> > Ben McBride
> > [EMAIL PROTECTED]
> >___
> >PythonCE mailing list
> >[email protected]
> >http://mail.python.org/mailman/listinfo/pythonce
> >
> >
> >
>
>
___
PythonCE mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pythonce


Re: [PythonCE] serial port access

2006-06-20 Thread Benjamin McBride
Thanks Gonzalo for your help.  I have read both the ctypes and
microsoft documentation.  My understanding is that I need to use the
CreateFile API function from the coredll to get a handle to the comm
port.  When I use ctypes:

>>> windll.coredll.CreateFile

I get an AttributeError saying the CreateFile function is not found.
Ironically, the ReadFile, WriteFile, and CloseHandle functions are all
found.

Am I just missing something simple here?

Ben

On 6/20/06, Gonzalo Monzón <[EMAIL PROTECTED]> wrote:
> Have you read the ctypes docs?
>
> http://starship.python.net/crew/theller/ctypes/tutorial.html
>
> You have to read the Microsoft docs too, search what dynamic libraries
> to use and what functions to call. Study the example I posted, you have
> to call these functions using ctypes:
>
> (openfile, readfile, writefile...)
>
> Don't know if somebody has implemented serial access using ctypes as to
> post an example, read the docs, first you need to understand how ctypes
> work -for that you should know or learn what C variable types are and
> understand it almost a little bit, then the codeproject example will
> come in handy- otherwise could be hard to code... Though any ctypes
> example handling file or stream data may help you. Though pyserial uses
> ctypes too, so you could have a look to the sources. The differences are
> you have to use straight windows api calls, and pyserial calls a helper
> library wich should use windows api's for windows platform.
>
> I have to code serial access too in the next weeks, but don't have the
> time now to get my hands in it. If you are not in hurry I could post an
> example when done.
>
> Gonzalo.
>
>
> Benjamin McBride escribió:
>
> >I've got ctypes installed.  However, I have not been able to find any
> >examples of how I might use ctypes for serial port access.  Any
> >suggestions would be appreciated.
> >
> >Thanks,
> >
> >Ben
> >
> >On 6/20/06, Gonzalo Monzón <[EMAIL PROTECTED]> wrote:
> >
> >
> >>Hi Benjamin,
> >>
> >>You can use ctypes for direct access to serial ports via windows apis
> >>(openfile, readfile, writefile...)
> >>
> >>Note that manufacturers can have specific implementations, even they
> >>must agree to PPC implementation, but you can found small differences.
> >>
> >>http://www.codeproject.com/system/simpleserialcomm.asp
> >>
> >>Regards,
> >>Gonzalo
> >>
> >>
> >>Benjamin McBride escribió:
> >>
> >>
> >>
> >>>Hi All,
> >>>
> >>>I need to access the serial port for my PPC application.  I have been
> >>>unable to locate information on this.  I'm using Python 2.4.3 and PPC
> >>>2003.  Previously I've used pyserial, but it appears that pyserial does
> >>>not work on Windows CE.
> >>>
> >>>Thanks for any suggestions,
> >>>
> >>>Ben McBride
> >>>[EMAIL PROTECTED]
> >>>___
> >>>PythonCE mailing list
> >>>[email protected]
> >>>http://mail.python.org/mailman/listinfo/pythonce
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
> >>
> >___
> >PythonCE mailing list
> >[email protected]
> >http://mail.python.org/mailman/listinfo/pythonce
> >
> >
> >
>
>
___
PythonCE mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pythonce


Re: [PythonCE] serial port access

2006-06-23 Thread Benjamin McBride
Thanks all for your help!

The final key was to use the wide-character variant of CreateFile.  As
soon as I have the code cleaned up I will post the code (should be in the
next day or so).  It will have a similar interface as pySerial.

Thanks,

Ben McBride

On 6/21/06, Luke Dunstan <[EMAIL PROTECTED]> wrote:
>
> You need to use the wide-character variants of Windows APIs, i.e.
> CreateFileW
>
> Luke
>
> - Original Message -
> From: "Benjamin McBride" <[EMAIL PROTECTED]>
> To: 
> Sent: Wednesday, June 21, 2006 4:54 AM
> Subject: Re: [PythonCE] serial port access
>
>
> Thanks Gonzalo for your help.  I have read both the ctypes and
> microsoft documentation.  My understanding is that I need to use the
> CreateFile API function from the coredll to get a handle to the comm
> port.  When I use ctypes:
>
> >>> windll.coredll.CreateFile
>
> I get an AttributeError saying the CreateFile function is not found.
> Ironically, the ReadFile, WriteFile, and CloseHandle functions are all
> found.
>
> Am I just missing something simple here?
>
> Ben
>
> On 6/20/06, Gonzalo Monzón <[EMAIL PROTECTED]> wrote:
> > Have you read the ctypes docs?
> >
> > http://starship.python.net/crew/theller/ctypes/tutorial.html
> >
> > You have to read the Microsoft docs too, search what dynamic libraries
> > to use and what functions to call. Study the example I posted, you have
> > to call these functions using ctypes:
> >
> > (openfile, readfile, writefile...)
> >
> > Don't know if somebody has implemented serial access using ctypes as to
> > post an example, read the docs, first you need to understand how ctypes
> > work -for that you should know or learn what C variable types are and
> > understand it almost a little bit, then the codeproject example will
> > come in handy- otherwise could be hard to code... Though any ctypes
> > example handling file or stream data may help you. Though pyserial uses
> > ctypes too, so you could have a look to the sources. The differences are
> > you have to use straight windows api calls, and pyserial calls a helper
> > library wich should use windows api's for windows platform.
> >
> > I have to code serial access too in the next weeks, but don't have the
> > time now to get my hands in it. If you are not in hurry I could post an
> > example when done.
> >
> > Gonzalo.
> >
> >
> > Benjamin McBride escribió:
> >
> > >I've got ctypes installed.  However, I have not been able to find any
> > >examples of how I might use ctypes for serial port access.  Any
> > >suggestions would be appreciated.
> > >
> > >Thanks,
> > >
> > >Ben
> > >
> > >On 6/20/06, Gonzalo Monzón <[EMAIL PROTECTED]> wrote:
> > >
> > >
> > >>Hi Benjamin,
> > >>
> > >>You can use ctypes for direct access to serial ports via windows apis
> > >>(openfile, readfile, writefile...)
> > >>
> > >>Note that manufacturers can have specific implementations, even they
> > >>must agree to PPC implementation, but you can found small differences.
> > >>
> > >>http://www.codeproject.com/system/simpleserialcomm.asp
> > >>
> > >>Regards,
> > >>Gonzalo
> > >>
> > >>
> > >>Benjamin McBride escribió:
> > >>
> > >>
> > >>
> > >>>Hi All,
> > >>>
> > >>>I need to access the serial port for my PPC application.  I have
> > >>> been
> > >>>unable to locate information on this.  I'm using Python 2.4.3 and
> > >>> PPC
> > >>>2003.  Previously I've used pyserial, but it appears that pyserial
> > >>> does
> > >>>not work on Windows CE.
> > >>>
> > >>>Thanks for any suggestions,
> > >>>
> > >>>Ben McBride
> > >>>[EMAIL PROTECTED]
> > >>>___
> > >>>PythonCE mailing list
> > >>>[email protected]
> > >>>http://mail.python.org/mailman/listinfo/pythonce
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>
> > >>
> > >___
> > >PythonCE mailing list
> > >[email protected]
> > >http://mail.python.org/mailman/listinfo/pythonce
> > >
> > >
> > >
> >
> >
> ___
> PythonCE mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/pythonce
> ___
> PythonCE mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/pythonce
>
___
PythonCE mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pythonce


Re: [PythonCE] serial port access

2006-09-22 Thread Benjamin McBride

I did get things mostly working.  I've attached what I have done.  I
had problems with losing data at higher baud rates, so I buffered data
in read().  If this is not the desired behavior it is easy to change
(just look in the source).
You also need ctypes installed.

Good Luck,

Ben
#some minor manual additions
INVALID_HANDLE_VALUE = -1
MAXDWORD = 4294967295
# Generated by h2py from /home/bdm/Desktop/winbase.h
VS_VERSION_INFO = 1
VS_USER_DEFINED = 100
VS_FFI_SIGNATURE = (-17890115)
VS_FFI_STRUCVERSION = 0x0001L
VS_FFI_FILEFLAGSMASK = 0x003FL
VS_FF_DEBUG = 0x0001L
VS_FF_PRERELEASE = 0x0002L
VS_FF_PATCHED = 0x0004L
VS_FF_PRIVATEBUILD = 0x0008L
VS_FF_INFOINFERRED = 0x0010L
VS_FF_SPECIALBUILD = 0x0020L
VOS_UNKNOWN = 0xL
VOS_DOS = 0x0001L
VOS_OS216 = 0x0002L
VOS_OS232 = 0x0003L
VOS_NT = 0x0004L
VOS_WINDOWSCE = 0x0005L
VOS__BASE = 0xL
VOS__WINDOWS16 = 0x0001L
VOS__PM16 = 0x0002L
VOS__PM32 = 0x0003L
VOS__WINDOWS32 = 0x0004L
VOS_DOS_WINDOWS16 = 0x00010001L
VOS_DOS_WINDOWS32 = 0x00010004L
VOS_OS216_PM16 = 0x00020002L
VOS_OS232_PM32 = 0x00030003L
VOS_NT_WINDOWS32 = 0x00040004L
VOS_CE_WINDOWS32 = 0x00050004L
VFT_UNKNOWN = 0xL
VFT_APP = 0x0001L
VFT_DLL = 0x0002L
VFT_DRV = 0x0003L
VFT_FONT = 0x0004L
VFT_VXD = 0x0005L
VFT_STATIC_LIB = 0x0007L
VFT2_UNKNOWN = 0xL
VFT2_DRV_PRINTER = 0x0001L
VFT2_DRV_KEYBOARD = 0x0002L
VFT2_DRV_LANGUAGE = 0x0003L
VFT2_DRV_DISPLAY = 0x0004L
VFT2_DRV_MOUSE = 0x0005L
VFT2_DRV_NETWORK = 0x0006L
VFT2_DRV_SYSTEM = 0x0007L
VFT2_DRV_INSTALLABLE = 0x0008L
VFT2_DRV_SOUND = 0x0009L
VFT2_DRV_COMM = 0x000AL
VFT2_DRV_INPUTMETHOD = 0x000BL
VFT2_FONT_RASTER = 0x0001L
VFT2_FONT_VECTOR = 0x0002L
VFT2_FONT_TRUETYPE = 0x0003L
VFFF_ISSHAREDFILE = 0x0001
VFF_CURNEDEST = 0x0001
VFF_FILEINUSE = 0x0002
VFF_BUFFTOOSMALL = 0x0004
VIFF_FORCEINSTALL = 0x0001
VIFF_DONTDELETEOLD = 0x0002
VIF_TEMPFILE = 0x0001L
VIF_MISMATCH = 0x0002L
VIF_SRCOLD = 0x0004L
VIF_DIFFLANG = 0x0008L
VIF_DIFFCODEPG = 0x0010L
VIF_DIFFTYPE = 0x0020L
VIF_WRITEPROT = 0x0040L
VIF_FILEINUSE = 0x0080L
VIF_OUTOFSPACE = 0x0100L
VIF_ACCESSVIOLATION = 0x0200L
VIF_SHARINGVIOLATION = 0x0400L
VIF_CANNOTCREATE = 0x0800L
VIF_CANNOTDELETE = 0x1000L
VIF_CANNOTRENAME = 0x2000L
VIF_CANNOTDELETECUR = 0x4000L
VIF_OUTOFMEMORY = 0x8000L
VIF_CANNOTREADSRC = 0x0001L
VIF_CANNOTREADDST = 0x0002L
VIF_BUFFTOOSMALL = 0x0004L
FILE_BEGIN = 0
FILE_CURRENT = 1
FILE_END = 2
MAXINTATOM = 0xC000
LMEM_FIXED = 0x
LMEM_MOVEABLE = 0x0002
LMEM_NOCOMPACT = 0x0010
LMEM_NODISCARD = 0x0020
LMEM_ZEROINIT = 0x0040
LMEM_MODIFY = 0x0080
LMEM_DISCARDABLE = 0x0F00
LMEM_VALID_FLAGS = 0x0F72
LMEM_INVALID_HANDLE = 0x8000
LMEM_DDESHARE = 0x
LMEM_LOWER = 0x
LMEM_NOT_BANKED = 0x
LMEM_NOTIFY = 0x
LMEM_SHARE = 0x
LHND = (LMEM_MOVEABLE | LMEM_ZEROINIT)
LPTR = (LMEM_FIXED | LMEM_ZEROINIT)
NONZEROLHND = (LMEM_MOVEABLE)
NONZEROLPTR = (LMEM_FIXED)
LMEM_DISCARDED = 0x4000
LMEM_LOCKCOUNT = 0x00FF
GMEM_FIXED = LMEM_FIXED
GMEM_MOVEABLE = LMEM_MOVEABLE
GPTR = LPTR
GHND = LHND
GMEM_DDESHARE = LMEM_DDESHARE
GMEM_DISCARDABLE = LMEM_DISCARDABLE
GMEM_LOWER = LMEM_LOWER
GMEM_NOCOMPACT = LMEM_NOCOMPACT
GMEM_NODISCARD = LMEM_NODISCARD
GMEM_NOT_BANKED = LMEM_NOT_BANKED
GMEM_NOTIFY = LMEM_NOTIFY
GMEM_SHARE = LMEM_SHARE
GMEM_ZEROINIT = LMEM_ZEROINIT
VER_PLATFORM_WIN32s = 0
VER_PLATFORM_WIN32_WINDOWS = 1
VER_PLATFORM_WIN32_NT = 2
VER_PLATFORM_WIN32_HH = 3
VER_PLATFORM_WIN32_CE = 3
DONT_RESOLVE_DLL_REFERENCES = 0x0001
LOAD_LIBRARY_AS_DATAFILE = 0x0002
LOAD_WITH_ALTERED_SEARCH_PATH = 0x0008
MSGQUEUE_NOPRECOMMIT = 0x0001
MSGQUEUE_ALLOW_BROKEN = 0x0002
MSGQUEUE_MSGALERT = 0x0001
DEBUG_PROCESS = 0x0001
DEBUG_ONLY_THIS_PROCESS = 0x0002
CREATE_SUSPENDED = 0x0004
CREATE_NEW_CONSOLE = 0x0010
STACK_SIZE_PARAM_IS_A_RESERVATION = 0x0001
INHERIT_CALLER_PRIORITY = 0x0002
THREAD_PRIORITY_TIME_CRITICAL = 0
THREAD_PRIORITY_HIGHEST = 1
THREAD_PRIORITY_ABOVE_NORMAL = 2
THREAD_PRIORITY_NORMAL = 3
THREAD_PRIORITY_BELOW_NORMAL = 4
THREAD_PRIORITY_LOWEST = 5
THREAD_PRIORITY_ABOVE_IDLE = 6
THREAD_PRIORITY_IDLE = 7
EXCEPTION_DEBUG_EVENT = 1
CREATE_THREAD_DEBUG_EVENT = 2
CREATE_PROCESS_DEBUG_EVENT = 3
EXIT_THREAD_DEBUG_EVENT = 4
EXIT_PROCESS_DEBUG_EVENT = 5
LOAD_DLL_DEBUG_EVENT = 6
UNLOAD_DLL_DEBUG_EVENT = 7
OUTPUT_DEBUG_STRING_EVENT = 8
RIP_EVENT = 9
WAIT_OBJECT_0 = 0xL
WAIT_ABANDONED = 0x0080L
WAIT_ABANDONED_0 = 0x0080L
WAIT_FAILED = (-1)
INFINITE = (-1)
TLS_MINIMUM_AVAILABLE = 64
STILL_ACTIVE = 0x0103
GENERIC_READ = ((-2147483648))
GENERIC_WRITE = (0x4000L)
GENERIC_EXECUTE = (0x2000L)
GENERIC_ALL = (0x1000L)
FILE_SHARE_READ = 0x0001
FILE_SHARE_WRITE = 0x0002
FILE_FLAG_WRITE_THROUGH = (-2147483648)
FILE_FLAG_OVERLAPPED = 0x4000
FILE_FLAG_NO_BUFFERING = 0x2000
FILE_FLAG_RANDOM_ACC