[PythonCE] building a 'simple' example
Dear all While there have been some posts on this topic I don't believe the answer is in there jet. Eventually I want to write (with help of a colliegue whom is experienced in c) a module that can use a device. Some c libraries are available, and all I realy need is a function that returns an Int or String when called. I am trying to to build and run Listing 29-1 from the Python bible, but so far I have been unable to compile annything that will work. MS eVC is installed, and it compiles and links with no errors or warnings. but when I put the dll on the PDA, and run a test program all I get is an ImportError: DLL load failed:The specified module could not be found. it can clearly find the file couse it knows it is a dll. I'm hoplessly lost on what could be wrong, does annyone have any ideas. Cheers here is the code: // simple.cpp : Defines the entry point for the DLL application. // #include "Python.h" static PyObject *simple_add(PyObject *pSelf, PyObject *pArgs) { PyObject *pX, *pY; if (!PyArg_ParseTuple(pArgs, "OO", &pX, &pY)) return NULL; return PyNumber_Add(pX, pY); } static char count_doc[] = "returns the number of arguments passed in"; static PyObject *simple_count(PyObject *pSelf, PyObject *pArgs) { long count = PyTuple_Size(pArgs); return PyInt_FromLong(count); } static PyMethodDef simple_methods[] = { {"add", simple_add, METH_VARARGS, NULL}, {"count", simple_count, METH_VARARGS, count_doc}, {NULL, NULL} }; DL_EXPORT(void) initsimple() { Py_InitModule("simple", simple_methods); } ___ PythonCE mailing list PythonCE@python.org http://mail.python.org/mailman/listinfo/pythonce
Re: [PythonCE] building a 'simple' example
Hi, Where did you put the DLL? What is it called? What were the commands that failed? Luke - Original Message - From: "Smit, M.C." <[EMAIL PROTECTED]> To: Sent: Friday, June 23, 2006 11:21 PM Subject: [PythonCE] building a 'simple' example > Dear all > > While there have been some posts on this topic I don't believe the answer > is in there jet. > > Eventually I want to write (with help of a colliegue whom is experienced > in c) a module that can use a device. Some c libraries are available, and > all I realy need is a function that returns an Int or String when called. > > I am trying to to build and run Listing 29-1 from the Python bible, > but so far I have been unable to compile annything that will work. > MS eVC is installed, and it compiles and links with no errors or warnings. > but when I put the dll on the PDA, and run a test program all I get is an > > ImportError: DLL load failed:The specified module could not be found. > > it can clearly find the file couse it knows it is a dll. I'm hoplessly > lost on what could be wrong, does annyone have any ideas. > > Cheers > > > here is the code: > // simple.cpp : Defines the entry point for the DLL application. > // > > #include "Python.h" > > static PyObject *simple_add(PyObject *pSelf, PyObject *pArgs) > { > PyObject *pX, *pY; > > if (!PyArg_ParseTuple(pArgs, "OO", &pX, &pY)) > return NULL; > > return PyNumber_Add(pX, pY); > } > > static char count_doc[] = "returns the number of arguments passed in"; > > static PyObject *simple_count(PyObject *pSelf, PyObject *pArgs) > { > long count = PyTuple_Size(pArgs); > return PyInt_FromLong(count); > } > > static PyMethodDef simple_methods[] = > { > {"add", simple_add, METH_VARARGS, NULL}, > {"count", simple_count, METH_VARARGS, count_doc}, > {NULL, NULL} > }; > > DL_EXPORT(void) initsimple() > { > Py_InitModule("simple", simple_methods); > } ___ PythonCE mailing list PythonCE@python.org http://mail.python.org/mailman/listinfo/pythonce
Re: [PythonCE] serial port access
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 > > >>>PythonCE@python.org > > >>>http://mail.python.org/mailman/listinfo/pythonce > > >>> > > >>> > > >>> > > >>> > > >>> > > >> > > >> > > >___ > > >PythonCE mailing list > > >PythonCE@python.org > > >http://mail.python.org/mailman/listinfo/pythonce > > > > > > > > > > > > > > ___ > PythonCE mailing list > PythonCE@python.org > http://mail.python.org/mailman/listinfo/pythonce > ___ > PythonCE mailing list > PythonCE@python.org > http://mail.python.org/mailman/listinfo/pythonce > ___ PythonCE mailing list PythonCE@python.org http://mail.python.org/mailman/listinfo/pythonce
[PythonCE] Problem with ctypes
The wince files on the ctypes sourceforge project site don't work for me. import ctypes was resulting in "import error: dll load failed". I claimed to be unable to locate _ctypes.pyd even though it was present and in sys.path. I tried both 0.9.9.6 and 0.9.9.3 with no luck, I tried different paths and configurations too. I finally checked the the pythonce project and downloaded the 0.9.9.6 files from there. They worked like a charm and now I'm up and running ctypes again. I have Python 2.4.3 running on a Dell Axim X5 with PPC 2003, installed to the SD Card. Has anyone else had similar problems? Tod ___ PythonCE mailing list PythonCE@python.org http://mail.python.org/mailman/listinfo/pythonce