Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Snapshot of screen

8 views
Skip to first unread message

VbPro7

unread,
Nov 19, 2009, 9:04:45 PM11/19/09
to
Hi VB lovers,

I'm using the following code to get a snapshot of the screen in a
StdPicture object.

http://www.devx.com/vb2themax/Tip/19172


However my problem is I need to get the space used (no of bytes) by the
image in memory. Is this possible? If not I would like to convert the image
into a JPG file and then get the size of file in bytes.
Size itself is not required actually. I just want to compare two images and
see if they are the same. The only way I can think of is to compare there
size/space in memory or disk. If there is another efficient way to do this
please advise.

Thanks

Dee Earley

unread,
Nov 20, 2009, 4:23:17 AM11/20/09
to

No, you can not relay on size to determine if they are the same.
Nor can you rely on different (non bitmap) binary data to say they are
different.

Bitmaps in memory are a fixed (height x width x bytes per pixel) +
header (with a few caveats for odd sizes and bit depths)
Once compressed, the final image data may contain other data so you are
unlikely to get exactly the same data for multiple encodes of the same
image.

The only way to reliably tell is to do a pixel by pixel comparison.
If the images will have been subject to lossy compression, you will have
to have a tolerance in there as well.

What are you actually trying to achieve by seeing if the screen has changed?

--
Dee Earley (dee.e...@icode.co.uk)
i-Catcher Development Team

iCode Systems

Dave O.

unread,
Nov 20, 2009, 8:45:27 AM11/20/09
to

"Dee Earley" <dee.e...@icode.co.uk> wrote in message
news:Ox51$IcaKH...@TK2MSFTNGP04.phx.gbl...

> The only way to reliably tell is to do a pixel by pixel comparison.
> If the images will have been subject to lossy compression, you will have
> to have a tolerance in there as well.

A while back I needed to compare bitmaps quickly and found that if I
combined 2 bitmaps using XOR (probably*) then if the pictures were identical
the result was pure black, then all I had to do was to zip through the
pixels of a single image looking for any non-zero value.
If the image is large you can save a bit of time by taking one half of the
result and XOR it with the other half, then repeat until down to a few
thousand pixels, again it will be all black if there were no non-black
pixels. Trial & error is probably the only way to find the optimum for
this.
Of course if the images were lossy such as JPEGs then it does get a lot
trickier as you'll get near black values, but that might be adequate to show
close similarity.

Another possibility that is best if you need to compare an image with
several others is to take the CRC of the images.

* Not sure it was XOR, could have been any logical operation and I don't
have the code to hand.

Dave O.


Nobody

unread,
Nov 20, 2009, 9:40:07 AM11/20/09
to
See this post, which gets the contents of a PictureBox as byte array. The
PictureBox AutoRedraw must be True. I believe you can adapt it to what you
need. I have made another that works regardless AutoRedraw property, but
it's few percentage points slower. That one uses BitBlt to copy PictureBox
contents to the compatible DC, instead of using the PictureBox autoredarw
bitmap itself.

http://groups.google.com/group/microsoft.public.vb.general.discussion/msg/9fafb6cfebff120e

Larry Serflaten

unread,
Nov 20, 2009, 2:45:33 PM11/20/09
to

"Dave O." <nob...@nowhere.com> wrote

> A while back I needed to compare bitmaps quickly and found that if I
> combined 2 bitmaps using XOR (probably*) then if the pictures were identical
> the result was pure black, then all I had to do was to zip through the
> pixels of a single image looking for any non-zero value.
> If the image is large you can save a bit of time by taking one half of the
> result and XOR it with the other half, then repeat until down to a few
> thousand pixels, again it will be all black if there were no non-black
> pixels. Trial & error is probably the only way to find the optimum for
> this.
> Of course if the images were lossy such as JPEGs then it does get a lot
> trickier as you'll get near black values, but that might be adequate to show
> close similarity.
>
> Another possibility that is best if you need to compare an image with
> several others is to take the CRC of the images.
>
> * Not sure it was XOR, could have been any logical operation and I don't
> have the code to hand.


I seem to recall a similar discussion...
http://groups.google.com/group/microsoft.public.vb.general.discussion/browse_thread/thread/a294f7e4aba0be1f/82bf4b082ec1c518?hl=en#82bf4b082ec1c518

"A while back" ? How about 8 years! <g>

LFS


Martin Trump

unread,
Nov 22, 2009, 7:56:54 AM11/22/09
to
> I'm using the following code to get a snapshot of the screen in a
> StdPicture object.
>
> http://www.devx.com/vb2themax/Tip/19172

Wow! What a chunk of code!

I think this fragment I have used could be adapted to your needs.

Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte,
ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

AppActivate getaviname
keybd_event vbKeyMenu, 0, 0, 0 ' Press ALT
keybd_event vbKeySnapshot, 0, 0, 0 ' Press Prntscr
keybd_event vbKeySnapshot, 0, 2, 0 ' Release Prntscr
keybd_event vbKeyMenu, 0, 2, 0 'Release ALT
pic2.Picture = Clipboard.GetData()
etc.
then save the picture

> However my problem is I need to get the space used (no of bytes) by the
> image in memory. Is this possible? If not I would like to convert the
> image into a JPG file and then get the size of file in bytes.

Comparing sizes of JPG's might be risky unless you know the level of
compression of each is the same.

HTH

Nobody

unread,
Nov 22, 2009, 9:43:44 AM11/22/09
to
"Martin Trump" <mar...@wmeadow.demon.co.uk> wrote in message
news:6yaOm.25276$tF6....@newsfe28.ams2...

