Re: Problem with access to shared memory(W2K) / ORIGINALLY (win32) speedfan api control

2005-04-06 Thread Claudio Grondi
Thomas Heller,
  it seems, that your email address
  [EMAIL PROTECTED] doesn't work
  or at least don't accept attachments,
  so maybe you can provide me with
  another one?

> ptr = cast(pBuf, POINTER(Buffer))
> print ptr # should print 
> struct = ptr[0]

results in breakdown of Python
(Windows exception, can't read from memory
at 0x0...07)
due to existance of
> ptr = cast(pBuf, POINTER(Buffer))
but the print
> print ptr # should print 
does its output to the console...

Strange...

Claudio

"Thomas Heller" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> "Claudio Grondi" <[EMAIL PROTECTED]> writes:
>
> >> For the mistake you made see below, hope that helps.
> > It doesn't.
> >
> >> > pBuf_buf = cast(pBuf, Buffer)
> >> Here's the problem.  pBuf is a pointer to a Buffer structure, not the
> >> buffer structure itself.
> >> Something like
> >> pBuf_buf = Buffer.from_address(pBuf)
> >> may work.
> > If I currently understand it right, cast() should
> > do exactly this, i.e. should write the content
> > pointed to by pBuf to a Python variable
> > pBuf_buf which is an object of the Buffer
> > class, where I can access the single
> > components like any other Python
> > variables - am I right or wrong?
>
> You are right - my bad.
> pBuf is a pointer to your structure, so:
>
> ptr = cast(pBuf, POINTER(Buffer))
> print ptr # should print 
> struct = ptr[0]
>
> and now 'struct' should contain the data that you need.
>
> >> For the general way to solve this problem you should know that you can
> >> access a shared memory area with a certain name also with Python's mmap
> >> module, although that is probably not documented very good.  There was
a
> >> recipe posted a few days ago which showed different ways to acces
shared
> >> memory, with or without ctypes.
> >
> >> > The code I use is provided also here:
> >> >  http://www.codecomments.com/Python/message430495.html
> >> >  http://mail.python.org/pipermail/python-list/2005-March/271853.html
> >> > (the mmap part of it doesn't work at all)
> >
> > So I am already using the recipe, right?
> > But it doesn't work as expected.
> > mmap doesn't work at all failing in
> > shmem = mmap.mmap(0, 0, "$M$B$M$5$S$D$", mmap.ACCESS_READ)
> > with WindowsError: [Errno 87] wrong parameter
>
> I get this error when I try to open a non-existing shared memory block.
> From the mmap docs:
>
>   If length is 0, the maximum length of the map is the current size of
>   the file, except that if the file is empty Windows raises an exception
>   (you cannot create an empty mapping on Windows).
>
> If I run it with non-zero length it does not raise an exception
>
>   shmem = mmap.mmap(0, 0, "$M$B$M$5$S$D$", mmap.ACCESS_READ)
>
> although it *creates* the shared memory block, IIUC.  Are you sure your
> speedfan app is running when you get the WindowsError?
>
> Thomas


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with access to shared memory(W2K) / ORIGINALLY (win32) speedfan api control

2005-04-06 Thread Thomas Heller
"Claudio Grondi" <[EMAIL PROTECTED]> writes:

>> For the mistake you made see below, hope that helps.
> It doesn't.
>
>> > pBuf_buf = cast(pBuf, Buffer)
>> Here's the problem.  pBuf is a pointer to a Buffer structure, not the
>> buffer structure itself.
>> Something like
>> pBuf_buf = Buffer.from_address(pBuf)
>> may work.
> If I currently understand it right, cast() should
> do exactly this, i.e. should write the content
> pointed to by pBuf to a Python variable
> pBuf_buf which is an object of the Buffer
> class, where I can access the single
> components like any other Python
> variables - am I right or wrong?

You are right - my bad.
pBuf is a pointer to your structure, so:

ptr = cast(pBuf, POINTER(Buffer))
print ptr # should print 
struct = ptr[0]

and now 'struct' should contain the data that you need.

>> For the general way to solve this problem you should know that you can
>> access a shared memory area with a certain name also with Python's mmap
>> module, although that is probably not documented very good.  There was a
>> recipe posted a few days ago which showed different ways to acces shared
>> memory, with or without ctypes.
>
>> > The code I use is provided also here:
>> >  http://www.codecomments.com/Python/message430495.html
>> >  http://mail.python.org/pipermail/python-list/2005-March/271853.html
>> > (the mmap part of it doesn't work at all)
>
> So I am already using the recipe, right?
> But it doesn't work as expected.
> mmap doesn't work at all failing in
> shmem = mmap.mmap(0, 0, "$M$B$M$5$S$D$", mmap.ACCESS_READ)
> with WindowsError: [Errno 87] wrong parameter

I get this error when I try to open a non-existing shared memory block.
>From the mmap docs: 

  If length is 0, the maximum length of the map is the current size of
  the file, except that if the file is empty Windows raises an exception
  (you cannot create an empty mapping on Windows).

If I run it with non-zero length it does not raise an exception

  shmem = mmap.mmap(0, 0, "$M$B$M$5$S$D$", mmap.ACCESS_READ)

although it *creates* the shared memory block, IIUC.  Are you sure your
speedfan app is running when you get the WindowsError?

Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with access to shared memory(W2K) / ORIGINALLY (win32) speedfan api control

2005-04-06 Thread Claudio Grondi
> For the mistake you made see below, hope that helps.
It doesn't.

> > pBuf_buf = cast(pBuf, Buffer)
> Here's the problem.  pBuf is a pointer to a Buffer structure, not the
> buffer structure itself.
> Something like
> pBuf_buf = Buffer.from_address(pBuf)
> may work.
If I currently understand it right, cast() should
do exactly this, i.e. should write the content
pointed to by pBuf to a Python variable
pBuf_buf which is an object of the Buffer
class, where I can access the single
components like any other Python
variables - am I right or wrong?

How can I access content at any
real memory address in Python
like you suggest with the
fictive(?) .from_address(memPointer)
method?
Wouldn't it be anyway protected?
Is not cast() a kind of solution to this
problem?

Because the exepected buffer
contains zero bytes I can't use
cast(pBuf, c_char_p) to get the entire
content as it is done in the recipe
provided by Srijit Kumar Bhadra.
At least the .Data0 value is set by cast()
in my trials, but it seems, that this has
nothing to do with the shared memory
area content.

> For the general way to solve this problem you should know that you can
> access a shared memory area with a certain name also with Python's mmap
> module, although that is probably not documented very good.  There was a
> recipe posted a few days ago which showed different ways to acces shared
> memory, with or without ctypes.

> > The code I use is provided also here:
> >  http://www.codecomments.com/Python/message430495.html
> >  http://mail.python.org/pipermail/python-list/2005-March/271853.html
> > (the mmap part of it doesn't work at all)

So I am already using the recipe, right?
But it doesn't work as expected.
mmap doesn't work at all failing in
shmem = mmap.mmap(0, 0, "$M$B$M$5$S$D$", mmap.ACCESS_READ)
with WindowsError: [Errno 87] wrong parameter

I am on Windows 2000 SP 4, Pyhon version 2.3.5
using ctypes version 0.9.5 .

Any further hints?

Claudio


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with access to shared memory(W2K) / ORIGINALLY (win32) speedfan api control

2005-04-06 Thread Thomas Heller
"Claudio Grondi" <[EMAIL PROTECTED]> writes:

> Background information:
> -
> in order to monitor mainboard sensory data
> as fan speeds, temperatures, applications
> like SpeedFan http://www.almico.com/speedfan.php
> or MBM http://mbm.livewiredev.com/
> can be used.
> Both of the mentioned apps expose data got
> from the hardware in a shared memory area.
>
> The goal to achieve:
> ---
> is to supervise the motherboard sensory
> data from within a Python script
>
> The approach:
> ---
> access to the shared memory area
> exposed by motherboard hardware
> querying apps from Python script.

For the mistake you made see below, hope that helps.

For the general way to solve this problem you should know that you can
access a shared memory area with a certain name also with Python's mmap
module, although that is probably not documented very good.  There was a
recipe posted a few days ago which showed different ways to acces shared
memory, with or without ctypes.

> The problem:
> -
> the below listed script code returns
> always same values, what
> leads to the conclusion, that something
> is going wrong.
>
> Can anyone help?
>
> Thanks in advance
>
> Claudio
>
> The code
> -
>   I use is provided also here:
>  http://www.codecomments.com/Python/message430495.html
>  http://mail.python.org/pipermail/python-list/2005-March/271853.html
> (the mmap part of it doesn't work at all)
>
> from ctypes import *
>
> class Buffer(Structure):
>   # just to see if any useful data can be acquired
>   _fields_ = [
> ("Data0", c_longlong)
>,("Data1", c_longlong)
>,("Data2", c_longlong)
>,("Data3", c_longlong)
>,("Data4", c_longlong)
>,("Data5", c_longlong)
>,("Data6", c_longlong)
>,("Data7", c_longlong)
>,("Data8", c_longlong)
>,("Data9", c_longlong)
>,("DataA", c_longlong)
>,("DataB", c_longlong)
>,("DataC", c_longlong)
>,("DataD", c_longlong)
>,("DataE", c_longlong)
>,("DataF", c_longlong)
>   ]
>
> szName = c_char_p("SFSharedMemory_ALM")  # SpeedFan
> szName = c_char_p("$M$B$M$5$S$D$")# MBM
> # szName = c_char_p("blabla")  # not existing shared memory
>
> FILE_MAP_ALL_ACCESS  = 0xF001F
> FALSE = 0
>
> hMapObject = windll.kernel32.OpenFileMappingA(
>FILE_MAP_ALL_ACCESS
>   ,FALSE
>   ,szName
> )
> if (hMapObject == 0):
>   print "Could not open file mapping object"
>   raise WinError()
>
> pBuf = windll.kernel32.MapViewOfFile(
>  hMapObject
> ,FILE_MAP_ALL_ACCESS
> ,0
> ,0
> ,0
> )
>
>   if (pBuf == 0):
> print "Could not map view of file"
> raise WinError()
>   else:
> print repr(pBuf)
> print repr(hMapObject)
>
> pBuf_str = cast(pBuf, c_char_p)
> print repr(pBuf_str.value)
> print repr(pBuf_str)
>
> pBuf_buf = cast(pBuf, Buffer)
Here's the problem.  pBuf is a pointer to a Buffer structure, not the
buffer structure itself.
Something like
pBuf_buf = Buffer.from_address(pBuf)
may work.

Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (win32) speedfan api control

2005-04-06 Thread Claudio Grondi
I have got the specs for SpeedFan from
the SpeedFan author :-) ,
but ...
inbetween I found, that full specs of the
shared memory access to
fan speeds, board, CPU temperature data
are also exposed by the MBM application
  http://mbm.livewiredev.com
and already published online
(including C, VB, Delphi code examples).
but ...
I failed to get the data into
a Python script :-( .
For details see my other
"Problem with access to shared memory(W2K) /
ORIGINALLY (win32) speedfan api control"
posting.

Claudio


"Almico" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> "Claudio Grondi" <[EMAIL PROTECTED]> wrote in message
news:<[EMAIL PROTECTED]>...
> > your script works ok on my W2K box :-).
> >
> > It makes me curious if I can get also the
> > temperatures into Python script for
> > further processing as easy as the setting
> > of the checkbox is done? (I have not
> > much experience with this kind of
> > programming yet)
> > May I ask how did you get the
> > "TJvXPCheckbox" and the other
> > values necessary to access the program
> > GUI ? (as I can see, there is no source
> > code of SpeedFan available) ?
>
> SpeedFan publishes a Shared Memory area. Drop SpeedFan's author (me
> :-)) an email to get its specs.


-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with access to shared memory(W2K) / ORIGINALLY (win32) speedfan api control

2005-04-06 Thread Claudio Grondi
Background information:
-
in order to monitor mainboard sensory data
as fan speeds, temperatures, applications
like SpeedFan http://www.almico.com/speedfan.php
or MBM http://mbm.livewiredev.com/
can be used.
Both of the mentioned apps expose data got
from the hardware in a shared memory area.

The goal to achieve:
---
is to supervise the motherboard sensory
data from within a Python script

The approach:
---
access to the shared memory area
exposed by motherboard hardware
querying apps from Python script.

The problem:
-
the below listed script code returns
always same values, what
leads to the conclusion, that something
is going wrong.

Can anyone help?

Thanks in advance

Claudio

The code
-
  I use is provided also here:
 http://www.codecomments.com/Python/message430495.html
 http://mail.python.org/pipermail/python-list/2005-March/271853.html
(the mmap part of it doesn't work at all)

from ctypes import *

class Buffer(Structure):
  # just to see if any useful data can be acquired
  _fields_ = [
("Data0", c_longlong)
   ,("Data1", c_longlong)
   ,("Data2", c_longlong)
   ,("Data3", c_longlong)
   ,("Data4", c_longlong)
   ,("Data5", c_longlong)
   ,("Data6", c_longlong)
   ,("Data7", c_longlong)
   ,("Data8", c_longlong)
   ,("Data9", c_longlong)
   ,("DataA", c_longlong)
   ,("DataB", c_longlong)
   ,("DataC", c_longlong)
   ,("DataD", c_longlong)
   ,("DataE", c_longlong)
   ,("DataF", c_longlong)
  ]

szName = c_char_p("SFSharedMemory_ALM")  # SpeedFan
szName = c_char_p("$M$B$M$5$S$D$")# MBM
# szName = c_char_p("blabla")  # not existing shared memory

FILE_MAP_ALL_ACCESS  = 0xF001F
FALSE = 0

hMapObject = windll.kernel32.OpenFileMappingA(
   FILE_MAP_ALL_ACCESS
  ,FALSE
  ,szName
)
if (hMapObject == 0):
  print "Could not open file mapping object"
  raise WinError()

pBuf = windll.kernel32.MapViewOfFile(
 hMapObject
,FILE_MAP_ALL_ACCESS
,0
,0
,0
)

  if (pBuf == 0):
print "Could not map view of file"
raise WinError()
  else:
print repr(pBuf)
print repr(hMapObject)

pBuf_str = cast(pBuf, c_char_p)
print repr(pBuf_str.value)
print repr(pBuf_str)

pBuf_buf = cast(pBuf, Buffer)
print
print
print repr(pBuf_buf)
print
print repr(pBuf_buf.Data0)
print repr(pBuf_buf.Data1)
print repr(pBuf_buf.Data2)
print repr(pBuf_buf.Data3)
print repr(pBuf_buf.Data4)
print repr(pBuf_buf.Data5)
print repr(pBuf_buf.Data6)
print repr(pBuf_buf.Data7)
print repr(pBuf_buf.Data8)
print repr(pBuf_buf.Data9)
print repr(pBuf_buf.DataA)
print repr(pBuf_buf.DataB)
print repr(pBuf_buf.DataC)
print repr(pBuf_buf.DataD)
print repr(pBuf_buf.DataE)
print repr(pBuf_buf.DataF)
  #:if/else (pBuf == 0)

windll.kernel32.UnmapViewOfFile(pBuf)
windll.kernel32.CloseHandle(hMapObject)

The output
--
is always the same:

13107200
80
''
c_char_p('')


<__main__.Buffer object at 0x007E3570>

13107200L
0L
0L
0L
0L
0L
0L
0L
0L
0L
0L
0L
0L
0L
0L
0L



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (win32) speedfan api control

2005-04-05 Thread Almico
"Claudio Grondi" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
PROTECTED]>...
> your script works ok on my W2K box :-).
> 
> It makes me curious if I can get also the
> temperatures into Python script for
> further processing as easy as the setting
> of the checkbox is done? (I have not
> much experience with this kind of
> programming yet)
> May I ask how did you get the
> "TJvXPCheckbox" and the other
> values necessary to access the program
> GUI ? (as I can see, there is no source
> code of SpeedFan available) ?

SpeedFan publishes a Shared Memory area. Drop SpeedFan's author (me
:-)) an email to get its specs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (win32) speedfan api control

2005-04-04 Thread Claudio Grondi
>>It makes me curious if I can get also the
>>temperatures into Python script for
>>further processing

> Winspector is good for this kind of thing.

Thanks for the link to Winspector - with this
tool it's really easy to find out the names
required to get down to the window elements
of a running application.

In the special case of speedfan there seems
to be no way to get the temperatures shown
in Reading tab into a Python script, because
the texts with the temperature values are not
separate window elements. The only
message sent to "TJvPanel" (it's the class
of the element with the temperatures)  is
WM_PAINT with 0, 0 values, so the actual
temperatures are "hidden" from beeing
accessed as easy as the value of the
checkbox.
Knowing the rectangle of the "TJvPanel"
it should be probably possible to OCR
the text shown, but this is another story.

By the way: is there a free tool (primary
for Windows, but best for both Linux
and Windows) able to get the text of the
word under the current mouse pointer
position like it is done e.g. by Babylon
translator?

Claudio


"Simon Brunning" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> On Apr 3, 2005 1:52 AM, Claudio Grondi <[EMAIL PROTECTED]> wrote:
> > May I ask how did you get the
> > "TJvXPCheckbox" and the other
> > values necessary to access the program
> > GUI ? (as I can see, there is no source
> > code of SpeedFan available) ?
>
> Winspector is good for this kind of thing.
>
> http://www.brunningonline.net/simon/blog/archives/001320.html
>
> -- 
> Cheers,
> Simon B,
> [EMAIL PROTECTED],
> http://www.brunningonline.net/simon/blog/



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (win32) speedfan api control

