//----------------------------------------------- CanESD::CanESD(int iIniBaudRate, int iNrNet) { //initial values int net=1; /* logical net number (here: 0) */ uint32_t mode=0; /* mode used for canOpen() */ int32_t txqueuesize=100; /* size of transmit queue */ int32_t rxqueuesize=100; /* size of receive queue */ int32_t txtimeout=0; /* timeout for transmit operations in ms */ int32_t rxtimeout=0; /* timeout for receive operations in ms */ NTCAN_RESULT retvalue; /* return values of NTCAN API calls */ //uint32_t baud=2; /* configured CAN baudrate (here: 500 kBit/s.) */ CMSG cmsg[8]; /* can message buffer */ int rtr=0; /* rtr bit */ int32_t len; /* # of CAN messages */ retvalue = canOpen(iNrNet, mode, txqueuesize, rxqueuesize, txtimeout, rxtimeout, &m_Handle); if (retvalue != NTCAN_SUCCESS) { LOGINFO("canOpen() failed: " << getErrorMessage(retvalue)); } Sleep(300); retvalue = canSetBaudrate(m_Handle, getBaudRate(iIniBaudRate)); if (retvalue != 0) { LOGINFO("canSetBaudrate() failed: " << getErrorMessage(retvalue)); canClose(m_Handle); } else { LOGINFO("Baudrate set to " << getBaudRate(iIniBaudRate)); } Sleep(300); //set Amtek Arm IDs int i; for(i=1; i < 2048; i++) { retvalue = canIdAdd(m_Handle, i); if (retvalue != NTCAN_SUCCESS) { LOGERROR("canIdAdd() failed: " << getErrorMessage(retvalue)); } } Sleep(300); m_LastID = -1; }
void SMSClient::setStatus(unsigned status) { if (status == STATUS_OFFLINE){ Contact *contact; ContactList::ContactIterator it; while ((contact = ++it) != NULL) contact->clientData.freeClientData(this); if (m_ta){ delete m_ta; m_ta = NULL; } return; } if (m_ta) return; m_ta = new GsmTA(this); connect(m_ta, SIGNAL(init_done()), this, SLOT(init())); connect(m_ta, SIGNAL(error()), this, SLOT(error())); connect(m_ta, SIGNAL(phonebookEntry(int, int, const QString&, const QString&)), this, SLOT(phonebookEntry(int, int, const QString&, const QString&))); connect(m_ta, SIGNAL(charge(bool, unsigned)), this, SLOT(charge(bool, unsigned))); connect(m_ta, SIGNAL(quality(unsigned)), this, SLOT(quality(unsigned))); connect(m_ta, SIGNAL(phoneCall(const QString&)), this, SLOT(phoneCall(const QString&))); if (!m_ta->open(getDevice(), getBaudRate(), getXonXoff())){ error_state("Can't open port", 0); return; } }
int SerialImpl::open() { //m_fd = ::open (getDevName(), O_RDWR | O_NOCTTY, O_NONBLOCK); // non-blocking mode m_fd = ::open (getDevName(), O_RDWR | O_NOCTTY); if (0 > m_fd) { kuDebug (kuERR, "[SerialImpl::open] open failed : dev(%s) baud(%d)\n", getDevName(), getBaudRate()); return (kuNOK); } struct termios oldtio, newtio; // stores current setting to vairable if (0 > tcgetattr (m_fd, &oldtio)) { kuDebug (kuERR, "[SerialImpl::open] dev(%s) tcgetattr failed\n", getDevName()); //return (kuNOK); } bzero(&newtio, sizeof(newtio)); newtio.c_cflag = CS8; // 8N1 (8bit, no parity, 1stopbit) newtio.c_cflag |= CLOCAL; // local connection newtio.c_cflag |= CREAD; // enable reading // newtio.c_cflag |= CRTSCTS; // H/W flow control newtio.c_cflag &= ~CRTSCTS; // disable flow control. 2013. 12. 2 by woong newtio.c_cflag |= getBaudRate(); // baud rate : (ex) B115200 newtio.c_iflag = IGNPAR; // non-parity newtio.c_oflag = 0; newtio.c_lflag = 0; // input mode (non-canonical, no echo, ...) // timeout is 5 seconds newtio.c_cc[VTIME] = 50; // timeout : TIME * 0.1 sec newtio.c_cc[VMIN] = 0; // blocking if (0 > tcflush (m_fd, TCIFLUSH)) { kuDebug (kuERR, "[SerialImpl::open] dev(%s) tcflush failed\n", getDevName()); //return (kuNOK); } if (0 > tcsetattr (m_fd, TCSANOW, &newtio)) { kuDebug (kuERR, "[SerialImpl::open] dev(%s) tcsetattr failed\n", getDevName()); //return (kuNOK); } // duplicates fd to read and write concurrently among threads m_readFd = dup(m_fd); kuDebug (kuDEBUG, "[SerialImpl::open] dup(%d/%d)\n", m_fd, m_readFd); kuDebug (kuINFO, "[SerialImpl::open] dev(%s) was opened\n", getDevName()); return (kuOK); }
/* initialize serial port */ void serInit(unsigned long baudRate) { unsigned int temp = getBaudRate(baudRate); UBRRH = (temp & 0xFF00) >> 8; UBRRL = temp & 0xFF; UCSRB = 0; // reset just to be sure serRxBufferHead = 0; // reset serRxBufferTail = 0; sbi(UCSRB, RXCIE); // Rx int enable sbi(UCSRB, RXEN); // enable rx and tx now sbi(UCSRB, TXEN); sei(); }
/** * Main function. */ int main(int argc, char *argv[]) { char *fileName; const char fileMode[] = "r+"; unsigned int baud; int fd; fileName = getDeviceFileName(argc, argv); fd = openDeviceFile(fileName, fileMode); baud = getBaudRate(argc, argv); setAttr(fd, baud); displayResult(fd); sendCommand(fd, "?"); displayResult(fd); sound(fd*10); printf("\n"); nosound(); close(fd); return EXIT_SUCCESS; }
void SerialImpl::printConfiguration () { kuDebug (kuINFO, "[SerialImpl::configuration] dev(%s) baud(%d)\n", getDevName(), getBaudRate()); }