Byte-operations.

D

Dave Rose

I hope someone can please help me. A few months ago, I found a VBS file,
MonitorEDID.vbs on the internet. It is great in that it will extract from the
registry of Windows the serial number of the attached monitor. (System
Administration / PC Inventory usage is obvious)

Standalone, it works fine. However, I'd like to integrate it with other system
interrogations via Tim Golden's WMI and Marc Hammonds Win32all to get RAM, HD
size, CPU, PC Serial Number, etc and to also take that info and toss into a
lite database, such as KirbyBase.

However, my Python is limited. I've gotten the first half of the program
translated (I believe, I haven't done exhaustive testing).

So, the data is stuck in a dictionary. A clipping is shown here:

{0: '\x00\xff\xff\xff\xff\xff\xff\x00$M\x93!\x01\ <-SNIP-> '}

Anyway, the functions from VBS I don't know how to translate to Python are:

# location(0)=mid(oRawEDID(i),0x36+1,18)
# location(1)=mid(oRawEDID(i),0x48+1,18)
#
# #you can tell if the location contains a serial number if it starts
with 0x00 00 00 ff
# strSerFind=chr(0x00) & chr(0x00) & chr(0x00) & chr(0xff)
#
# #or a model description if it starts with 0x00 00 00 fc
# strMdlFind=chr(0x00) & chr(0x00) & chr(0x00) & chr(0xfc)


# #the week of manufacture is stored at EDID offset 0x10
# tmpmfgweek=ord(mid(oRawEDID(i),0x10+1,1))


# #store it in month/year format
# if tmpEDIDMajorVer < 255-48 and tmpEDIDRev < 255-48 :
# tmpver=chr(48+tmpEDIDMajorVer) & "." & chr(48+tmpEDIDRev)
# else:
# tmpver="Not available"


# if (Byte1 and 16) > 0:
# Char1=Char1+4


If someone can help me understand what to do with these types of commands, I'd
be much appreciative. Once it's translated, I'd be happy to share this!


Thanks!
Dave
 
D

Dan Bishop

Dave said:
I hope someone can please help me. A few months ago, I found a VBS file,
MonitorEDID.vbs on the internet. ....[snip]...
Anyway, the functions from VBS I don't know how to translate to Python are:

# location(0)=mid(oRawEDID(i),0x36+1,18)
# location(1)=mid(oRawEDID(i),0x48+1,18)

IIRC, the BASIC mid$ function is mid(string, start, length), where the
starting index is 1-based. The Python equivalent is
string[start-1:start-1+length], so these two lines would convert to

location = [oRawEDID(i)[54:72], oRawEDID(i)[72:90]]
# #you can tell if the location contains a serial number if it starts
with 0x00 00 00 ff
# strSerFind=chr(0x00) & chr(0x00) & chr(0x00) & chr(0xff)

The "chr" function is the same in Python as in VB. But unlike VB, you
can use literals for special characters.

strSerFind = '\x00\x00\x00\xFF'

....[snip]...
# tmpver=chr(48+tmpEDIDMajorVer) & "." &
chr(48+tmpEDIDRev)

In python, the string concatenation operator is "+" instead of "&".
However, this line can be written more concisely as:

tmpver = "%c.%c" % (48 + tmpEDIDMajorVer, 48 + tmpEDIDRev)

But for single-digit integers, chr(48+n) is just an obscure way of
writing str(n), so what it really means is:

tmpver = "%s.%s" % (tmpEDIDMajorVer, tmpEDIDRev)
# if (Byte1 and 16) > 0:
# Char1=Char1+4

VB's "and" operator is a bitwise operator; the "if" statement is
testing whether bit 4 is set in Byte1. The Python equivalent is

if Byte1 & 0x10:
Char1 += 4
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,113
Latest member
Vinay KumarNevatia
Top