/* * hoitek.cpp * by Bernd Herd (C) 2009 (herdsoft.com) * * Based on: * tenma.c * by Robert Kavaler (c) 2009 (relavak.com) * * Utility program to read daata from a Houtek HID UART device. * This device is used in the USB cable for PeakTech 3315 DMM devices * and Likely Tinma 72-7730 DMM. * * Based on linux /dev/hidraw interface. This code is written as a driver with * some unit test code to show how to incorporate it into an application. * * To operate the unit test software: * 1. Plug the USB cable into your computer. * 2. Check which /dev/hidraw device was created. Normally it is /dev/hidraw0. * 3. Check for permissions. Maybe do chmod o+rw /dev/hidraw0 as root, or * chgrp dialout /dev/hidraw0 * 4. Compile the code: gcc -o hoitek hoitek.c * 5. Run the code using the device name as a parameter: * ./hoitek /dev/hidraw0 * 6. Turn on the DMM. * 7. Press the RS232 button the on the DMM for one second, it will beep. * 8. Have fun. * * This will display the raw data read from the device. * To interpret the data read you will need a DMM-Specific filter, * for example by calling: * * ./hoitek /dev/hidraw1 | ./peaktech3315 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #include #include #include #include #include #include #include #include /** * Open the given device * * @param devicename Filename of the /dev entry to open * @param bps Bits per second, 2400 for PeakTech 3315 and Tenma 72-7730 * * * @return File descriptor to be closed by a call to close(fd), * -1 on errors. */ int hoitek_open(const char *devicename, int bps) { unsigned char buf[6]; int fd = open(devicename, O_RDWR); if(fd >= 0) { buf[0] = 0; buf[1] = bps; buf[2] = bps>>8; buf[3] = bps>>16; buf[4] = bps>>24; buf[5] = 3; // 3 = 8 bits no parity?? if(write(fd, buf, sizeof(buf)) != sizeof(buf)) { perror("write hoitek config header"); close(fd); fd = -1; } } else { perror("open"); } return fd; } int main(int argc, const char **argv) { int fd = hoitek_open( argc>1 ? argv[1] : "/dev/hidraw0", 2400 ); if (fd != -1) { unsigned char buf[8]; int error=0; do { error = read(fd, buf, sizeof(buf))!=sizeof(buf); if (error) { perror("read"); } else { int i; int len=buf[0] & 7; for (i=0; i