[VB6] TEMPer Gold USB HID Thermometer Class-VBForums
Results 1 to 16 of 16

Thread: [VB6] TEMPer Gold USB HID Thermometer Class

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,363

    Lightbulb [VB6] TEMPer Gold USB HID Thermometer Class

    Note

    Be sure to see the updated version (posted as version 2 below)!


    Some Background

    TEMPer is a series of products by PCsensor for measuring temperature (and in some cases humidity). There are many models on the market with varying capabilities. While some of the early units appear as USB Serial devices (COMx: ports) the newer ones are USB HID devices that use the standard Windows driver and don't require driver installation.

    TEMPerGold.cls is a Visual Basic 6.0 Class that works only with the TEMPer Gold product. It is a wrapper around the RDingUSB.dll that comes with the unit's software package. The software is a basic .Net application you may or may not find useful. There is basically ZERO documentation available on the companion mini-CD or online.

    TEMPer Gold runs from about $9 to $20 USD (depending on where you shop) if you are curious. I've never seen the red LED light up as described by PCsensor. But perhaps mine has a dummy LED where the LED would go, having been dropped to save costs?


    Basic Operation

    If you plug in the TEMPer Gold without installing any software it "installs" in Windows as two HID devices: one a keyboard and the other a special function device.

    As a "keyboard" you can make basic use of the TEMPer by opening Excel or even Notepad and then holding Caps Lock or Num Lock for 3 seconds, which makes it start "typing" readings until you hold down Caps Lock or Num Lock 3 seconds again.

    Details on using the sample .Net applet can be found on the PCsensor web site (see link above). I didn't install it because I have too much .Net clutter here right now anyway, and did not want to risk the cruft a poorly constructed installer might leave behind even after uninstalling it.


    Extracting RDingUSB.dll

    Since [version 1 of] my code requires this DLL you'll have to extract it in order to use TEMPerGold.cls yourself.

    The easiest way is to locate the MSI package containing the PCsensor demo applet and do an "administrative install" to extract the installation files to a folder. Example:

    Code:
    msiexec /a "d:\work\temper\thepackage.msi" /qb TARGETDIR="d:\work\temper\packagefiles"

    My Demo

    The attached demo Project archive contains all of the files needed to build and run the VB6 demo. However for it to run you'll need to either put RDingUSB.dll in the Project folder yourself, or else place it where a normal system DLL Search will find it.

    The demo as written manages the state of its UI to guide you through the right steps, but basically:
    • First you Open the device.
    • Then you can Get/Set the Calibration.
    • Then you can start taking sample readings.
    • Finally you Close the device.

    Calibration is an offset ranging from -8 to +7C, and it seems to be non-volatile. You only need to set it when you want to adjust it.


    Oof!

    This was a messy thing to track down and I had lots of false starts.

    While written only for the TEMPer Gold you can probably modify it to work for other TEMPer devices that are USB HID devices. The earlier models that present themselves as a USB COM-port might be easier to use but most of the logic in this class will not apply.

    From a DUMPBIN of the file the RDingUSB.dll is really a renamed SonixUSB.dll.


    Taking it Further

    You could easily write a data logger, charting application, etc. if you want one.

    I'm thinking of adding it as optional functionality to my GossCam webcam server posted here in another thread.
    Attached Images Attached Images   
    Attached Files Attached Files
    Last edited by dilettante; Aug 4th, 2012 at 09:17 AM. Reason: new version

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,363

    Re: [VB6] TEMPer Gold USB HID Thermometer Class

    Hmm, the HTTP webcam server suggests other possibilities.

    In addition to just displaying the temperature on the images, it could also log both temperatures and a "brightness" score for the image at the time of each sample. That might be interesting to use for graphing, one data point being somewhat boring by itself.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,363

    Re: [VB6] TEMPer Gold USB HID Thermometer Class

    BTW:

    You can find GossCam as part of this thread: AVICap32 Cam Streaming w/o Clipboard.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,363

    Re: [VB6] TEMPer Gold USB HID Thermometer Class

    Hmm...

    Even though PCsensor suggests these work on "NT" (I suspect they meant NT 4.0) it looks like this sort of USB HID device requires Windows 2000 or later, and may not work at all for Win9x.

    I haven't had a chance to confirm this though. Who actually has a machine with Windows 95 running on it these days? I sure don't, and do most of my Win9x testing in a VM. Even using a VM product that does USB pass-through from the host might not prove anything.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,363

    Version 2

    Well with a little more work I have produced another version.

    Also see version 2.4 posted below!

    TEMPerGold.cls version 2 has the following improvements:
    • No longer requires RDingUSB.dll, it does the job in pure VB6 and system API calls.
    • Should be able to handle multiple TEMPer Gold devices attached to the same system.

    The multiple-device functionality has not been tested, since I have only a single unit here.

    Do not be fooled by the attachment size, much of the increase consists of improved documentation. I have left the revision history comments in and added a section on Usage.


    I use an 8.x version of LINK.EXE so if you are still using the 6.0 version that ships with VB6 your binaries will be larger. But the version 1 demo consisted of the EXE (40KB here) and RDingUSB.dll (44KB).

    My version 2 demo doesn't need the extra DLL and compiles and links to a feathery 48KB for me. So not only is there one less dependency, there is a 36KB net savings! Not too shabby, if I do say so myself.
    Attached Files Attached Files
    Last edited by dilettante; Aug 14th, 2012 at 03:17 PM.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,363

    Re: [VB6] TEMPer Gold USB HID Thermometer Class

    Keep in mind that these demos (and both versions of the Class) aren't especially useful if you don't have a TEMPer Gold to play with.


    And while I am thinking about it:

    You should be able to use this Class from within VBA 6.x hosts too!
    Last edited by dilettante; Aug 3rd, 2012 at 03:02 AM.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,363

    Re: [VB6] TEMPer Gold USB HID Thermometer Class

    Update:

    As I expected, initial testing shows that this code also works with the external-probe TEMPer1 device. The TEMPer1 is packaged somewhat differently and has an external sensor connected by a cable that is about 3 feet long.
    Attached Images Attached Images  

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,363

    Re: [VB6] TEMPer Gold USB HID Thermometer Class

    I should have posted this very minor update a while back, but here it is now.

    This is version 2.4 and it has one significant change with a few minor changes:
    • Added Name(Dev) property.
    • Added range check on the IsOpen(Dev) property.
    • Added a few comments and corrected some typos.

    The significant change is the first one, which lets the client program retrieve the "names" of the devices found. This can be useful for programs that need to service multiple sensors since their sequence in the list cannot be guaranteed from run to run.

    To make a long story short, I've confirmed my class can handle multiple devices properly.


    The Long Story

    Right now the class can handle TEMPer1 and TEMPer Gold devices but these look identical in terms of USB product and vendor codes, etc. Even the firmware version string can be identical!

    In fact the only way they vary sems to be by where they are plugged into the PC. So these USB device names cannot absolutely tell you which is which. If you have two devices and swap them later your program will never "know" it. Examples:
    Code:
    \\?\hid#vid_0c45&pid_7401&mi_01#7&8fe1afd&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
    \\?\hid#vid_0c45&pid_7401&mi_01#7&1602e383&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
    This isn't as bad as it sounds though. Your program can map these names to a shorthand or descriptive name and the association should "stick" until you move devices around.


    How I Handle Mappings

    For example in one of my data logger programs I use an INI file to hold the mappings:
    Code:
    [Devices]
    \\?\hid#vid_0c45&pid_7401&mi_01#7&8fe1afd&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}=
    \\?\hid#vid_0c45&pid_7401&mi_01#7&1602e383&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}=
    
    [\\?\hid#vid_0c45&pid_7401&mi_01#7&8fe1afd&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}]
    SourceNameT1=Freezer1
    RecordT1=True
    SourceNameT2=RED7#9762T2
    RecordT2=False
    SourceNameH=RED7#9762H
    RecordH=False
    
    [\\?\hid#vid_0c45&pid_7401&mi_01#7&1602e383&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}]
    SourceNameT1=Freezer2
    RecordT1=True
    SourceNameT2=RED7#3487T2
    RecordT2=False
    SourceNameH=RED7#3487H
    RecordH=False
    Here the T1 items are the TEMPer Gold's single temperature measurement. The T2 and H items reflect possible future support for dual-sensor TEMPer devices that have either a 2nd temperature sensor or a humidity sensor.

    The SourceNameXX items in the INI file are manually configured once, after I do an initial run of my logger to scan for devices and build the INI file. Then I edit the file to set the individual sensor names I want and turn on recording for each.

    The RED7#9999XX type names are random unique names the INI builder inserts (RED7 here being the computer name). "Freezer1" and "Freezer2" are what I renamed the two active sensors my two TEMPer units have. Those names are carried in my data logs and can be used as charting curve series labels, etc.
    Attached Files Attached Files
    Last edited by dilettante; Aug 15th, 2012 at 08:11 PM. Reason: corrected confusing typo

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,363

    Re: [VB6] TEMPer Gold USB HID Thermometer Class

    The class and demo do not provide any charting or logging themselves. You'd have to write your own programs to do that, or log the data for import into Excel, etc.

    This isn't too bad though, and we always have the MSChart control in VB6.

    The example image here isn't the best (the greenhouse heater is designed to gently keep the temperature up in cold weather, not warm weather). It gives you the general notion though.
    Attached Images Attached Images  
    Last edited by dilettante; Aug 15th, 2012 at 07:52 PM.

  10. #10
    New Member
    Join Date
    Oct 2012
    Posts
    1

    Re: [VB6] TEMPer Gold USB HID Thermometer Class

    Hi,
    Excellent work and information. I was wondering if you can create a DLL for C# or tell how to use your code in Visual Studio 2010 to access and read data from Temper USB. Much obliged.
    I bought the device last week. I want to read data from it using Visual Studio 2010. C# is the requirement. I am not very experienced programmer. Just wanted to do experiments for knowledge seeking

    Tayyab

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,363

    Re: [VB6] TEMPer Gold USB HID Thermometer Class

    Sorry, I missed your post until just now.

    If you had the VB6 development system you could compile my class as a DLL and use it via COM Interop but since most C# users wouldn't normally have any need for VB6 they wouldn't have it to play with. I can't really do this for you myself for a couple of reasons:
    • We can't provide binary in attachments here.
    • The code is actually still pretty rough even though working and you'd almost certainly want to improve upon it yourself. So you really want source code and not a compiled DLL.


    Another option might be to acquire a version of VB.Net (which you may already have on hand depending on the Edition of Visual Studio .Net you use) and attempt an automated conversion and then polish that up. But the odds of that saving you any effort are probably pretty minimal. The conversion process VS provides for VB6-to-VB.Net is rough at best, and in this case there'd be a lot of PInvoke stuff which most likely makes things even rougher (mostly a ton of "TODO:" comments in the result).

    Your best bet would probably be a bunch of work, yet a lot less than some of the alternatives. You'd need to go through the source of one of the later versions of my TEMPer interface class pretty much line by line and convert it to C#, and then carefully go through and rewrite it as cleaner C#.


    If I were you here's how I'd tackle this:
    • Download my "version 1" attachment from very early in this thread. It has the shortest amount of code to translate because it uses the RDingUSB.DLL for the low-level operations.
    • Take the CD that came with your TEMPer or go to PCSensor's web site and get the software they provide for the device.
    • The software comes as an MSI installer package (or a ZIP archive with an MSI inside). Extract the MSI without installing it.
    • Dig into the extracted folder structure and grab the RDingUSB.DLL
    • Carefuly work through my TEMPerGold version 1 VB6 class, opening it in Notepad if nothing else. Translate what you find into a C# class.

    To extract the MSI I'd do something like this:
    • Create a junk folder someplace, the root of a D:\, etc. drive may be easiest. Let's say D:\RDing as an example.
    • Copy the MSI file into it, as in D:\RDing\TEMPer V23.4.msi
    • Open a command prompt and change the current drive and directory to D:\RDing
    • Extract by typing msiexec /a "D:\RDing\TEMPer V23.4.msi" /qb TARGETDIR="D:\RDing\Extracted"
    • Ok any UAC prompt, it thinks it is doing an administrative install but it doesn't install anything.
    • Then dig through the Extracted subfolder looking for the RDingUSB.DLL and copy that into your Project folder to use it.
    • Delete all of the junk folder and its contents.

    This involves the barest minimum of conversion effort for you. You can always go back and wade through my later versions to look at adding more features or bypassing the need for the RDingUSB.DLL after you get comfortable with things.

    About the only bizarre looking thing in the different versions of my classes above is probably where I build some Byte arrays of USB commands during the Class_Initialize event. There are trivial ways to do the same thing in C# as part of declarations.

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,363

    Re: [VB6] TEMPer Gold USB HID Thermometer Class

    It looks like I never did get around to posting any updates. Later the same month I obtained a TEMPerHUM Gold that meaures both temperature and humidity.

    I'm posting a TEMPerMulti.cls demo here that has the newest version of my class. It handles several of hese devices. I pretty much finished this last August but it is working so I'm not sure why I hadn't posted it here back then.

    I'm using the class as part of a weather station project. Basically I have a webcam, a TEMPerHUM, and a small USB hub inside a small birdhouse with an "extended USB cable" running back to a Windows Home Server 2011 machine indoors. It has been running well for a while (since early September or so).
    Attached Images Attached Images  
    Attached Files Attached Files

  13. #13
    New Member
    Join Date
    Sep 2013
    Location
    Southern Spain
    Posts
    1

    Re: [VB6] TEMPer Gold USB HID Thermometer Class

    Hi,
    Thanks for the work you have done on this. I have used your VB6 class to create a DLL which I have been able to call from C#.
    I thought you might like to know of a minor problem I encountered that you are unlikely to have hit.
    It worked instantly using an XP VM but kept failing in W8, both with my dll and with your Multi Demo application, obviously I suspected W8 or X64 problems.
    I tracked the problem down to my Dell touch screen monitor. It connects the touch via a HID device and that kept reporting "the process cannot access the file because it is being used by another process" in response to the CreateFile.
    I suppose that could happen with any other device that is in use. I patched around it accepting an error only if it was the VID of the Temper.

    I am using the TemperHum as part of my telescope focuser.

    Laurie

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,363

    Re: [VB6] TEMPer Gold USB HID Thermometer Class

    Hi Laurie,

    Glad this was useful to you.

    Sorry that you ran into that problem but at least you have a workaround/fix. Should be helpful information to others running into similar HID device collisions.

    One of the things I really don't care for is that sometimes the TEMPer devices can "go nuts" and automagically go into keyboard mode and start sending "types" data to the PC. So far I haven't found a solution, and it can be a serious problem if you do not have a program with keyboard focus active that can "eat" those keystrokes. Even when you have a key-eater it can lose focus and then the Desktop/Shell gets thoem and things can get really crazy!

    If there is a way to disable that function of these TEMPer devices I have not found it yet.

  15. #15
    New Member
    Join Date
    Oct 2013
    Posts
    1

    Re: [VB6] TEMPer Gold USB HID Thermometer Class

    Quote Originally Posted by dilettante View Post
    It looks like I never did get around to posting any updates. Later the same month I obtained a TEMPerHUM Gold that meaures both temperature and humidity.

    I'm posting a TEMPerMulti.cls demo here that has the newest version of my class. It handles several of hese devices. I pretty much finished this last August but it is working so I'm not sure why I hadn't posted it here back then.
    Attached is info on how to get the TEMPerNTC working. See attached example in C# and a fully debugged working executable, with comments in the code. TEMPerNTC provides 0.01 degree Celsius resolution and fast updates on the external sensor. It can be used with any NTC thermistor having a resistance of 10Kohm @ 25C and a Beta Value of 3950; these are available on eBay in many shapes and sizes for well under $1 each.

    Attachment removed by moderator.
    Last edited by Joacim Andersson; Oct 2nd, 2013 at 02:25 AM. Reason: Removed attachment

  16. #16
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,458

    Re: [VB6] TEMPer Gold USB HID Thermometer Class

    @snovotill: Welcome to the VBForums.

    I've removed your attachment since it contained both the compiled DLL as well as an EXE file. Binary files are not allowed to be used as attachments in this forum, only source code files are allowed. Also your code example is in C# while this is the CodeBank forum for VB6.
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.