using System;
using TEMPer.Communication;
namespace TEMPerDemo
{
class Program
{
const String m_CallNumFormat = "000000";
const String m_TempFormat = "00.0000";
static void Main(string[] args)
{
double TempC;
double TempF;
int i;
String[] ComPorts = TEMPerInterface.FindDevices();
if (ComPorts.Length == 0) return;
TEMPerInterface[] Devices = new TEMPerInterface[ComPorts.Length];
for (i = 0; i < ComPorts.Length; i++)
Devices[i] = new TEMPerInterface(ComPorts[i]);
for (int CallNum = 1; CallNum <= 1000; CallNum++)
{
for(i = 0; i < Devices.Length; i++)
{
TempC = Devices[i].ReadTEMP();
TempF = TEMPerInterface.CtoF(TempC);
Console.WriteLine(" "
+ CallNum.ToString(m_CallNumFormat)
+ " - "
+ Devices[i].PortName
+ " - "
+ TempC.ToString(m_TempFormat) + " C"
+ " - "
+ TempF.ToString(m_TempFormat) + " F");
}
}
}
}
}
The results:
000001 - COM19 - 22.3750 C - 72.2750 F
000002 - COM19 - 22.3750 C - 72.2750 F
000003 - COM19 - 22.3750 C - 72.2750 F
000004 - COM19 - 22.3750 C - 72.2750 F
....
000049 - COM19 - 22.5000 C - 72.5000 F
000050 - COM19 - 22.5000 C - 72.5000 F
Requirements:
As of version 2008.01.29.1, the DLL no longer requires USBRDXP.DLL (thanks to Bob for the code that removed this dependency).
Notes:
The device speaks Celsius.. and as such only returns degrees in 0.1250 increments.
If you decide to use this library or the above code, please feel free to contact me with questions (not that I completely understand everything their original code is doing.. trust me, the decompiled code lacks a lot of context) or comments.. but please understand that I'm not responsible for any problems/issues that might crop up as a result of using this library.
The library only does a few things:
1. Reads the registry to list the system's com ports
2. Queries each COM port to find those that have a TEMPer device
3. Reads/writes to the COM port to get temperature data
That's it.. there's no other magic or trickery going on inside the library.
Download the DLL: TEMPer.Communication.dll (v. 2008.02.23.1)
Download the source code: TEMPer.cs (v. 2008.02.23.1)
Changes
------------
v.1
- Initial release
v.2008.01.29.1
- Removed static reference to SerialPort (I suspect this is why reading from multiple devices would fail when multiple instances were created. I'll have to wait for my new devices to arrive before I can verify this).
- Removed the dependency on the TEMPer driver/dll. Thanks to Bob (see comments below) for the C++ code to implement the TEMPer device verification manually. The code below was ported to C# to make things a bit easier on my end.
- Added a version to the DLL
v.2008.02.23.1
- GetPortNames() now uses the managed SerialPort.GetPortNames() instead of querying the windows registry.
- I experimented with the idea of making ReadTemp a static call (removing the need to create an instance of the TEMPerInterface class) but the overhead for initializing the device added more than 1 second to each read call (something I was not willing to live with). Instead, I cleaned up a bit of the code I borrowed form the original TEMPer exe which shaved a few hundred milliseconds off of each call.
- The SerialPort is only kept open for the initialization of the device and for each ReadTemp (previously, the SerialPort was not being closed at the end of every ReadTemp call). Leaving the SerialPort open (eliminating the overhead of opening/closing the SerialPort each time) caused major freezing issues on my Vista laptop. The performance gain was insignificant, so the SerialPort is now closed at the end of each ReadTemp call. As the SerialPort is closed at the end of each read, there is no longer a need to manually call the Close function on the TEMPerInterface class (therefore that function has been removed).

84 comments: