Voltcraft waveform dump


A tiny C- tool for reading the internal memory of the Voltcraft(R) Oszilloskop 650 A/D.

You can use kst for viewing the data.



file: http://darcs.erazor-zone.de/voltcraft/main.c

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <string.h>
/*
	baudrate settings are defined in <asm/termbits.h>, which is
	included by <termios.h>
*/
#define BAUDRATE B9600
/* change this definition for the correct port */
#define MODEMDEVICE "/dev/ttyS0"
#define _POSIX_SOURCE 1 /* POSIX compliant source */
 
const float vertical_scale_table[]={
	20,10,5,2,
	1,0.5,0.2,0.1,
	50E-3,20E-3,10E-3,5E-3,
	2E-3,1E-3
};
 
const float horizontal_scale_table[]={
	100,50,20,
	10,5,2,
	1,0.5,0.2,
	0.1,50E-3,20E-3,
	10E-3,5E-3,2E-3,
	1E-3,0.5E-3,0.2E-3,
	0.1E-3,50E-6,20E-6,
	10E-6,5E-6,2E-6,
	1E-6,0.5E-6,0.2E-6
};
 
int serial_fd;
 
int serial_send_buffer(char* buffer, unsigned int lenght);
int serial_read_buffer(void);
 
int main() {
	int fd,c,res;
	struct termios oldtio,newtio;
	char buffer[1024];
	unsigned int buffer_index;
 
	unsigned int vertical_scale_index,horizontal_scale_index;
 
	float horizontal_scale,vertical_scale;
	/* 
		Open modem device for reading and writing and not as controlling tty
		because we don't want to get killed if linenoise sends CTRL-C.
	*/
	serial_fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
	if (serial_fd <0) {
		perror(MODEMDEVICE);
		exit(-1);
	}
 
	/* 
		BAUDRATE: Set bps rate. You could also use cfsetispeed and cfsetospeed.
		CRTSCTS : output hardware flow control (only used if the cable has
					all necessary lines. See sect. 7 of Serial-HOWTO)
		CS8     : 8n1 (8bit,no parity,1 stopbit)
		CLOCAL  : local connection, no modem contol
		CREAD   : enable receiving characters
	*/
	newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
 
	/*
		IGNPAR  : ignore bytes with parity errors
		ICRNL   : map CR to NL (otherwise a CR input on the other computer
					will not terminate input)
		otherwise make device raw (no other input processing)
	*/
	newtio.c_iflag = IGNPAR | ICRNL;
 
	/*
		Raw output.
	*/
	newtio.c_oflag = 0;
 
	/*
		ICANON  : enable canonical input
		disable all echo functionality, and don't send signals to calling program
	*/
	newtio.c_lflag = ICANON;
 
	/* 
		initialize all control characters 
		default values can be found in /usr/include/termios.h, and are given
		in the comments, but we don't need them here
	*/
	newtio.c_cc[VINTR]    = 0;     /* Ctrl-c */ 
	newtio.c_cc[VQUIT]    = 0;     /* Ctrl-\ */
	newtio.c_cc[VERASE]   = 0;     /* del */
	newtio.c_cc[VKILL]    = 0;     /* @ */
	newtio.c_cc[VEOF]     = 4;     /* Ctrl-d */
	newtio.c_cc[VTIME]    = 0;     /* inter-character timer unused */
	newtio.c_cc[VMIN]     = 1;     /* blocking read until 1 character arrives */
	newtio.c_cc[VSWTC]    = 0;     /* '\0' */
	newtio.c_cc[VSTART]   = 0;     /* Ctrl-q */ 
	newtio.c_cc[VSTOP]    = 0;     /* Ctrl-s */
	newtio.c_cc[VSUSP]    = 0;     /* Ctrl-z */
	newtio.c_cc[VEOL]     = 0;     /* '\0' */
	newtio.c_cc[VREPRINT] = 0;     /* Ctrl-r */
	newtio.c_cc[VDISCARD] = 0;     /* Ctrl-u */
	newtio.c_cc[VWERASE]  = 0;     /* Ctrl-w */
	newtio.c_cc[VLNEXT]   = 0;     /* Ctrl-v */
	newtio.c_cc[VEOL2]    = 0;     /* '\0' */
	/* 
		now clean the modem line and activate the settings for the port
	*/
	tcflush(serial_fd, TCIFLUSH);
	tcsetattr(serial_fd,TCSANOW,&newtio);
 
	/*
		terminal settings done, now handle input
		In this example, inputting a 'z' at the beginning of a line will 
		exit the program.
	*/
 
	write(serial_fd,"*IDN?\n",6);
	buffer[read(serial_fd,buffer,100)-1]=0;
	//printf(";%s\n",buffer);
 
	write(serial_fd,"V1?A\n",5);
	buffer[read(serial_fd,buffer,4)-1]=0;
	sscanf(buffer,"%03u",&vertical_scale_index);
	vertical_scale=vertical_scale_table[vertical_scale_index-1];
	//printf(";vertical scale=%f\n",vertical_scale);
 
/*
	write(serial_fd,"V5?A\n",5);
	buffer[read(serial_fd,buffer,4)-1]=0;
	printf("%s\n",buffer);
	//sscanf(buffer,"%03u",&vertical_scale_index);
 
	//vertical_offset=;
*/
	write(serial_fd,"H1?\n",4);
	buffer[read(serial_fd,buffer,4)-1]=0;
	sscanf(buffer,"%03u",&horizontal_scale_index);
	horizontal_scale=horizontal_scale_table[horizontal_scale_index-1];
	//printf(";horizontal scale=%f\n",horizontal_scale);
 
 
	write(serial_fd,"WA?\n",4);
	read(serial_fd,buffer,1024);
	for (buffer_index=0; buffer_index<1000;buffer_index++) {
		printf("%f\t%f\n",
			(float)(buffer_index)*10/999*horizontal_scale,
			(float)((unsigned char)buffer[buffer_index])/255*8*vertical_scale-(float)4*vertical_scale
		);
	}
	write(serial_fd,"*CLR\n",5);
	write(serial_fd,"*ULK\n",5);
 
	/* restore the old port settings */
	tcsetattr(fd,TCSANOW,&oldtio);
 
	return 0;
}
 
wiki/projects/linux/voltcraft.txt · Last modified: 2005/08/25 17:28 by e-razor
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki