Browse Source

add PC side code

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@4368 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 17 years ago
parent
commit
1c2456777c
2 changed files with 62 additions and 0 deletions
  1. +6
    -0
      testdac/pc/Makefile
  2. +56
    -0
      testdac/pc/setdac.c

+ 6
- 0
testdac/pc/Makefile View File

@@ -0,0 +1,6 @@
.PHONY: clean all

all : setdac

clean :
rm -f setdac

+ 56
- 0
testdac/pc/setdac.c View File

@@ -0,0 +1,56 @@
#include <stdio.h>
#include <stdlib.h>
#include <termio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <err.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <errno.h>
#include <string.h>
#include <stdint.h>

int main(int argc, char *argv[])
{
int baudrate=B9600;
int fd_serial;
struct termios options;
FILE *s;
int val;
uint8_t c;
if (argc != 3) {
fprintf(stderr,"usage: %s device value\n", *argv);
fprintf(stderr," ex: %s /dev/ttyS0 123\n", *argv);
exit(1);
}

val = atoi(argv[2]);
if (val < 0 || val > 255)
errx(1, "bad value: %s", argv[2]);

if ((fd_serial = open(argv[1], O_RDWR|O_NOCTTY)) == -1)
err(1, "serial device %s", argv[1]);

fcntl(fd_serial, F_SETFL, 0);
tcgetattr(fd_serial, &options);
cfsetispeed(&options, baudrate);
cfsetospeed(&options, baudrate);
options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~PARENB;
options.c_cflag |= CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_cflag &= ~CRTSCTS;
options.c_oflag &= ~OPOST;
if (tcsetattr(fd_serial, TCSANOW, &options) != 0)
err(1, "setting serial device parameters");

c = val;
printf("Sending byte 0x%02x\n", c);
write(fd_serial, &c, 1);

close(fd_serial);
return 0;
}

Loading…
Cancel
Save