>> http://www.devx.com/vb2themax/Tip/19172
>
> Wow! What a chunk of code!
>
> I think this fragment I have used could be adapted to your needs.
>
> Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal
> bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
>
> AppActivate getaviname
> keybd_event vbKeyMenu, 0, 0, 0 ' Press ALT
> keybd_event vbKeySnapshot, 0, 0, 0 ' Press Prntscr
> keybd_event vbKeySnapshot, 0, 2, 0 ' Release Prntscr
> keybd_event vbKeyMenu, 0, 2, 0 'Release ALT
> pic2.Picture = Clipboard.GetData()
> etc.
> then save the picture

I could think of three issues with the code you posted:

1 - It would erase the clipboard, and this may annoy the user.

2 - The code you posted would capture the active window only, while the
BitBlt method would capture any window unless it's obscured by other
windows, in which case it captures the area in the desktop that it would
usually occupy.

3 - You need to use "Set" with any object assignment, so use "Set
pic2.Picture = Clipboard.GetData()".


Martin Trump

unread,
Nov 22, 2009, 10:25:15 AM11/22/09
to

> I could think of three issues with the code you posted:
>
> 1 - It would erase the clipboard, and this may annoy the user.

Accepted but you could save and restore it if necessary.

> 2 - The code you posted would capture the active window only, while the
> BitBlt method would capture any window unless it's obscured by other
> windows, in which case it captures the area in the desktop that it would
> usually occupy.

Yes, but I did say it could be adapted. Just omit the ALT stuff.

> 3 - You need to use "Set" with any object assignment, so use "Set
> pic2.Picture = Clipboard.GetData()".

Really? pic2.Picture = Clipboard.GetData() seems to work for me.
Am I deluding myself? Often happens, I'm no expert :-)

Dave O.

unread,
Nov 23, 2009, 5:05:49 AM11/23/09
to

"Martin Trump" <mar...@wmeadow.demon.co.uk> wrote in message
news:bJcOm.130761$9M4.1...@newsfe03.ams2...

>
>> I could think of three issues with the code you posted:
>>
>> 1 - It would erase the clipboard, and this may annoy the user.

> Accepted but you could save and restore it if necessary.

If you knew how difficult that might be you would not say that.

The clipboard can contain the same information in several formats all of
which you would need to store and replace, for example a selection of a
Excel spreadsheet is stored in the clipboard as ALL of the following
clipboard formats:

Biff, Biff3, BIFF4, Biff5, Biff8, Bitmap, Csv, Data Interchange Format,
DataObject, Device Independent Bitmap, Embed Source, Enhanced Metafile, HTML
Format, Hyperlink, Link, Link Source, Link Source Descriptor, Locale
Identifier, Metafile, Microsoft Symbolic Link, Native, Object Descriptor,
ObjectLink, OEM Text, Ole Private Data, OwnerLink, Rich Text Format, Text,
Unicode Text, Unknown: -16639, Unknown: -16640, Unknown: 129, Unknown: 17,
Wk1 & XML Spreadsheet,

That is an extreme example but just a bit of plain text is in these formats:
Text, OEM Text, Unicode Text & Locale Identifier
Also if you've ever placed a list of files onto the clipboard using code
you'll know what fun that can be.

Regards
Dave O.

Dave O.

unread,
Nov 23, 2009, 5:08:28 AM11/23/09
to

"Larry Serflaten" <serf...@usinternet.com> wrote in message
news:OrVTGoha...@TK2MSFTNGP04.phx.gbl...
>
> "Dave O." <nob...@nowhere.com> wrote

That was a while wasn't it!
Well the technique seems to work well enough, thanks again for your help
back then when dinosaurs roamed the Earth.

Dave O.


H-Man

unread,
Nov 23, 2009, 11:22:27 AM11/23/09
to

right, size alone won't tell you anything for sure. That's what a ahsh
function is for. Using a simple CRC32 function on the two data sets would
tell you pretty much right away if the data is the same.


--
HK

Dave O.

unread,
Nov 23, 2009, 11:52:49 AM11/23/09
to

"H-Man" <Sp...@bites.fs> wrote in message
news:4b0ab6ba$0$65831$892e...@auth.newsreader.octanews.com...

Here's a thought, JPEGs being lossy tend to corrupt the image enough to make
comparisons tricky.
BMPs are not lossy but compared to JPEGs have huge file sizes.
Putting BMPs into a ZIP file can give as good, if not better compression
than JPEG and depending on which library you use (I use InfoZip) you can get
it to return the CRC of the file thus saving all that mucking about with CRC
routines.

So if he saves as BMP then sticks them into a ZIP file or files he can
compare easily and instead of a JPEG library he'll need a ZIP library, so
not really any change in overhead but a far simpler bit of coding.

Regards - Dave O.


Peter T

unread,
Nov 24, 2009, 4:39:24 AM11/24/09
to
"Martin Trump" <mar...@wmeadow.demon.co.uk> wrote in message

>> 3 - You need to use "Set" with any object assignment, so use "Set

>> pic2.Picture = Clipboard.GetData()".
>
> Really? pic2.Picture = Clipboard.GetData() seems to work for me.

Yes both w/out Set work for me, in VBA too. I've never quite understood why.

Regards,
Peter T

Nobody

unread,
Nov 24, 2009, 5:35:27 AM11/24/09
to
"Peter T" <peter_t@discussions> wrote in message
news:%23V0DEoO...@TK2MSFTNGP06.phx.gbl...

Looking at Object Browser(F2), the default property for both is "Handle". So
that line is equivalent to:

pic2.Picture.Handle = Clipboard.GetData().Handle


Peter T

unread,
Nov 24, 2009, 5:59:48 AM11/24/09
to

"Nobody" <nob...@nobody.com> wrote in message news:%

> "Peter T" <peter_t@discussions> wrote in message
>> "Martin Trump" <mar...@wmeadow.demon.co.uk> wrote in message
>>
>>>> 3 - You need to use "Set" with any object assignment, so use "Set
>>>> pic2.Picture = Clipboard.GetData()".
>>>
>>> Really? pic2.Picture = Clipboard.GetData() seems to work for me.
>>
>> Yes both w/out Set work for me, in VBA too. I've never quite understood
>> why.
>
> Looking at Object Browser(F2), the default property for both is "Handle".
> So that line is equivalent to:
>
> pic2.Picture.Handle = Clipboard.GetData().Handle

AhHa, similar in VBA
MSForms.Image.Picture - Property Picture As StdPicture
StdPicture.Handle As OLE_HANDLE
Default member of stdole.StdPicture

Intuitively I guess .Handle = .Handle is a tad more efficient. Or is it, any
reason to use or not use Set?

Regards,
Peter T

Ralph

unread,
Nov 24, 2009, 9:22:24 AM11/24/09
to

"Peter T" <peter_t@discussions> wrote in message
news:ewGI$UPbKH...@TK2MSFTNGP06.phx.gbl...

Which is "more efficient" has no impact since the decision of which contruct
to use has already made behind the scenes by the VB (or VBA) Editor/Parser
when the code is first typed or read into the parser. ie, the "dye has been
cast" before the code itself ever runs.

The question is whether or not one intends to assign or re-assign an object
reference or modify the attribute of an existing object. A poor choice only
manifests itself later if the resultant object is not what the programmer
intended.

As an aside, the VB Clipboard Object is a wrapper for the system Clipboard
which itself constructs an OLE Object of the particular type to return data.
(Or reuses an existing object to honor subsequent calls.) ie, the Clipboard
Object is a far busier and more complex critter than its simple interface
might imply. <g>

-ralph


Martin Trump

unread,
Nov 24, 2009, 11:06:14 AM11/24/09
to

>>> 3 - You need to use "Set" with any object assignment, so use "Set
>>> pic2.Picture = Clipboard.GetData()".
>> Really? pic2.Picture = Clipboard.GetData() seems to work for me.
>
> Yes both w/out Set work for me, in VBA too. I've never quite understood why.

All this is getting too complicated for me. For amusement only may I
claim to have the smallest VB project ever posted, one line of
executable code?

In VB a project put a button and a PictureBox on Form1. The _only_ code
is :-

Private Sub Command1_Click()

Picture1.Picture = Clipboard.GetData()

End Sub

Open any picture in Paint, CNTR+A, CNTR+C, run the VB and click the
button and the picture appears. KISS?

Peter T

unread,
Nov 24, 2009, 11:07:08 AM11/24/09
to
"Ralph" <nt_cons...@yahoo.com> wrote in message

> "Peter T" <peter_t@discussions> wrote in message
>> "Nobody" <nob...@nobody.com> wrote in message

OK "more efficient" was a poorly worded, but still not quite following.

> The question is whether or not one intends to assign or re-assign an
> object
> reference or modify the attribute of an existing object.

Say the intention is to assign the object (picture) to the control for
viewing, after which the object is not required for any other purpose.
Perhaps as in Martin's example -
(Set) pic2.Picture = Clipboard.GetData()

Or, if making a bmp (stdPicture) for viewing in the control

(Set) pic2.Picture = myStdPictureObject

Or, copy the picture from one control to another
(Set) pic2.Picture = pic1.Picture

To Set or not to Set or no difference?

> A poor choice only manifests itself later if the
> resultant object is not what the programmer intended

How might a poor choice of use of Set of manifest itself?

Regards,
Peter T


Dave O.

unread,
Nov 24, 2009, 11:23:00 AM11/24/09
to
"Ralph" <nt_cons...@yahoo.com> wrote in message
news:OUJyUHRb...@TK2MSFTNGP02.phx.gbl...

> As an aside, the VB Clipboard Object is a wrapper for the system Clipboard
> which itself constructs an OLE Object of the particular type to return
> data.
> (Or reuses an existing object to honor subsequent calls.) ie, the
> Clipboard
> Object is a far busier and more complex critter than its simple interface
> might imply. <g>
>
> -ralph

Hi

I posted a comment about that on 23 Nov '09 @ 10:05 but my Outlook Express
seems to be unable to resolve the comp.lang.basic.visual.misc newsgroup,
someone might want to re-post what I said to that group.

Regards
Dave O.


Bob Butler

unread,
Nov 24, 2009, 11:32:04 AM11/24/09
to

"Nobody" <nob...@nobody.com> wrote in message
news:%237HScHP...@TK2MSFTNGP02.phx.gbl...

That may explain that one but the same thing occurs other places (e.g. the
ADODB.CommandObject's ActiveConnection property). You can even create it
using VB.

Class1:
=======
Private moX As Object

Public Property Let MyProp(ByVal x As Object)
Set moX = x
End Property

Public Property Set MyProp(ByVal x As Object)
Set moX = x
End Property

Public Property Get MyProp() As Object
Set MyProp = moX
End Property

========
Module1:
========
Private Sub Main()
Dim c As Class1
Set c = New Class1
c.MyProp = Clipboard
MsgBox TypeName(c.MyProp)
c.MyProp = Nothing
End Sub

Since the Property Let actually uses Set the calling code can use or not use
Set and the result will be the same


Mike Williams

unread,
Nov 24, 2009, 11:49:45 AM11/24/09
to
"Ralph" <nt_cons...@yahoo.com> wrote in message
news:OUJyUHRb...@TK2MSFTNGP02.phx.gbl...

> . . . the "dye has been cast" before the code itself ever runs.

. . . and the die . . . that's been cast as well ;-)

Mike

Martin Trump

unread,
Nov 24, 2009, 12:03:38 PM11/24/09
to

> right, size alone won't tell you anything for sure. That's what a ahsh
> function is for. Using a simple CRC32 function on the two data sets would
> tell you pretty much right away if the data is the same.

If it's a .bmp the header (bytes 0-53) will be the same for a given
screen resolution. The picture data is in multiples of 4-bytes. Wouldn't
it be easier/quicker to do long word comparisons? Just a thought.

Nobody

unread,
Nov 24, 2009, 1:13:54 PM11/24/09
to
"Martin Trump" <mar...@wmeadow.demon.co.uk> wrote in message
news:rvTOm.2784$Lu6...@newsfe05.ams2...

I am a big believer in KISS too. The construct you are using works in this
particular situation because the object has default property(Handle), and
the object itself has limited properties, and they are set when the handle
property is modified. This does not work with most objects. If the object
doesn't have a default property, you get a compile time error until you use
Set. If it has default property, then only that property is copied. When you
use "Set" the object is not copied, but a reference is added to the already
existing object, unless you use "New" keyword, in which case another object
is created.

This sample illustrates:

Option Explicit

Private Sub Command1_Click()
Dim o As IPictureDisp

Set o = Clipboard.GetData
Picture1.Picture = o

Debug.Print Picture1.Picture.Handle
Debug.Print Picture1.Picture.Width
Debug.Print Picture1.Picture.Height
'Debug.Print Picture1.Picture.hPal
Debug.Print Picture1.Picture.Type

Debug.Print o.Handle
Debug.Print o.Width
Debug.Print o.Height
'Debug.Print o.hPal
Debug.Print o.Type
End Sub


Output:

Case 1: Without Set:

621091395
8387
3254
1
621091395
8387
3254
1

Case 2: Using Set:

352663803
8387
3254
1
352663803
8387
3254
1

The results are identical, but again, this won't work for most objects.


Ralph

unread,
Nov 24, 2009, 2:03:41 PM11/24/09
to

"Mike Williams" <Mi...@WhiskyAndCoke.com> wrote in message
news:%23hzWfYS...@TK2MSFTNGP02.phx.gbl...

Yeah, that too. <g>

Not sure why I used the word "dye" except by poorly formed habit when young,
as I have since made a conscious decision to force myself to use the more
commonly accepted quote as "the die is cast" from the reported - "Alea iacta
est". Where "alea" is most certainly the singular of the word for "dice" - a
gambling device.

However, it turns out that there are other reported quotes. Ignoring those
that suggest "die" is the pattern or mold before a metal is poured. (As they
are certainly insane.) The other has Caesar quoting a Greek idiom/proverb in
which once a "dye" or coloring substance has been thrown into the water
there is no going back. This is more colorful and seems a better fit for a
dramatic scene where Caesar, a man who ardently wanted to be viewed as
educated, is standing before the waters of the Rubicon.

[Patrician Romans loved quoting Greek phrases, and Caesar did so often in
his writings. Something akin to using French now days to sound more
enlightened.]

But since most historians of that time provide a quote referring to a
'gaming device' I've accepted that "the die is cast" is most likely correct.
I just can't always remember to catch myself before typing. <g>

-ralph


Bob Butler

unread,
Nov 24, 2009, 2:29:46 PM11/24/09
to

"Ralph" <nt_cons...@yahoo.com> wrote in message
news:O50agkTb...@TK2MSFTNGP06.phx.gbl...
<cut>

> However, it turns out that there are other reported quotes. Ignoring those
> that suggest "die" is the pattern or mold before a metal is poured. (As
> they
> are certainly insane.)

Why would they be certainly insane? If the die has been cast then you've
already made the piece so it's too late to make any more changes to the
die... seems to fit as well as the others.


Ralph

unread,
Nov 24, 2009, 2:49:57 PM11/24/09
to

"Bob Butler" <no...@nospam.ever> wrote in message
news:O8ehryTb...@TK2MSFTNGP02.phx.gbl...

I was referring to arguments (ahh ... discussions) I have had in the past
where others presented exactly that view. At that time I weighted their
argument and judged it lack sufficient merit for further consideration.
Having made that decision it became bewildering to me that anyone could
persist in their view. The only logical explanation is that they were
insane.

The older I get, the more insanity I seem to run across.

-ralph
<g>


Mike Williams

unread,
Nov 24, 2009, 3:30:00 PM11/24/09
to

"Ralph" <nt_cons...@yahoo.com> wrote in message
news:O50agkTb...@TK2MSFTNGP06.phx.gbl...

> Not sure why I used the word "dye" except by poorly formed
> habit when young, as I have since made a conscious decision
> to force myself to use the more commonly accepted quote as
> "the die is cast" from the reported - "Alea iacta est". Where
> "alea" is most certainly the singular of the word for "dice" - a
> gambling device.

Yep. That's certainly my own take on it.

> However, it turns out that there are other reported quotes.
> Ignoring those that suggest "die" is the pattern or mold before
> a metal is poured. (As they are certainly insane.)

Seems quite sane to me. At a push I'd accept that as an alternative.

> The other has Caesar quoting a Greek idiom/proverb in
> which once a "dye" or coloring substance has been thrown
> into the water there is no going back. This is more colorful

More colourful yes, but far less likely, and of course sheer lunacy ;-)

Mike

Bob Butler

unread,
Nov 24, 2009, 4:10:26 PM11/24/09
to

