本文整理汇总了C++中setParity函数的典型用法代码示例。如果您正苦于以下问题:C++ setParity函数的具体用法?C++ setParity怎么用?C++ setParity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setParity函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setBaud
void NetworkManager::SerialSetting::fromMap(const QVariantMap &setting)
{
if (setting.contains(QLatin1String(NM_SETTING_SERIAL_BAUD))) {
setBaud(setting.value(QLatin1String(NM_SETTING_SERIAL_BAUD)).toUInt());
}
if (setting.contains(QLatin1String(NM_SETTING_SERIAL_BITS))) {
setBits(setting.value(QLatin1String(NM_SETTING_SERIAL_BITS)).toUInt());
}
if (setting.contains(QLatin1String(NM_SETTING_SERIAL_PARITY))) {
QChar character = setting.value(QLatin1String(NM_SETTING_SERIAL_PARITY)).toChar();
if (character == 'n') {
setParity(NoParity);
} else if (character == 'E') {
setParity(EvenParity);
} else if (character == 'o') {
setParity(OddParity);
}
}
if (setting.contains(QLatin1String(NM_SETTING_SERIAL_STOPBITS))) {
setStopbits(setting.value(QLatin1String(NM_SETTING_SERIAL_STOPBITS)).toUInt());
}
if (setting.contains(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY))) {
setSendDelay((Setting::SecretFlagType)setting.value(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY)).toULongLong());
}
}
示例2: switch
bool serial::setFormat (format_t fmt)
{
bool r = true;
switch(fmt) {
case serial::Format7E1:
r &= setDatabits(serial::DB7);
r &= setStopbits(serial::SB1);
r &= setParity(serial::ParityEven);
break;
case serial::Format7O1:
r &= setDatabits(serial::DB7);
r &= setStopbits(serial::SB1);
r &= setParity(serial::ParityOdd);
break;
case serial::Format8N1:
default:
r &= setDatabits(serial::DB8);
r &= setStopbits(serial::SB1);
r &= setParity(serial::ParityNone);
break;
}
return r;
}
示例3: m_fd
SerialPort::SerialPort(const string device)
: m_fd(0), m_baudRate(0), m_wordSize(0), m_asyncTimeout(DEFAULT_ASYNC_TIMEOUT)
{
if((m_fd = ::open(device.c_str(), O_RDWR | O_NOCTTY)) < 0)
throw SysException();
::bzero(&m_term, sizeof(m_term));
::tcgetattr(m_fd, &m_termOld);
setBaudRate(DEFAULT_BAUD_RATE);
setWordSize(DEFAULT_WORD_SIZE);
setParity(DEFAULT_PARITY);
m_term.c_cflag |= CLOCAL | CREAD;
m_term.c_iflag = IGNPAR;
m_term.c_oflag = OPOST;
m_term.c_lflag = 0;
m_term.c_cc[VTIME] = 0;
m_term.c_cc[VMIN] = 1;
setAttr();
if(::fcntl(m_fd, F_SETOWN, getpid()) == -1)
throw SysException();
}
示例4: openTouchDev
static int openTouchDev( char const *devName ){
int fd = -1 ;
if( !isSerial(devName) ){
fd = open(devName, O_RDONLY);
}
else {
printf( "Serial touch screen\n" );
char const *end = strchr( devName, ',' );
if( 0 == end )
end = devName + strlen(devName);
unsigned nameLen = end-devName ;
printf( "nameLen: %u, end %p\n", nameLen, end );
char deviceName[512];
if( nameLen < sizeof(deviceName) ){
memcpy( deviceName, devName, nameLen );
deviceName[nameLen] = '\0' ;
unsigned baud = 9600 ;
unsigned databits = 8 ;
char parity = 'N' ;
unsigned stop = 1 ;
if( '\0' != *end ){
end++ ;
baud = 0 ;
while( isdigit(*end) ){
baud *= 10 ;
baud += ( *end-'0' );
end++ ;
}
if( ',' == *end ){
end++ ;
databits = *end-'0' ;
end++ ;
if( ',' == *end ){
end++ ;
parity = *end++ ;
if( ',' == *end ){
stop = end[1] - '0';
}
}
}
}
fd = open( deviceName, O_RDWR );
if( 0 < fd ){
printf( "settings: %s,%u,%u,%c,%u\n", deviceName, baud, databits, parity, stop );
setBaud( fd, baud );
setRaw( fd );
setDataBits( fd, databits );
setStopBits( fd, stop );
setParity( fd, parity );
}
else
perror( deviceName );
}
else
fprintf( stderr, "Invalid touch device name\n" );
}
return fd ;
}
示例5: LOCK_MUTEX
/*!
\fn bool Posix_QextSerialPort::open(int=0)
Opens a serial port. Note that this function does not specify which device to open. If you need
to open a device by name, see Posix_QextSerialPort::open(const char*). This function has no
effect if the port associated with the class is already open. The port is also configured to the
current settings, as stored in the Settings structure.
*/
bool Posix_QextSerialPort::open(int) {
LOCK_MUTEX();
if (!portOpen) {
/*open the port*/
Posix_File->setName(portName);
if (Posix_File->open(IO_Async|IO_Raw|IO_ReadWrite)) {
portOpen=true;
}
/*configure port settings*/
tcgetattr(Posix_File->handle(), &Posix_CommConfig);
/*set up other port settings*/
Posix_CommConfig.c_cflag|=CREAD|CLOCAL;
Posix_CommConfig.c_lflag&=(~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ISIG));
Posix_CommConfig.c_iflag&=(~(INPCK|IGNPAR|PARMRK|ISTRIP|IXANY));
Posix_CommConfig.c_oflag&=(~OPOST);
Posix_CommConfig.c_cc[VMIN]=0;
Posix_CommConfig.c_cc[VINTR] = _POSIX_VDISABLE;
Posix_CommConfig.c_cc[VQUIT] = _POSIX_VDISABLE;
Posix_CommConfig.c_cc[VSTART] = _POSIX_VDISABLE;
Posix_CommConfig.c_cc[VSTOP] = _POSIX_VDISABLE;
Posix_CommConfig.c_cc[VSUSP] = _POSIX_VDISABLE;
setBaudRate(Settings.BaudRate);
setDataBits(Settings.DataBits);
setStopBits(Settings.StopBits);
setParity(Settings.Parity);
setFlowControl(Settings.FlowControl);
setTimeout(Posix_Copy_Timeout.tv_sec, Posix_Copy_Timeout.tv_usec);
tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
}
UNLOCK_MUTEX();
return portOpen;
}
示例6: tcgetattr
bool QSerialPort::open(int block)
{
if( block== 1) portDesc = ::open(portName.toAscii(),O_RDWR);
else portDesc = ::open(portName.toAscii(),O_RDWR | O_NONBLOCK );
if(portDesc == -1)
{
return false;
}
portOpen = true;
tcgetattr(portDesc, &portConfig);
portConfig.c_cflag|=(CLOCAL | CREAD);
portConfig.c_lflag&=(~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ISIG));
portConfig.c_iflag&=(~(IGNBRK|BRKINT|PARMRK|ISTRIP |INLCR| IGNCR|ICRNL|IXON)); // (~(INPCK|IGNPAR|PARMRK|ISTRIP|IXANY));
portConfig.c_iflag&=~(ICRNL);
portConfig.c_oflag&=(~OPOST);
tcsetattr(portDesc, TCSANOW, &portConfig);
setBaudRate(settings.baudRate);
setDataBits(settings.dataBits);
setFlowControl(settings.flowControl);
setParity(settings.parity);
setStopBits(settings.stopBits);
setDtr();
setRts();
connect(&portFile, SIGNAL(readyRead()), this, SLOT(slotNotifierActivated()));
return true;
}
示例7: setBaud
void
SerialPort::setSerial(int baud, int dataBits, int parity, int stopBits)
{
setBaud(baud);
setDataBits(dataBits);
setParity(parity);
setStopBits(stopBits);
}
示例8: sizeof
/*!
\fn bool Win_QextSerialPort::open(OpenMode mode)
Opens a serial port. Note that this function does not specify which device to open. If you need
to open a device by name, see Win_QextSerialPort::open(const char*). This function has no effect
if the port associated with the class is already open. The port is also configured to the current
settings, as stored in the Settings structure.
*/
bool Win_QextSerialPort::open(OpenMode mode) {
unsigned long confSize = sizeof(COMMCONFIG);
Win_CommConfig.dwSize = confSize;
DWORD dwFlagsAndAttributes = 0;
if (queryMode() == QextSerialBase::EventDriven)
dwFlagsAndAttributes += FILE_FLAG_OVERLAPPED;
LOCK_MUTEX();
if (mode == QIODevice::NotOpen)
return isOpen();
if (!isOpen()) {
/*open the port*/
Win_Handle=CreateFileA(port.toLatin1(), GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL);
if (Win_Handle!=INVALID_HANDLE_VALUE)
{
/*configure port settings*/
GetCommConfig(Win_Handle, &Win_CommConfig, &confSize);
GetCommState(Win_Handle, &(Win_CommConfig.dcb));
/*set up parameters*/
Win_CommConfig.dcb.fBinary=TRUE;
Win_CommConfig.dcb.fInX=FALSE;
Win_CommConfig.dcb.fOutX=FALSE;
Win_CommConfig.dcb.fAbortOnError=FALSE;
Win_CommConfig.dcb.fNull=FALSE;
setBaudRate(Settings.BaudRate);
setDataBits(Settings.DataBits);
setStopBits(Settings.StopBits);
setParity(Settings.Parity);
setFlowControl(Settings.FlowControl);
setTimeout(Settings.Timeout_Millisec);
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
//init event driven approach
if (queryMode() == QextSerialBase::EventDriven) {
Win_CommTimeouts.ReadIntervalTimeout = MAXDWORD;
Win_CommTimeouts.ReadTotalTimeoutMultiplier = 0;
Win_CommTimeouts.ReadTotalTimeoutConstant = 0;
Win_CommTimeouts.WriteTotalTimeoutMultiplier = 0;
Win_CommTimeouts.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(Win_Handle, &Win_CommTimeouts);
if (!SetCommMask( Win_Handle, EV_TXEMPTY | EV_RXCHAR | EV_DSR)) {
qWarning("Failed to set Comm Mask. Error code: %ld", GetLastError());
UNLOCK_MUTEX();
return false;
}
overlapThread->start();
}
QIODevice::open(mode);
}
} else {
UNLOCK_MUTEX();
return false;
}
UNLOCK_MUTEX();
return isOpen();
}
示例9: disable
void Serial::config(uint32_t speed, Serial::Parity parity, Serial::WordLength dataBits, Serial::StopBits stopBits, HardwareFlowControl hardwareFlow)
{
disable(Device::Part::All);
setSpeed(speed);
setParity(parity);
setWordLength(dataBits);
setStopBits(stopBits);
setHardwareFlowControl(hardwareFlow);
}
示例10: setBaudRate
/*! \brief SerialDevice::stopDevice Is the serial interface's implementation of setDefaults.
* Sets the serial devices to the default values. (Rate=9600, Parity=None, Flow=None, Data=8, Stop=1)
*/
void SerialDevice::setDefaults()
{
statusReady = false;
setBaudRate(9600);
setParity(0);
setFlowControl(0);
setDataBits(8);
setStopBits(1);
}
示例11: setBaudRate
/*!
Sets the port settigns.
*/
void QextSerialPort::setPortSetting(const PortSettings& settings)
{
setBaudRate(settings.BaudRate);
setDataBits(settings.DataBits);
setParity(settings.Parity);
setStopBits(settings.StopBits);
setFlowControl(settings.FlowControl);
setTimeout(settings.Timeout_Millisec);
}
示例12: setBaudRate
/*!
\fn Win_QextSerialPort::Win_QextSerialPort(const PortSettings& settings)
Constructs a port with default name and specified settings.
*/
Win_QextSerialPort::Win_QextSerialPort(const PortSettings& settings) {
Win_Handle=INVALID_HANDLE_VALUE;
setBaudRate(settings.BaudRate);
setDataBits(settings.DataBits);
setStopBits(settings.StopBits);
setParity(settings.Parity);
setFlowControl(settings.FlowControl);
setTimeout(settings.Timeout_Sec, settings.Timeout_Millisec);
}
示例13: lock
/*!
Opens the serial port associated to this class.
This function has no effect if the port associated with the class is already open.
The port is also configured to the current settings, as stored in the Settings structure.
*/
bool QextSerialPort::open(OpenMode mode)
{
QMutexLocker lock(mutex);
if (mode == QIODevice::NotOpen)
return isOpen();
if (!isOpen()) {
qDebug() << "trying to open file" << port.toAscii();
//note: linux 2.6.21 seems to ignore O_NDELAY flag
if ((fd = ::open(port.toAscii() ,O_RDWR | O_NOCTTY | O_NDELAY)) != -1) {
qDebug("file opened succesfully");
setOpenMode(mode); // Flag the port as opened
tcgetattr(fd, &old_termios); // Save the old termios
Posix_CommConfig = old_termios; // Make a working copy
/* the equivelent of cfmakeraw() to enable raw access */
#ifdef HAVE_CFMAKERAW
cfmakeraw(&Posix_CommConfig); // Enable raw access
#else
Posix_CommConfig.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
| INLCR | IGNCR | ICRNL | IXON);
Posix_CommConfig.c_oflag &= ~OPOST;
Posix_CommConfig.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
Posix_CommConfig.c_cflag &= ~(CSIZE | PARENB);
Posix_CommConfig.c_cflag |= CS8;
#endif
/*set up other port settings*/
Posix_CommConfig.c_cflag|=CREAD|CLOCAL;
Posix_CommConfig.c_lflag&=(~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ISIG));
Posix_CommConfig.c_iflag&=(~(INPCK|IGNPAR|PARMRK|ISTRIP|ICRNL|IXANY));
Posix_CommConfig.c_oflag&=(~OPOST);
Posix_CommConfig.c_cc[VMIN]= 0;
#ifdef _POSIX_VDISABLE // Is a disable character available on this system?
// Some systems allow for per-device disable-characters, so get the
// proper value for the configured device
const long vdisable = fpathconf(fd, _PC_VDISABLE);
Posix_CommConfig.c_cc[VINTR] = vdisable;
Posix_CommConfig.c_cc[VQUIT] = vdisable;
Posix_CommConfig.c_cc[VSTART] = vdisable;
Posix_CommConfig.c_cc[VSTOP] = vdisable;
Posix_CommConfig.c_cc[VSUSP] = vdisable;
#endif //_POSIX_VDISABLE
setBaudRate(Settings.BaudRate);
setDataBits(Settings.DataBits);
setParity(Settings.Parity);
setStopBits(Settings.StopBits);
setFlowControl(Settings.FlowControl);
setTimeout(Settings.Timeout_Millisec);
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
if (queryMode() == QextSerialPort::EventDriven) {
readNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
connect(readNotifier, SIGNAL(activated(int)), this, SIGNAL(readyRead()));
}
示例14: sizeof
/*!
Opens a serial port. Note that this function does not specify which device to open. If you need
to open a device by name, see QextSerialPort::open(const char*). This function has no effect
if the port associated with the class is already open. The port is also configured to the current
settings, as stored in the Settings structure.
*/
bool QextSerialPort::open(OpenMode mode) {
unsigned long confSize = sizeof(COMMCONFIG);
Win_CommConfig.dwSize = confSize;
DWORD dwFlagsAndAttributes = 0;
if (queryMode() == QextSerialPort::EventDriven)
dwFlagsAndAttributes += FILE_FLAG_OVERLAPPED;
QMutexLocker lock(mutex);
if (mode == QIODevice::NotOpen)
return isOpen();
if (!isOpen()) {
/*open the port*/
Win_Handle=CreateFileA(port.toAscii(), GENERIC_READ|GENERIC_WRITE,
0, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL);
if (Win_Handle!=INVALID_HANDLE_VALUE) {
QIODevice::open(mode);
/*configure port settings*/
GetCommConfig(Win_Handle, &Win_CommConfig, &confSize);
GetCommState(Win_Handle, &(Win_CommConfig.dcb));
/*set up parameters*/
Win_CommConfig.dcb.fBinary=TRUE;
Win_CommConfig.dcb.fInX=FALSE;
Win_CommConfig.dcb.fOutX=FALSE;
Win_CommConfig.dcb.fAbortOnError=FALSE;
Win_CommConfig.dcb.fNull=FALSE;
setBaudRate(Settings.BaudRate);
setDataBits(Settings.DataBits);
setStopBits(Settings.StopBits);
setParity(Settings.Parity);
setFlowControl(Settings.FlowControl);
setTimeout(Settings.Timeout_Millisec);
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
//init event driven approach
if (queryMode() == QextSerialPort::EventDriven) {
Win_CommTimeouts.ReadIntervalTimeout = MAXDWORD;
Win_CommTimeouts.ReadTotalTimeoutMultiplier = 0;
Win_CommTimeouts.ReadTotalTimeoutConstant = 0;
Win_CommTimeouts.WriteTotalTimeoutMultiplier = 0;
Win_CommTimeouts.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(Win_Handle, &Win_CommTimeouts);
if (!SetCommMask( Win_Handle, EV_TXEMPTY | EV_RXCHAR | EV_DSR)) {
qWarning() << "failed to set Comm Mask. Error code:", GetLastError();
return false;
}
winEventNotifier = new QWinEventNotifier(overlap.hEvent, this);
connect(winEventNotifier, SIGNAL(activated(HANDLE)), this, SLOT(onWinEvent(HANDLE)));
WaitCommEvent(Win_Handle, &eventMask, &overlap);
}
}
} else {
return false;
}
return isOpen();
}
示例15: construct
/*!
\fn Posix_QextSerialPort::Posix_QextSerialPort(const char* name, const PortSettings& settings)
Constructs a port with specified name and settings.
*/
Posix_QextSerialPort::Posix_QextSerialPort(const char* name, const PortSettings& settings)
:QextSerialBase(name) {
construct();
setBaudRate(settings.BaudRate);
setDataBits(settings.DataBits);
setStopBits(settings.StopBits);
setParity(settings.Parity);
setFlowControl(settings.FlowControl);
setTimeout(settings.Timeout_Sec, settings.Timeout_Millisec);
}