本文整理汇总了C++中SetCommMask函数的典型用法代码示例。如果您正苦于以下问题:C++ SetCommMask函数的具体用法?C++ SetCommMask怎么用?C++ SetCommMask使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetCommMask函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
BOOL ConnPort::ClosePort()
{
g_iExitFlag=1;
while(1)
{
static int iTimeoutCount=0;
Sleep(10);
if(40==iTimeoutCount)
{
TerminateThread(m_hThreadRead,0);
TerminateThread(m_hThreadWrite,0);
TerminateThread(m_hDataParse,0);
break;
}
else if(1==g_rExitFlag && 1==g_wExitFlag && 1==g_pExitFlag)
{
break;
}
else
{
iTimeoutCount++;
}
}
EscapeCommFunction(m_hPort,CLRRTS);
EscapeCommFunction(m_hPort,CLRDTR);
SetCommMask(m_hPort,0);
if(NULL==m_hPort)return FALSE;
if(NULL==m_hThreadRead)return FALSE;
if(NULL==m_hThreadWrite)return FALSE;
if(NULL==m_hDataParse)return FALSE;
if(!CloseHandle(m_hPort))return FALSE;
if(!CloseHandle(m_hThreadRead))return FALSE;
if(!CloseHandle(m_hThreadWrite))return FALSE;
if(!CloseHandle(m_hDataParse))return FALSE;
m_bIsConnect=FALSE;
return TRUE;
}
示例2: SetCommMask
// 关闭串口
_XBool _XSerialPort::close()
{
if(!m_bOpened || m_hIDComDev == NULL) return XTrue;
if(m_overlappedRead.hEvent != NULL) CloseHandle(m_overlappedRead.hEvent);
if(m_overlappedWrite.hEvent != NULL) CloseHandle(m_overlappedWrite.hEvent);
if(m_mode == SP_MODE_AUTO) //自动模式的时候开启线程
{
m_threadState = STATE_SET_TO_END;
SetCommMask(m_hIDComDev,0);
while(1)
{//等待线程结束
if(m_threadState == STATE_END) break;
Sleep(1);
}
}
CloseHandle(m_hIDComDev);
m_bOpened = XFalse;
m_hIDComDev = NULL;
return XTrue;
}
示例3: TerminateThread
void ConnPort::ResetComStatues()
{
m_rCount=0;
m_wCount=0;
m_bHexShow=FALSE;
TerminateThread(m_hThreadRead,0);
TerminateThread(m_hThreadWrite,0);
TerminateThread(m_hDataParse,0);
EscapeCommFunction(m_hPort,CLRRTS);
EscapeCommFunction(m_hPort,CLRDTR);
SetCommMask(m_hPort,0);
CloseHandle(m_hPort);
CloseHandle(m_hThreadRead);
CloseHandle(m_hThreadWrite);
CloseHandle(m_hDataParse);
m_bIsConnect=FALSE;
}
示例4: GetLastError
// Habilitacion y programacion del puerto serie
int CComm32::OpenComm()
{
if (m_OnOpen) return ERROR_ALREADY_INITIALIZED;
m_HPort=CreateFile(m_Name,GENERIC_READ+GENERIC_WRITE,
0,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0);
if (m_HPort==INVALID_HANDLE_VALUE)
return GetLastError();
m_OnOpen=true;
if (GetFileType(m_HPort)!=FILE_TYPE_CHAR)
{
CloseHandle(m_HPort);
return ERROR_OPEN_FAILED;
}
m_Read_Overlapped.hEvent=CreateEvent(NULL,true,true,NULL);
if (m_Read_Overlapped.hEvent==0)
{
CloseAll();
return GetLastError();
}
m_Write_Overlapped.hEvent=CreateEvent(NULL,true,true,NULL);
if (m_Write_Overlapped.hEvent==0)
{
CloseAll();
return GetLastError();
}
GetCommProperties(m_HPort,&m_CommProp);
SetCommMask(m_HPort,m_EvtMask);
SetCommTimeouts(m_HPort,&m_CommTimeOuts);
GetCommModemStatus(m_HPort,&m_ModemStat);
DWORD size=sizeof(COMMCONFIG);
GetCommConfig(m_HPort,&m_CommConfig,&size);
return 0;
}
示例5: Close
BOOL CSerialPort::Open(LPCTSTR PortName, DWORD BaudRate, BYTE ByteSize, BYTE Parity, BYTE StopBits, DWORD DesiredAccess)
{
Close();
m_PortHandle = CreateFile(PortName, DesiredAccess, 0, NULL, OPEN_EXISTING, 0, 0);
if (m_PortHandle != INVALID_HANDLE_VALUE)
{
DCB dcb;
CString s;
dcb.DCBlength = sizeof(dcb);
GetCommState(m_PortHandle, &dcb);
dcb.BaudRate = BaudRate;
dcb.ByteSize = ByteSize;
dcb.StopBits = StopBits;
dcb.Parity = Parity;
dcb.fDsrSensitivity = 0;
dcb.fOutxCtsFlow = 0;
dcb.fOutxDsrFlow = 0;
dcb.fInX = 0;
dcb.fOutX = 0;
dcb.fDtrControl = DTR_CONTROL_DISABLE; //DTR and RTS 0
dcb.fRtsControl = RTS_CONTROL_DISABLE;
SetCommState(m_PortHandle, &dcb);
COMMTIMEOUTS touts;
touts.ReadIntervalTimeout = 0;
touts.ReadTotalTimeoutMultiplier = 0;
touts.ReadTotalTimeoutConstant = 10;
touts.WriteTotalTimeoutConstant = 10;
touts.WriteTotalTimeoutMultiplier = 0;
SetCommTimeouts(m_PortHandle, &touts);
SetCommMask (m_PortHandle, EV_CTS | EV_DSR | EV_RING | EV_RLSD);
PurgeComm(m_PortHandle, PURGE_TXCLEAR | PURGE_RXCLEAR);
return TRUE;
}
else
{
return FALSE; // Use GetLastError() to know the reason
}
}
示例6: EIO_Set
void EIO_Set(uv_work_t* req) {
SetBaton* data = static_cast<SetBaton*>(req->data);
if (data->rts) {
EscapeCommFunction((HANDLE)data->fd, SETRTS);
} else {
EscapeCommFunction((HANDLE)data->fd, CLRRTS);
}
if (data->dtr) {
EscapeCommFunction((HANDLE)data->fd, SETDTR);
} else {
EscapeCommFunction((HANDLE)data->fd, CLRDTR);
}
if (data->brk) {
EscapeCommFunction((HANDLE)data->fd, SETBREAK);
} else {
EscapeCommFunction((HANDLE)data->fd, CLRBREAK);
}
DWORD bits = 0;
GetCommMask((HANDLE)data->fd, &bits);
bits &= ~(EV_CTS | EV_DSR);
if (data->cts) {
bits |= EV_CTS;
}
if (data->dsr) {
bits |= EV_DSR;
}
if (!SetCommMask((HANDLE)data->fd, bits)) {
ErrorCodeToString("Setting options on COM port (SetCommMask)", GetLastError(), data->errorString);
return;
}
}
示例7: Transfer_Packet
/*------------------------------------------------------------------------------------------------------------------
-- FUNCTION: Transfer_Packet
--
-- DATE: November 25, 2015
--
-- REVISIONS: (Date and Description)
--
-- DESIGNER: Ruoqi Jia
--
-- PROGRAMMER: Ruoqi Jia
--
-- INTERFACE: Transfer_Packet(LPVOID packet)
-- -LPVOID packet : the packet to be sent
--
-- RETURNS: 0 upon successful thread finish
--
-- NOTES:
-- Represents the sending state of the wireless protocol design. This thread is called whenever a user chooses a
-- file to send and presses the Send button. We confirm the line to make sure the line is available. If confirm line
-- times out, we bring the protocol back to the Wait state to wait for an ENQ, and re-initialize the read thread. If
-- confirm line succeeds, we send our packet using SendPacket. When SendPacket succeeds or times out, we do a check
-- on the priority states of the sender and receiver. If we don't have priority and the sender has priority, we enter
-- the wait state again to wait for an ENQ, otherwise we will just go directly to the read idle state. Finally, we
-- reinitialize the read thread and return from this write thread.
----------------------------------------------------------------------------------------------------------------------*/
DWORD WINAPI Transfer_Packet(LPVOID packet)
{
ResetEvent(Ev_Read_Thread_Finish);
SetCommMask(hComm, RETURN_COMM_EVENT);
WaitForSingleObject(hWrite_Lock, 2000);
char* s = (char*)packet;
OutputDebugString("Starting confirm line loop\n");
if (!ConfirmLine())
{
OutputDebugString("exceeded confirm line max tries\n");
//WAIT STATE: wait for an enq, for a specified amount of time. If we get one, set
//the receivedENQinWait boolean flag to skip directly to acknowledging line in read thread
receivedENQinWait = WaitForEnq();
ReleaseMutex(hWrite_Lock);
Initialize_Read();
SetEvent(Ev_Send_Thread_Finish);
delete[]s;
return 0;
}
OutputDebugString("Sending packet\n");
SendPacket(s);
//Check Priorities
//only when we want priority and sender doesn't want priority, we go directly to read idle. every other priority combo,
//we go to wait state
if ((!weHavePriority && senderHasPriority) || (weHavePriority && senderHasPriority) || (!weHavePriority && !senderHasPriority))
{
//WAIT STATE: wait for an enq, for a specified amount of time. If we get one, set
//the receivedENQinWait boolean flag to skip directly to acknowledging line in read thread
OutputDebugString("Going to wait state\n");
receivedENQinWait = WaitForEnq();
}else
SetEvent(Ev_Send_Thread_Finish);
//going back to wait/idle state
ReleaseMutex(hWrite_Lock);
Initialize_Read();
delete[]s;
return 0;
}
示例8: openXBee
void openXBee(char * device, HANDLE * fd)
{
DCB dcb;
COMMTIMEOUTS cto = { 0, 0, 0, 0, 0 };
memset(&dcb,NULL,sizeof(dcb));
dcb.DCBlength = sizeof(dcb);
dcb.BaudRate = 9600;
dcb.Parity = NOPARITY;
dcb.fParity = 0;
dcb.StopBits = ONESTOPBIT;
dcb.ByteSize = 8;
dcb.fOutxCtsFlow = 0;
dcb.fOutxDsrFlow = 0;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fDsrSensitivity = 0;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fOutX = 0;
dcb.fInX = 0;
dcb.fErrorChar = 0;
dcb.fBinary = 1;
dcb.fNull = 0;
dcb.fAbortOnError = 0;
dcb.wReserved = 0;
dcb.XonLim = 2;
dcb.XoffLim = 4;
dcb.XonChar = 0x13;
dcb.XoffChar = 0x19;
dcb.EvtChar = 0;
*fd = CreateFile(device, GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING,NULL,NULL);
if (fd == INVALID_HANDLE_VALUE)
{
printf("OPENCOMM Failed\n");
COMMERR(-1, "CreateFile");
}
COMMERR((!SetCommMask(*fd, 0)?-1:0), "SetCommMask");
COMMERR((!SetCommTimeouts(*fd,&cto)?-1:0), "SetCommTimeouts"); //Met en bloquant pour le passage en mode API
COMMERR((!SetCommState(*fd,&dcb)?-1:0), "SetCommState");;
}
示例9: CreateFileA
int NcrComPort::ReadByte()
{
DCB dcb;
int retVal;
BYTE Byte;
DWORD dwBytesTransferred;
DWORD dwCommModemStatus;
HANDLE hPort = CreateFileA(
this->Port,
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
0,
NULL
);
if (!GetCommState(hPort, &dcb))
return 0x100;
FillDcb(dcb);
if (!SetCommState(hPort,&dcb))
return 0x100;
SetCommMask (hPort, EV_RXCHAR | EV_ERR); //receive character event
WaitCommEvent (hPort, &dwCommModemStatus, 0); //wait for character
if (dwCommModemStatus & EV_RXCHAR) {
ReadFile (hPort, &Byte, 1, &dwBytesTransferred, 0); //read 1
retVal = Byte;
} else if (dwCommModemStatus & EV_ERR)
retVal = 0x101;
CloseHandle(hPort);
return retVal;
}
示例10: ReadThread
/*DWORD ReadThread(HWND hwnd)
*Purpose: Reads characters coming in from the port and calls
*the PaintRead function to print them.
*Arg 1 - Handle to the window procedure.
*/
DWORD ReadThread(HWND hwnd) {
char message2[] = {0x01, 0x09, 0x00, 0x03, 0x01, 0x41, 0x0A, 0x41, 0xBE};
char *inbuff = "";
DWORD nBytesRead, dwEvent;
COMSTAT comstat;
COMMTIMEOUTS timeOuts;
OVERLAPPED osRead = {0};
osRead.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
//Set the total timeout interval
memset(&timeOuts, 0, sizeof(timeOuts));
timeOuts.ReadTotalTimeoutMultiplier = 5;
timeOuts.ReadTotalTimeoutConstant = 50;
SetCommTimeouts(hComm, &timeOuts);
SetCommMask(hComm, EV_RXCHAR);
//Initialize packet
packet.found = 0;
packet.total = -1;
packet.lrc = 0;
while(mode == CONNECT) {
if(WaitCommEvent(hComm, &dwEvent, NULL)) {
ClearCommError(hComm, NULL, &comstat);
if((dwEvent & EV_RXCHAR) && comstat.cbInQue) {
if(!ReadFile(hComm, &inbuff, comstat.cbInQue, &nBytesRead, &osRead)) {
break;
}
else {
if(nBytesRead)
PaintRead(hwnd, inbuff, nBytesRead);
}
}
}
ResetEvent(osRead.hEvent);
}
PurgeComm(hComm, PURGE_RXCLEAR);
return 0L;
}
示例11: commReadThread
// Thread that continuously checks for characters comming in on the serial port.
DWORD WINAPI commReadThread() {
char *charBuff; // holds character found on serial port.
DWORD evtMask;
COMSTAT comstat; // stores serial status information
DWORD numBytesRead;
COMMTIMEOUTS timeOuts;
int i, read;
gOverlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); // create overlap event to prevent simultanious access to serial port
// Timeouts in milliseconds
memset(&timeOuts, 0, sizeof(timeOuts));
timeOuts.ReadIntervalTimeout = 0;
timeOuts.ReadTotalTimeoutMultiplier = 5;
timeOuts.ReadTotalTimeoutConstant = 50;
SetCommTimeouts(TTYInfo.hCommPort, &timeOuts);
SetCommMask(TTYInfo.hCommPort, EV_RXCHAR);
while (TTYInfo.fConnected) { // only loops while serial port is connected.
if (WaitCommEvent(TTYInfo.hCommPort, &evtMask, NULL)) {
charBuff = '\0'; // stores character from serial port
ClearCommError(TTYInfo.hCommPort, NULL, &comstat); // get status information from serial port
charBuff = malloc(comstat.cbInQue);
if ((evtMask & EV_RXCHAR) && comstat.cbInQue) { // check if queue is empty
ReadFile(TTYInfo.hCommPort, charBuff, comstat.cbInQue, &numBytesRead, &gOverlapped); // read a single character from the serial port
}
for (i = 0; i < (int)numBytesRead; i++) {
if (charBuff[i] > 0) { // don't know why, I just had to
interpretChar(charBuff[i]);
}
}
}
}
return 0;
}
示例12: wprintf
int ConnPort::OpenPort(TCHAR *szPort,int iBaudrate,int iParity,int iDataBits,int iStopBits)
{
DWORD dwThreadID=0;
g_iExitFlag=0;
m_hPort=NULL;
m_hPort=CreateFile(szPort,
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
if(!m_hPort)
{
m_hPort=NULL;
wprintf(TEXT("open port failed!!!\r\n"));
return FALSE;
}
//指定端口检测的事件集
SetCommMask(m_hPort,EV_RXCHAR);
//设置缓冲区,内部输入、输出缓冲区大小
SetupComm(m_hPort,1024,1024);
//刷新缓冲区信息->输入、输出缓冲区
PurgeComm(m_hPort,PURGE_TXCLEAR|PURGE_RXCLEAR);
if(!ConfigPort(iBaudrate,iParity,iDataBits,iStopBits)) return FALSE;
if(!CommTimeouts())return FALSE;
//创建读写线程
m_hThreadRead = CreateThread(0,0,(LPTHREAD_START_ROUTINE)ReadThreadProc, (void*)this,0,&dwThreadID);
m_hThreadWrite = CreateThread(0,0,(LPTHREAD_START_ROUTINE)WriteThreadProc, (void*)this,0,&dwThreadID);
m_hDataParse = CreateThread(0,0,(LPTHREAD_START_ROUTINE)PareDataProc, (void*)this,0,&dwThreadID);
m_bIsConnect=TRUE;
return TRUE;
}
示例13: SetCommMask
//////////////////////////////////////////////////////////////////////
// CloseConnection
// return: 0 always
//
int CAsyncPort::CloseConnection()
{
// not connected
m_isConnected = FALSE;
// disable event notification and wait for thread to halt
SetCommMask(m_hCommDev, 0);
// block until thread has been halted
while (m_dwThreadID != 0) {
Sleep(10);
}
// drop DTR
EscapeCommFunction(m_hCommDev, CLRDTR);
// purge any outstanding reads/writes and close device handle
PurgeComm (
m_hCommDev,
PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR
);
// close device
CloseHandle(m_hCommDev);
// reset instance variables
m_hCommDev = INVALID_HANDLE_VALUE;
memset(m_szCommDevName, 0, sizeof (m_szCommDevName));
memset(& m_commConfig, 0, sizeof (COMMCONFIG));;
m_commConfig.dwSize = sizeof (COMMCONFIG);
memset(& m_commProp, 0, sizeof (COMMPROP));
memset(& m_commTimeOuts, 0, sizeof (COMMTIMEOUTS));
memset(m_baInBuf, 0, sizeof (m_baInBuf));
m_nInBufIndex = 0;
m_nInBufSize = 0;
return (0);
}
示例14: SetCommMask
// 포트를 닫는다.
void CCommThread::ClosePort()
{
//--> 연결되지 않았음.
// sflag = FALSE;
m_bConnected = FALSE;
::SendMessage(hStartWnd, WM_COMM_OPEN, 0, 0);
//DCB dcb;
//SetCommState( m_hComm, &dcb);
//--> 마스크 해제..
SetCommMask( m_hComm, 0);
Sleep(60);
//--> 포트 비우기.
PurgeComm( m_hComm, PURGE_TXABORT | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_RXCLEAR);
//Sleep(60);
CloseHandle(m_hComm);
//--> 핸들 닫기
}
示例15: EIO_Set
void EIO_Set(uv_work_t* req) {
SetBaton* data = static_cast<SetBaton*>(req->data);
if (data->rts) {
EscapeCommFunction((HANDLE)data->fd, SETRTS);
} else {
EscapeCommFunction((HANDLE)data->fd, CLRRTS);
}
if (data->dtr) {
EscapeCommFunction((HANDLE)data->fd, SETDTR);
} else {
EscapeCommFunction((HANDLE)data->fd, CLRDTR);
}
if (data->brk) {
EscapeCommFunction((HANDLE)data->fd, SETBREAK);
} else {
EscapeCommFunction((HANDLE)data->fd, CLRBREAK);
}
DWORD bits = 0;
GetCommMask((HANDLE)data->fd, &bits);
bits &= ~(EV_CTS | EV_DSR);
if (data->cts) {
bits |= EV_CTS;
}
if (data->dsr) {
bits |= EV_DSR;
}
// TODO check for error
data->result = SetCommMask((HANDLE)data->fd, bits);
}