int main() { LibSerial::SerialStream ss; ss.Open("/dev/ttyACM0"); //serial/by-id/usb-LeafLabs_Maple-if00"); if ( !ss.good() ) { std::cout << "Not good" << std::endl; exit(1); } ss.SetCharSize( LibSerial::SerialStreamBuf::CHAR_SIZE_8 ) ; if ( !ss.good() ) { std::cout << "can't set char size" << std::endl; exit(1); } char c = 0x1; write_letter(ss,l_a); usleep(1000000); write_letter(ss,l_b); //ss.write(&c, 0); }
int setup_serial_port( LibSerial::SerialStream& serial_port, const char* SERIAL_PORT_DEVICE, LibSerial::SerialStreamBuf::BaudRateEnum baud_rate ) { using namespace LibSerial; //Open the port SERIAL_PORT_DEVICE serial_port.Open( SERIAL_PORT_DEVICE ); if ( ! serial_port.good() ) { std::cout << "Not able to open serial port at " << SERIAL_PORT_DEVICE << std::endl; return 0; } //Set Baudrate serial_port.SetBaudRate( baud_rate ); if ( ! serial_port.good() ) { std::cout << "Unable to set Baud Rate " << std::endl; return 0; } //Set Character Size serial_port.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ); if( ! serial_port.good() ) { std::cout << "Unable to set Char Size 8" << std::endl; return 0; } //Set Parity serial_port.SetParity( SerialStreamBuf::PARITY_NONE ); if( ! serial_port.good() ) { std::cout << "Unable to set Parity None " << std::endl; return 0; } //Set Number of Stop Bits serial_port.SetNumOfStopBits( 1 ); if( ! serial_port.good() ) { std::cout << "Unable to set Num of Stop Bits 1 " << std::endl; return 0; } //Set Hardware Flow Control serial_port.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE ); if( ! serial_port.good() ) { std::cout << "Unable to set Hardware Flow Control None" << std::endl; return 0; } return 1; }
void init_serial() { // Open the serial port. const char *const SERIAL_PORT_DEVICE = "/dev/ttyACM0"; serial_port.Open(SERIAL_PORT_DEVICE); CHECK_S("Could not open serial port") //SET_AND_CHECK( SetBaudRate, BAUD_9600, "Could not set the baud rate." ); SET_AND_CHECK( SetCharSize, CHAR_SIZE_8, "Could not set the character size." ); SET_AND_CHECK( SetParity , PARITY_NONE, "Could not disable the parity." ); // Set the number of stop bits serial_port.SetNumOfStopBits(1); CHECK_S("Could not set the number of stop bits") // Turn on hardware flow control serial_port.SetFlowControl(LibSerial::SerialStreamBuf::FLOW_CONTROL_NONE); CHECK_S("Could not use hardware flow control") }
/** * open FUSE function * @param * @see fuse_operations structure from fuse.h * @return */ static int usb_open(const char *path, struct fuse_file_info *fi) { //printf("[+] usb_open start\n"); if(strcmp(path, devname) != 0) { //printf("[x] usb_open path error: %s\n", path); return -ENOENT; } /*if((fi->flags & 3) != O_RDONLY) { //printf("[x] usb_open flags error: %x\n", fi->flags); return -EACCES; }*/ s.Open("/dev/ttyUSB0"); //printf("[+] usb_open end\n"); return 0; }