/** * Create an instance of a Serial Port class. * * @param baudRate The baud rate to configure the serial port. The cRIO-9074 supports up to 230400 Baud. * @param dataBits The number of data bits per transfer. Valid values are between 5 and 8 bits. * @param parity Select the type of parity checking to use. * @param stopBits The number of stop bits to use as defined by the enum StopBits. */ SerialPort::SerialPort(UINT32 baudRate, UINT8 dataBits, SerialPort::Parity parity, SerialPort::StopBits stopBits):m_resourceManagerHandle(0), m_portHandle (0) { ViStatus status = VI_SUCCESS; status = viOpenDefaultRM((ViSession *) & m_resourceManagerHandle); wpi_assertCleanStatus(status); status = viOpen(m_resourceManagerHandle, "ASRL1::INSTR", VI_NULL, VI_NULL, (ViSession *) & m_portHandle); wpi_assertCleanStatus(status); status = viSetAttribute(m_portHandle, VI_ATTR_ASRL_BAUD, baudRate); wpi_assertCleanStatus(status); status = viSetAttribute(m_portHandle, VI_ATTR_ASRL_DATA_BITS, dataBits); wpi_assertCleanStatus(status); status = viSetAttribute(m_portHandle, VI_ATTR_ASRL_PARITY, parity); wpi_assertCleanStatus(status); status = viSetAttribute(m_portHandle, VI_ATTR_ASRL_STOP_BITS, stopBits); wpi_assertCleanStatus(status); // Set the default timeout to 5 seconds. SetTimeout(5.0f); // Don't wait until the buffer is full to transmit. SetWriteBufferMode(kFlushOnAccess); EnableTermination(); //viInstallHandler(m_portHandle, VI_EVENT_IO_COMPLETION, ioCompleteHandler, this); //viEnableEvent(m_portHandle, VI_EVENT_IO_COMPLETION, VI_HNDLR, VI_NULL); }
/** * Create an instance of a Serial Port class. * * @param baudRate The baud rate to configure the serial port. The cRIO-9074 supports up to 230400 Baud. * @param dataBits The number of data bits per transfer. Valid values are between 5 and 8 bits. * @param parity Select the type of parity checking to use. * @param stopBits The number of stop bits to use as defined by the enum StopBits. */ SerialPort::SerialPort(uint32_t baudRate, uint8_t dataBits, SerialPort::Parity parity, SerialPort::StopBits stopBits) : m_resourceManagerHandle (0) , m_portHandle (0) , m_consoleModeEnabled (false) { ViStatus localStatus = VI_SUCCESS; localStatus = viOpenDefaultRM((ViSession*)&m_resourceManagerHandle); wpi_setError(localStatus); localStatus = viOpen(m_resourceManagerHandle, const_cast<char*>("ASRL1::INSTR"), VI_NULL, VI_NULL, (ViSession*)&m_portHandle); wpi_setError(localStatus); if (localStatus != 0) { m_consoleModeEnabled = true; return; } localStatus = viSetAttribute(m_portHandle, VI_ATTR_ASRL_BAUD, baudRate); wpi_setError(localStatus); localStatus = viSetAttribute(m_portHandle, VI_ATTR_ASRL_DATA_BITS, dataBits); wpi_setError(localStatus); localStatus = viSetAttribute(m_portHandle, VI_ATTR_ASRL_PARITY, parity); wpi_setError(localStatus); localStatus = viSetAttribute(m_portHandle, VI_ATTR_ASRL_STOP_BITS, stopBits); wpi_setError(localStatus); // Set the default timeout to 5 seconds. SetTimeout(5.0f); // Don't wait until the buffer is full to transmit. SetWriteBufferMode(kFlushOnAccess); EnableTermination(); //viInstallHandler(m_portHandle, VI_EVENT_IO_COMPLETION, ioCompleteHandler, this); //viEnableEvent(m_portHandle, VI_EVENT_IO_COMPLETION, VI_HNDLR, VI_NULL); nUsageReporting::report(nUsageReporting::kResourceType_SerialPort, 0); }