"Ralph" <nt_cons...@yahoo.com> wrote in message
news:%230lrW%23TbKH...@TK2MSFTNGP06.phx.gbl...

Ah, kind of like arguing that VB.Net is an enhanced version of VB.... I get
it.

> The older I get, the more insanity I seem to run across.

I know that feeling


Ralph

unread,
Nov 24, 2009, 5:09:27 PM11/24/09
to

"Bob Butler" <no...@nospam.ever> wrote in message
news:eRDt7qUb...@TK2MSFTNGP06.phx.gbl...

> >
> > I was referring to arguments (ahh ... discussions) I have had in the
past
> > where others presented exactly that view. At that time I weighted their
> > argument and judged it lack sufficient merit for further consideration.
> > Having made that decision it became bewildering to me that anyone could
> > persist in their view. The only logical explanation is that they were
> > insane.
>
> Ah, kind of like arguing that VB.Net is an enhanced version of VB.... I
get
> it.
>

Ha, that is a true example of insanity and an apt analogy.

The "die" as a pattern or mold crowd point to prior art and historical usage
to try and support their claim. But it fails when it is pointed out that
while "die" for a pattern/mold, and "die" for a gambling device, are
homonymic in English - both Latin and Greek words for the respective items
are completely different, and no historian of the period ever suggested
Caesar was referrng to "datum".

The "VB.Net is an enhanced version of VB" crowd can point to MS marketing to
back up their claims, but one only needs a quick glance at the parser to
appreciate they have very little in common.

-ralph


MoiInAust

unread,
Dec 3, 2009, 7:26:03 PM12/3/09
to
Mike!

If anyone knows it would be you. How can I read data from the USB port into
a vb6 progam?


Nobody

unread,
Dec 3, 2009, 7:46:32 PM12/3/09
to
"MoiInAust" <us...@user.com> wrote in message
news:4b185727$1...@dnews.tpgi.com.au...

> Mike!
>
> If anyone knows it would be you. How can I read data from the USB port
> into a vb6 progam?

See "Visual Basic 6" here:

http://www.lvr.com/hidpage.htm

For some reason the page does not appear completely in IE6. If this happens
to you, try another browser, like FireFox.

Main page:

http://www.lvr.com/usb.htm

MoiInAust

unread,
Dec 4, 2009, 2:56:02 PM12/4/09
to

"Nobody" <nob...@nobody.com> wrote in message
news:%239U%236sHdK...@TK2MSFTNGP06.phx.gbl...
Thanks for that, but I found it too lengthy and confusing.

I am trying to develop an application that reads voltages via the USB port
and presents them in a graph. Both the x and y will be associated with
voltage changes (ie time will not come into it). There will be no actual HID
devices to identify and I don't want an all singing and dancing general
application that will eg check which device is there. I don't want someone
to write the code. I am happy to sytruggle through that. But I do want to
know the syntax just to read voltages via the USB port. Like 'vbReadUSB'
or suchlike.
>


Jim Mack

unread,
Dec 4, 2009, 3:20:20 PM12/4/09
to
MoiInAust wrote:
>>
>> http://www.lvr.com/usb.htm
>>
> Thanks for that, but I found it too lengthy and confusing.
>
> I am trying to develop an application that reads voltages via the
> USB port and presents them in a graph. Both the x and y will be
> associated with voltage changes (ie time will not come into it).
> There will be no actual HID devices to identify and I don't want an
> all singing and dancing general application that will eg check
> which device is there. I don't want someone to write the code. I am
> happy to sytruggle through that. But I do want to know the syntax
> just to read voltages via the USB port. Like 'vbReadUSB' or
> suchlike.


What you're asking for doesn't exist. The USB port is a serial digital
port. It does not respond to analog voltage levels. That would require
an ADC.

You can buy ADCs that have a USB interface, which would come with a
driver and perhaps a software library / ActiveX. But there is no way
you will ever read varying analog voltages using the USB port alone.

--
Jim Mack
Twisted tees at http://www.cafepress.com/2050inc
"We sew confusion"

Schmidt

unread,
Dec 4, 2009, 3:24:50 PM12/4/09
to

"MoiInAust" <us...@user.com> schrieb im Newsbeitrag
news:4b196958$1...@dnews.tpgi.com.au...> > Main page:


> I do want to know the syntax just to read voltages
> via the USB port. Like 'vbReadUSB' or suchlike.

The "syntax" is defined by the vendor of your USB-
AD-converter-Box.

