misuse serial port for I2C
I want to translate c++ code (below) to java
how can i do that?
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include"i2c_m.h"
#define DBG 0
staticint fd = -1;
void scl_high(void){
if (DBG) printf("c");//dbg
int arg=TIOCM_RTS;
ioctl(fd, TIOCMBIS, &arg);
}
void scl_low(void){
if (DBG) printf("_");//dbg
int arg=TIOCM_RTS;
ioctl(fd, TIOCMBIC, &arg);
}
void sda_high(void){
if (DBG) printf("1");//dbg
int arg=TIOCM_DTR;
int r=0;
r=ioctl(fd, TIOCMBIS, &arg);
}
void sda_low(void){
if (DBG) printf("0");//dbg
int arg=TIOCM_DTR;
ioctl(fd, TIOCMBIC, &arg);
}
int wait_port(void){
if (DBG) printf("w");//dbg
usleep(1);
return(0);
}
// open port and set sda/scl to high
int open_tty(char *comport){
fd = open(comport, O_RDWR | O_NOCTTY);
if (fd <0){
fprintf(stderr,"ERROR: can not open serial port %s\n",comport);
exit(1);
}
sda_high();
scl_high();
return(fd);
}
int close_tty(void){
return( close(fd) );
}
...skip...