2005-04-04 Thread Simon Brunning
On Apr 2, 2005 3:22 AM, tlviewer <[EMAIL PROTECTED]> wrote:
(Snip Windows GUI automation stuff.)

WATSUP includes a module for Windows GUI automation. It's probably
worth a look - it might save you from doing all the research that I
had to do!

http://www.tizmoi.net/watsup/intro.html

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (win32) speedfan api control

2005-04-04 Thread Simon Brunning
On Apr 3, 2005 1:52 AM, Claudio Grondi <[EMAIL PROTECTED]> wrote:
> May I ask how did you get the
> "TJvXPCheckbox" and the other
> values necessary to access the program
> GUI ? (as I can see, there is no source
> code of SpeedFan available) ?

Winspector is good for this kind of thing.

http://www.brunningonline.net/simon/blog/archives/001320.html

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (win32) speedfan api control

2005-04-03 Thread Cappy2112
Nice idea- getting the handle to a control.
But how do you know what to pass for wparam , lparam , flags ?

BTW- I don't see anything unique to Active Python here.
You can do all of this with the Python windows extensions, which can be
installed without Active Python.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (win32) speedfan api control

2005-04-02 Thread Claudio Grondi
your script works ok on my W2K box :-).

It makes me curious if I can get also the
temperatures into Python script for
further processing as easy as the setting
of the checkbox is done? (I have not
much experience with this kind of
programming yet)
May I ask how did you get the
"TJvXPCheckbox" and the other
values necessary to access the program
GUI ? (as I can see, there is no source
code of SpeedFan available) ?