These usually come with a full set of drivers/APIs (for all
kind of languages) - in most cases even with VB5/6
sample-code (and an "USBDeviceAPI.bas" file, which
contains the appropriate Declares.

Here are some vendors, which I know, deliver
VB-modules with their boxes:

http://www.meilhaus.de/en/home/
(they distribute the LabJack-Boxes here, which you can
directly buy at: http://labjack.com/ too of course.


http://www.datatranslation.com/
(not the cheapest, but they offer true-parallel-AD-sampling
boxes in good quality - one of the not that costly ones
is the DT9810)

Don't know, what you have in mind exactly - if it needs to
be even smaller (in the 20$-range), in the last years nearly
each of the larger chip-vendors (Texas Instruments, Analog
Devices, etc.) has brought up nice "thumb-size" evaluation-
kits - usually involving a micro-processor with integrated
A/D-ports, Rs232, etc. - the PC-communication is then
done mostly over a virtual Rs232-port, which you could
read and write with the VB-COMM-control.
Here's an example-picture of that category.
http://focus.ti.com/graphics/tool/ez430-f2013.jpg

The datarate (the capture-frequency) - as well as the bit-depth
is not that high as with the "real measurement-boxes" above,
(which don't emulate a COM-port, but talk over their own
USB-drivers-API) but for many scenarios these small "sticks"
are good enough.

Olaf

MoiInAust

unread,
Dec 4, 2009, 4:04:49 PM12/4/09
to

"Jim Mack" <no-uc...@mdxi.com> wrote in message
news:LeKdnVDz6YCZ8oTW...@giganews.com...

THat's OK. I'm quite happy about an ADC, but how then to read the output
through the USB port into a vb prgram?


MoiInAust

unread,
Dec 4, 2009, 4:08:28 PM12/4/09
to

"Schmidt" <s...@online.de> wrote in message
news:%23sGipES...@TK2MSFTNGP05.phx.gbl...
These are great clues. Thanks for the replies Guys. What I am hoping to make
is a vb6 wobbulator. A swept RF signal passes over the bandwidth of an IF
and displays a graph of frequency versus amplitude. Gives the classic IF
characteristic. I can do this on an analogue scope but would like to do it
on a full sized flat screen and maybe display a graticule of frequency and
dBs too.


Schmidt

unread,
Dec 4, 2009, 6:20:47 PM12/4/09
to

"MoiInAust" <us...@user.com> schrieb im Newsbeitrag
news:4b19...@dnews.tpgi.com.au...

> These are great clues. Thanks for the replies Guys.
> What I am hoping to make is a vb6 wobbulator. A
> swept RF signal passes over the bandwidth of an IF
> and displays a graph of frequency versus amplitude.
> Gives the classic IF characteristic. I can do this on an
> analogue scope but would like to do it on a full sized
> flat screen and maybe display a graticule of frequency and
> dBs too.

Hmm, in what frequency-ranges do you want to get
that to work?
If you really mean radio-frequencies, then even the
more expensive USB-A/D-boxes are not able to
"keep pace" with such an requirement.

About 1-2MegaSamples per second is the maximum IMO
for "normal" AD-digitizing over USB - and radio-
frequencies are much higher than even that.

If you only want to do that in the "near NF"-range
(below 50kHz) "just for fun", then you can also use your
already built-in soundcard for that (on two channels with
16Bit each, up to a sample-rate of 48kHz).

For radio-frequency-capturing you need special hardware,
which has appropriate fast buffers built in, usually you're
capturing then only "certain, short events" which you can
adjust some "react to" triggers for in the RF/HF-hardware,
so that the internal buffers of the hardware (which can
only store captured HF-samples up to a certain amount ...
speaking: *time*), do not overflow.
Later on with your PC-based software, you typically only
read out the buffered content of such a "trigger-initiated and
captured timeframe" for your "RF-event of interest".

Olaf

MoiInAust

unread,
Dec 5, 2009, 4:58:14 AM12/5/09
to

"Schmidt" <s...@online.de> wrote in message
news:%23EFt9mT...@TK2MSFTNGP02.phx.gbl...
Thanks Olaf. I wanted to read 455 KHz +- 10 KHz so it sounds like no go.


Schmidt

unread,
Dec 5, 2009, 7:45:45 AM12/5/09
to

"MoiInAust" <us...@user.com> schrieb im Newsbeitrag
news:4b1a2eba$1...@dnews.tpgi.com.au...

> > About 1-2MegaSamples per second is the maximum IMO
> > for "normal" AD-digitizing over USB - and radio-
> > frequencies are much higher than even that.

> ...
> ...


> I wanted to read 455 KHz +- 10 KHz so it sounds like no go.

Given my above statement, if you use for example this device-category:
http://www.datatranslation.com/products/dataacquisition/usb/dt9832.asp

Then you can capture a 455kHz signal at a constant rate of
e.g. 2MSample/second (in 16Bit res.) - continously, since
these expensive boxes stream their data over the fast USB2.0
channel.

There are also cheaper USB-based "oscilloscopes" available,
which can work up to 50MHz - but the data from these
devices cannot be transferred continously to your PC-
software anymore - instead these "oszis" buffer shorter
time-intervals of the internally high-frequently captured data -
starting at a trigger-event - and what you get transferred
to your PC (continously) are only the contents of these
shorter time-frames.

Just google around a bit - there are also "specialized forums"
available, where hardware- (or electronics-) related questions
are better placed.

Olaf


MoiInAust

unread,
Dec 5, 2009, 12:45:20 PM12/5/09
to

"Schmidt" <s...@online.de> wrote in message
news:OAhbxoad...@TK2MSFTNGP05.phx.gbl...
Could you suggest such a forum? Also, although we are looking at the eg 455
KHz passband on an IF strip, I believe the data iteslf is much slower, as
the sweep is relatively slow, ie the speed of the sawtooth used to produce
it..


Martin Trump

unread,
Dec 6, 2009, 8:14:55 AM12/6/09
to
Care to e-mail me? Too off topic for clvbm

Schmidt

unread,
Dec 6, 2009, 9:03:22 AM12/6/09
to

"MoiInAust" <us...@user.com> schrieb im Newsbeitrag
news:4b1a9c31$1...@dnews.tpgi.com.au...

> Could you suggest such a forum?

Only from short googling for "electronics radio forum":
http://www.drmrx.org/
Would say, the guys there know very well, what you
want to achieve (working on the IF-result of a
HF-mixer "in software").
At least they should have better suggestion, where
to look elsewhere, to achieve your goals (just in case
they cannot help you).

> Also, although we are looking at the eg 455 KHz
> passband on an IF strip, I believe the data iteslf is
> much slower, as the sweep is relatively slow, ie the
> speed of the sawtooth used to produce it..

If that is more meant, with regards to the "price-point"
of such an "ready-to-use" 2MSamples-USB-device -
I'm sure there are also cheaper ones from other vendors.

If you want to save even more money on the needed
hardware, you could also develop a small board yourself,
there are so many nice micro-controller(eval boards) out there -
even the 32Bit ARM-based ones are not that expensive anymore -
with support for fast USB-transfers and with digital ports,
where you could bind the A/D-converter chip of your choice
...and with a little bit of C-programming you could bring such
a design to work then - or use prebuilt boards from people
who've been "already there" - would say the above mentioned
forum is a good place to ask all that.

Olaf


Dr J R Stockton

unread,
Dec 6, 2009, 5:54:58 PM12/6/09
to
In comp.lang.basic.visual.misc message <4b1a2eba$1...@dnews.tpgi.com.au>,
Sat, 5 Dec 2009 20:58:14, MoiInAust <us...@user.com> posted:

>
>Thanks Olaf. I wanted to read 455 KHz +- 10 KHz so it sounds like no go.
>

If it is bandwidth-limited to 10 kHz then one can recover the waveform
by sampling at only about 10 000 samples/second.

--
(c) John Stockton, near London. *@merlyn.demon.co.uk/?.?.Stockton@physics.org
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Correct <= 4-line sig. separator as above, a line precisely "-- " (SoRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)

Jim Mack

unread,
Dec 6, 2009, 7:27:45 PM12/6/09
to
Dr J R Stockton wrote:
> In comp.lang.basic.visual.misc message
> <4b1a2eba$1...@dnews.tpgi.com.au>, Sat, 5 Dec 2009 20:58:14, MoiInAust
> <us...@user.com> posted:
>>
>> Thanks Olaf. I wanted to read 455 KHz +- 10 KHz so it sounds like
>> no go.
>>
>
> If it is bandwidth-limited to 10 kHz then one can recover the
> waveform by sampling at only about 10 000 samples/second.

Nyquist says you need at least two samples per cycle to adequately
recover the waveform.

Martin Trump

unread,
Dec 7, 2009, 7:55:08 AM12/7/09
to

> Nyquist says you need at least two samples per cycle to adequately
> recover the waveform.

I have to wonder if this thread has gone down a blind alley. As I see it
the OP probably wants just the amplitude of the IF strip's output, not
to reconstruct the waveform. Just a guess.

Jim Mack

unread,
Dec 7, 2009, 8:05:35 AM12/7/09
to
Martin Trump wrote:
>> Nyquist says you need at least two samples per cycle to adequately
>> recover the waveform.
>
> I have to wonder if this thread has gone down a blind alley.

Or just a side street. Wouldn't be the first one.

> As I see it the OP probably wants just the amplitude of the IF

> strip's output...

I'm sure you're right. The question is, how often does he want to read
the amplitude? (-:

Martin Trump

unread,
Dec 7, 2009, 8:26:34 AM12/7/09
to

>> As I see it the OP probably wants just the amplitude of the IF
>> strip's output...
>
> I'm sure you're right. The question is, how often does he want to read
> the amplitude? (-:

Good question. Many factors involved but principally the frequency sweep
rate of the i/p. I think better the OP should post again and give some
more details rather than we hypothesize.

Martin

MoiInAust

unread,
Dec 7, 2009, 11:24:28 PM12/7/09
to

"Martin Trump" <mar...@wmeadow.demon.co.uk> wrote in message
news:oW6Tm.73773$os.6...@newsfe25.ams2...

Yes, graphing the amplitude against the frequency should give a resonance
curve. Eg frequency 455 KHz +- 20 KHz perhaps gives a curve similar to a
curve of normal distribution. If there is a crystal or mechnical filter the
curve will be much sharper but should be symmetrical if the filter is on
frequency.


MoiInAust

unread,
Dec 8, 2009, 4:19:17 AM12/8/09
to

"MoiInAust" <us...@user.com> wrote in message
news:4b1dd502$1...@dnews.tpgi.com.au...
And to answer the other question, the sweep need only be fat enough to give
a good stable trace on the oscilloscope/screen, say 50 Hz?


MoiInAust

unread,
Dec 8, 2009, 1:03:53 PM12/8/09
to
> And to answer the other question, the sweep need only be fat enough to
> give a good stable trace on the oscilloscope/screen, say 50 Hz?
That was meant to be *fast* enough!


Dr J R Stockton

unread,
Dec 8, 2009, 12:27:15 PM12/8/09
to
In comp.lang.basic.visual.misc message <7ZSdnfmPFtac0YHWnZ2dnUVZ_r2dnZ2d
@giganews.com>, Sun, 6 Dec 2009 19:27:45, Jim Mack <no-uc...@mdxi.com>
posted:

>Dr J R Stockton wrote:
>> In comp.lang.basic.visual.misc message
>> <4b1a2eba$1...@dnews.tpgi.com.au>, Sat, 5 Dec 2009 20:58:14, MoiInAust
>> <us...@user.com> posted:
>>>
>>> Thanks Olaf. I wanted to read 455 KHz +- 10 KHz so it sounds like
>>> no go.
>>>
>>
>> If it is bandwidth-limited to 10 kHz then one can recover the
>> waveform by sampling at only about 10 000 samples/second.
>
>Nyquist says you need at least two samples per cycle to adequately
>recover the waveform.

A little knowledge is a dangerous thing; and that you have. You should
read <http://en.wikipedia.org/wiki/Nyquist-Shannon_sampling_theorem#Shan
non.27s_original_proof> and <http://en.wikipedia.org/wiki/Nyquist-
Shannon_sampling_theorem#Sampling_of_non-baseband_signals>, for example.

Nyquist said what you say, but in conjunction with a condition that I
expressly ruled out.

You should read all of the pages cited by <http://en.wikipedia.org/wiki/
Nyquist> in connection with Harry Nyquist and sampling.

Schmidt

unread,
Dec 12, 2009, 2:48:52 PM12/12/09
to

"Dr J R Stockton" <repl...@merlyn.demon.co.uk> schrieb im Newsbeitrag
news:eRFTqnDz...@invalid.uk.co.demon.merlyn.invalid...

> >>> ... I wanted to read 455 KHz +- 10 KHz so it sounds like


> >>> no go.
> >>>
> >>
> >> If it is bandwidth-limited to 10 kHz then one can recover the
> >> waveform by sampling at only about 10 000 samples/second.
> >
> >Nyquist says you need at least two samples per cycle to
> >adequately recover the waveform.
>

> A little knowledge is a dangerous thing; and that you have...

Hmm, at least it was a recommendation which would have
worked (for sure) in the given case.

If you sample a given 455kHz (+-10kHz) signal at only
10kSamples/sec, then you place the Nyquist-frequency (zone)
of the ADC at 5kHz - and (sub-)sampling the input-signal
this way, would give you backfolded frequencies at multiples
of 5KHz max only - therefore not covering the +-10kHz-input-
range fully.

So your recommendation of "about 10 000 samples/second"
would not work. ;-)

Olaf

Dr J R Stockton

unread,
Dec 13, 2009, 12:57:32 PM12/13/09
to
In comp.lang.basic.visual.misc message <ufET1V2e...@TK2MSFTNGP02.ph
x.gbl>, Sat, 12 Dec 2009 20:48:52, Schmidt <s...@online.de> posted:

There is a difference, of a factor of two, between 455 +- 10 kHz,
bandwidth 20 kHz, and 455 kHz bandwidth 10 kHz. Also, "about" is quite
an elastic term.

The need is to take samples at more than twice the rate corresponding to
the bandwidth, and to do so long and accurately enough to obtain
sufficient resolution.

In one case I used to deal with, the bandwidth was as near to zero as
the finest known oscillator makers could do it (i.e. a good sine wave),
the sample rate was either faster or slower than twice the wave
frequency, and (leaving out other considerations) the need was to
recover in effect the amplitude and phase.

--
(c) John Stockton, near London. *@merlyn.demon.co.uk/?.?.Stockton@physics.org
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.

Correct <= 4-line sig. separator as above, a line precisely "-- " (RFC5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFC5536/7)

Schmidt

unread,
Dec 14, 2009, 8:29:55 AM12/14/09
to

"Dr J R Stockton" <repl...@merlyn.demon.co.uk> schrieb im Newsbeitrag
news:XbUx43CM...@invalid.uk.co.demon.merlyn.invalid...

[SubSampling a given input-signal at a lower than "Nyquist-rate"... ]

> >If you sample a given 455kHz (+-10kHz) signal at only
> >10kSamples/sec, then you place the Nyquist-frequency (zone)
> >of the ADC at 5kHz - and (sub-)sampling the input-signal
> >this way, would give you backfolded frequencies at multiples
> >of 5KHz max only - therefore not covering the +-10kHz-input-
> >range fully.
> >
> >So your recommendation of "about 10 000 samples/second"
> >would not work. ;-)
>
> There is a difference, of a factor of two, between 455 +- 10 kHz,
> bandwidth 20 kHz, and 455 kHz bandwidth 10 kHz. Also,
> "about" is quite an elastic term.

Sure... ;-)

> The need is to take samples at more than twice the rate

> corresponding to the bandwidth...
That's not the only condition - you would also need to take
care, to place the "starting-point" of such a "SubSampling-
Nyquist-zone" exactly at the "center-point" (in our
example the 455kHz) - or choose a twice or three times
as large sample-rate - and place the "starting-point" below
the lowest frequency of the interval ...(here: 445kHz) and
do a "center-correction" in software.

