Jump to content

Recommended Posts

Posted

I know that this theme was discussed several times but I read all These threats with no helping result.

I have two pieces of TEMPer1F USB Thermometer.

It is a Standard Windows HID device with no add. Driver needed.

With the device I got an App reading from it and showing Graphs and much more and which can handle several devices.

With the Software came also a RDingUSB.dll file handling the communication with the device.

I can call the dll without any error. But the Problem is how to Access the device using the DLL and Access more than one of same VID/PID

by Serial or anything else useful.

I have also sources in c# doing the Job, but no experience in C# to successfuly port it to AutoIT.

 

So my question: Can anyone help me to realize the simple pull of the temperature value from the devices based on C# source?

The rest to write it to MySQL DB and repeat it etc. is no Problem for me.

***************************************

The C# part with the DLL functions class:

***************************************

using System;
using System.Runtime.InteropServices;

namespace TEMPer
{
  internal class RDing
  {
    [DllImport("RDingUSB.dll")]
    public static extern IntPtr OpenUSBDevice(int VID, int PID);

    [DllImport("RDingUSB.dll")]
    public static extern IntPtr CloseUSBDevice(IntPtr hDevice);

    [DllImport("RDingUSB.dll")]
    public static extern bool WriteUSB(IntPtr hDevice, byte[] pBuffer, uint dwBytesToWrite, ref ulong lpNumberOfBytesWritten);

    [DllImport("RDingUSB.dll")]
    public static extern bool ReadUSB(IntPtr hDevice, byte[] pBuffer, uint dwBytesToRead, ref ulong lpNumberOfBytesRead);

    [DllImport("RDingUSB.dll")]
    public static extern ushort GetInputLength(IntPtr hDevice);

    [DllImport("RDingUSB.dll")]
    public static extern ushort GetOutputLength(IntPtr hDevice);

    [DllImport("RDingUSB.dll")]
    public static extern uint GetErrorMsg(ref string[] lpErrorMsg, uint dwErrorMsgSize);
  }
}

*********************************

The C# code snippet working with the functions of the class above is in the attachment

this is the interesting part where the data is sent and pulled which I

do not understand to transcode to AutoIT

Important my devices are the type2 (TEMPer1F) :

*********************************

So in the end I Need: Call DLL, read all devices in array

Loop the Array until ubound(Array) and for each device in Array read the temperature value and prepare the data to

decimal 6,1 (SQL Format) and °C

So how to pull the value from the devices?

Maybe somwbody finds the important part in the C#  (the code above is for different models, mine is TEMPer1F

Or maybe someone has solved this and has maybe a uDF for this

 

 

MainForm.cs

  • 2 weeks later...
Posted

What I have for now is scanning for the devices using WMI and write the deviceID's to array

So net step is how to open the device and send data, and receive data.

What I understand from the code is, that it sends array of 9 byte and receives array with 9 bytes.

first it has to send 9 byte with settings for getting the calibration data and next the 9 byte to get the temperature value

and this is as I understand in byte 7 and 8 as byte and has to be converted to INT and then calcualted with the converted calibration value to get the

correct temp-values.

But how can this be done. Anyone experiences with communication with USB HID devices?

My actual code:

**********************************

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <Math.au3>
#include <Date.au3>
#include <Misc.au3>
#include <StructureConstants.au3>
#Include <WinAPI.au3>
#include <RawInput.au3>


$temp1 = 0;
$temp2 = 0;


$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

;$readCalibCmd  = new byte[] ( ................................?);
$readTemperCmd = new byte[] ( 0, 1, 0x80, 0x33, 1, 0, 0, 0, 0 );
$writeDataCmd  = new byte[] ( 0, 1, 0x81, 0x55, 1, 0, 0, 0, 0 );

Global Const $SP_DEV_BUF = "byte[9]";

hotkeyset("{Esc}","Terminate")

Func Terminate()
    Exit 0
EndFunc   ;==>Terminat

$stringDevices = "";


Local $vObjWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")

 

    $vObjItem = $vObjWMI.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE '%VID_0C45&PID_7401\\%' ","WQL",$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    ;MsgBox(0, "Fehler", @error);
    If IsObj($vObjItem) then

        For $objItem In $vObjItem
            
            
        ;here has to be what I need    
        ;$calibValArray =     array.....
        ;tempValArray   =     array.....    
            
        ;CalculTION OF CORRECT TEMPERATURE VALUE BASED ON CALIBRATION AND TEMPERATURE DATA            
            

        $stringDevices = $stringDevices & $objItem.DeviceID & @CRLF;


        Next
    Msgbox(1,"TEMPER1F Geräte",$stringDevices); Actually shows up all found devices with the VID/PID and suppressed NULL Devices/Interfaces
    Endif

***************************

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...