Claudio

"tlviewer" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> hello,
>
> If you run the Mainboard monitor, speedfan, here is
> an ActivePython script to force automatic fan control.
> http://www.almico.com/speedfan.php
>
> It's a great example of how clean the WinApi interface is
> in ActivePython. The script sets focus to the checkbox of
> interest and toggles the checkbox. AFAIK, speedfan will only
> start without fan control, requiring the user to manually
> check the checkbox to turn it on.
>
> hope someone finds it useful,
> tlviewer
>
> #!/usr/bin/python
> # author: [EMAIL PROTECTED]
> # date: April 1, 2005
> # description: turn on SpeedFan automatic fan speed
> # keywords: speedfan readings
> #import win32api as ap
>
> import win32gui as wi
> import win32ui as ui
> import win32con as wc
>
> # dialog class name
> cl = "TJvXPCheckbox"
>
> try:
> hWnd = wi.FindWindowEx( 0, 0, "TForm1", "SpeedFan 4.20")
> print hWnd
> hWnd = wi.FindWindowEx( hWnd, 0, "TPageControl", "")
> print hWnd
> hWnd = wi.FindWindowEx( hWnd, 0, "TTabSheet", "Readings")
> print hWnd
> hWnd = wi.FindWindowEx( hWnd, 0, cl, "Automatic fan speed")
>
> print hWnd
> res = wi.SetForegroundWindow(hWnd)
> res=wi.SendMessageTimeout(hWnd,wc.WM_LBUTTONDOWN,wc.MK_LBUTTON,0,2,75)
> res = wi.SendMessageTimeout( hWnd,wc.WM_LBUTTONUP, 0, 0, 2, 75 )
> print res
> except:
> pass
> #end code