In the OPs case a "correct centering" would be achievable
with a sample-frequency of:
70kHz
(which would give a Nyquist-zone-window of 35KHz) ...
and multiplied: (13 * 35 = 455) this would meet the condition
(this is the lowest frequency which fulfills the requirements, as
long as one wants to calculate with "whole numbers only").

For not that easy to "produce" sampling frequencies of:
30,333333333333KHz
Nyquist-zone-window = 15.1666666666666KHz
(the multiplier to reach 455kHz exactly would be 30 then)
or
a sample-frequency of:
20.222222222222kHz
Nyquist-zone-window = 10.111111111111KHz
(the multiplier to reach 455kHz exactly would be 45 then)
...the approach would also work, but these are unusual,
difficult to ensure sample-frequencies.

Otherwise (placing the "Nyquist-zone-backfolding-point" not
exactly at the center-frequency, but somewhere "within") the
approach would require a lot of corrections in software - really
don't know, if the OP wants to go there and is able to handle
the approach correctly in these "special cases".

Also required (although being lower) would be a very *stable*
sampling-frequency (and a very short sample-and-hold interval
IMO, working at least "at the level" of 455kHz), to reduce
jitter and make that backfolding-approach a:
"reliably working success without surprises". ;-)

So, the "brute-force-approach" is not a bad recommendation,
since the potential surprises are lowered (at the cost of
somewhat higher harware-requirements). So it boils down
(as always) to the wellknown:
larger hardware-fixcosts (bought 3rd-party stuff)
vs.
knowledge+time (to grow "your own, cheaper thing")

But we're getting more and more off-topic now -
a hardware- (or electronics-) forum would really be a better
place to discuss such things.


Olaf


0 new messages