Test and Measurement Forum

th03lnx on Linux: Need feedback on hardware status

Having problems ? let us know the details here

th03lnx on Linux: Need feedback on hardware status

Postby dybdahl » Mon Nov 03, 2003 10:41 am

We will use the TH-03 to monitor temperatures in our server rooms, and for this purpose, it is extremely important to know, whether there actually is a temperature measurement going on.

As it is now, the th03lnx program only writes the temperatures to the shared memory, but it doesn't provide any information about the age of these measurements. This means, that the temperatures in the shared memory can be very old measurements, which are no longer valid.

There is a field named "active", but it seems to be stuck on 1 if you kill the th03lnx program.

I would strongly suggest to put a Linux timestamp into the shared memory every time the temperatures are updated - this would solve this problem, and should be quite easy to make.

I am more than willing to be a beta tester on this one :-)

Lars Dybdahl.

Postby markspencer » Wed Nov 05, 2003 10:35 am


It does dound like a good idea, I will place this as a wishlist item for the next software release.

Best regards,

Mark Spencer
User avatar
Site Admin
Site Admin
Posts: 598
Joined: Wed May 07, 2003 9:45 am

We solved the problem

Postby dybdahl » Wed Nov 05, 2003 10:56 am

I solved the problem this way:

I modified the th03shm.c program, so that it:

- Takes a parameter (0, 1 or 2), that specifies what temperature we want to read
- Exits with an error code and an error message if temperature is zero.
- Otherwise, it reads the temperature and writes it to stdout
- At last it zeroes the temperature.

Our network monitoring application (http://www.sysorb.com/) then queries the temperature once each minute. This is enough to ensure that the temperature is rewritten by th03lnx before the next measurement, and if th03lnx should fail to write new temperature measurements into share memory, then sysorb will issue an alert. Works perfectly... :-)

Here is the modified source-code of th03shm.c:

Code: Select all
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <syslog.h>
#include "th03lnx.h"

#define FALSE           0
#define TRUE            1

int main (int argc, char * const * argv)
  int           i;
  int           c;
  int           sm;
  int           found;
  int           idx;
  TH03_SHARED * sm_ptr;

  sm = shmget (TH03_DEFAULT_KEY, sizeof (TH03_SHARED), 0);
  if (sm < 0)
    printf ("th03shm: Unable to find shared memory\n");
    exit (1);
  sm_ptr = (TH03_SHARED *) shmat (sm, (void *) 0, 0);
  if (sm_ptr == (void *) -1)
    printf ("th03shm: Unable to attach shared memory %d %X\n", sm, sm_ptr);
    exit (2);

  if (!sm_ptr->active)
    printf ("th03shm: Th03 not active\n");
    shmdt (sm_ptr);
    exit (3);

  // Check parameters
  if (argc!=2) {
    printf ("th03shm: No parameter specified. Specify 0, 1 or 2.\n");
    shmdt (sm_ptr);
    exit (4);
  if (strcmp(argv[1],"0")==0) idx=0; else
  if (strcmp(argv[1],"1")==0) idx=1; else
  if (strcmp(argv[1],"2")==0) idx=2; else {
    printf ("th03shm: Invalid parameter specified. Specify 0, 1 or 2.\n");
    shmdt (sm_ptr);
    exit (5);

  // Wait until all of the temperatures goes non-zero
  if (sm_ptr->channel_values[idx]==0) {
    printf("FAILED - no measurement, yet\n");
    shmdt (sm_ptr);
    exit (6);
  } else {
    printf ("T%d=%.2f\n", idx, (float) sm_ptr->channel_values [idx] / 100);

  /* Use this line to kill the th03lnx driver
  sm_ptr->active = FALSE;

  shmdt (sm_ptr);


Make file th03shm

Postby Guest » Fri May 25, 2007 4:47 pm

Dear Linux Users,

I have successfully connected a TH03 unit using the th03lnx driver and have been able to obtain the 'tracking' information together with the temperature readout. The crunch comes when I cancel the driver and try to use the make file for the next stage of the set up. When I use the make th03shm.c command i get a reply saying that the commands cannot be found for lines 1 through 16. I also get a syntax error for line 36.
Does anyone have any suggestions as to what I might be doing wrong?



Return to Getting Started

Who is online

Users browsing this forum: No registered users and 0 guests