-- 
http://mail.python.org/mailman/listinfo/python-list


(win32) speedfan api control

2005-04-01 Thread tlviewer
hello,

If you run the Mainboard monitor, speedfan, here is
an ActivePython script to force automatic fan control.
http://www.almico.com/speedfan.php

It's a great example of how clean the WinApi interface is
in ActivePython. The script sets focus to the checkbox of
interest and toggles the checkbox. AFAIK, speedfan will only
start without fan control, requiring the user to manually
check the checkbox to turn it on. 

hope someone finds it useful,
tlviewer

#!/usr/bin/python
# author: [EMAIL PROTECTED] 
# date: April 1, 2005
# description: turn on SpeedFan automatic fan speed
# keywords: speedfan readings
#import win32api as ap 

import win32gui as wi
import win32ui as ui
import win32con as wc

# dialog class name
cl = "TJvXPCheckbox"

try:
hWndÂ=Âwi.FindWindowEx(Â0,Â0,Â"TForm1",Â"SpeedFanÂ4.20")Â
printÂhWndÂ
hWndÂ=Âwi.FindWindowEx(ÂhWnd,Â0,Â"TPageControl",Â"")ÂÂ
printÂhWnd
hWndÂ=Âwi.FindWindowEx(ÂhWnd,Â0,Â"TTabSheet",Â"Readings")
printÂhWnd
hWndÂ=Âwi.FindWindowEx(ÂhWnd,Â0,Âcl,Â"AutomaticÂfanÂspeed")

printÂhWnd
resÂ=Âwi.SetForegroundWindow(hWnd)
res=wi.SendMessageTimeout(hWnd,wc.WM_LBUTTONDOWN,wc.MK_LBUTTON,0,2,75)ÂÂ
resÂ=Âwi.SendMessageTimeout(ÂhWnd,wc.WM_LBUTTONUP,Â0,Â0,Â2,Â75Â)Â
printÂres
except:
pass
#end code
-- 
http://mail.python.org/mailman/listinfo/python-list