예제 #1
1
DWORD SerialPort::ThreadProc (LPVOID lpdwThreadParam ) {
    SerialPort *port =  (SerialPort *)lpdwThreadParam;
    HANDLE hCOM = port->get_com();
    DWORD read;
    const int buffSize = 1024;
    char buff[buffSize];
    while (true) {
        read = 0;
        bool res = ReadFile(hCOM, buff, buffSize, &read,0);
        if(!port->mTreadFlag)
        	break;
        if(res) {
            if(read > 0) {
                port->mReadError = false;
                buff[read]='\0';
                SerialPortRecieved(port, buff, read);
                port->mBytesRecivedSinceLastSend += read;
            } else {
                if(GetCommModemStatus(hCOM, &read)==0) {
                    if(port->mReadError == false)
                        SerialPortError(port, ERROR_READ_STRING);
                    port->mReadError = true;
                } else {
                    port->mReadError = false;
                }
                port->sleep(100);
            }
        } else {
            port->mReadError = true;
            SerialPortError(port, ERROR_READ_STRING);
            port->sleep(100);
        }
    }
    return 0;
}
예제 #2
0
파일: comm.cpp 프로젝트: inspirer/history
unsigned int WINAPI mthread(void *t)
{
  DWORD mask = 0;
  register CComm *cm = (CComm *)t;

  GetCommModemStatus(cm->h,&cm->mstat);
  cm->status=1;
  while(1){
     if(!WaitCommEvent(cm->h,&mask,&cm->ovr) ) {
         DWORD e=GetLastError();
         if( e == ERROR_IO_PENDING ) {
            DWORD r;
            if( !GetOverlappedResult(cm->h,&cm->ovr,&r,TRUE) ) {
               throw errors("GetOverlappedResult failed");
               break;
            }
         } else {
            throw errors("WaitCommEvent failed");
            break;
         }
     }

     if( mask == 0 ) {
         break;
     }

     if( mask & EV_RXCHAR) {
         char buf[10];
         DWORD read;
         do {
            read = 0;
            if( !ReadFile(cm->h,buf,sizeof(buf),&read,&cm->ovr) ) {
               if( GetLastError() == ERROR_IO_PENDING ){
                  if( !GetOverlappedResult(cm->h,&cm->ovr,&read,TRUE)){
                     throw errors("GetOverlappedResult failed");
                     break;
                  }
               } else {
                  throw errors("ReadFile failed");
                  break;
               }
            }
            if(read){
              cm->receive(buf,read);
            }
         } while(read);
     }
     if( mask & EV_TXEMPTY) {
       SetEvent(cm->txenable);
     }
     if ( mask & (EV_RLSD|EV_DSR|EV_CTS)) {
       GetCommModemStatus(cm->h,&cm->mstat);
       cm->status=1;
     }
     mask = 0;
  }
  CloseHandle(cm->ovr.hEvent);
  CloseHandle(cm->h);cm->h=NULL;
  return 0;
}
예제 #3
0
/*!
\fn ulong Win_QextSerialPort::lineStatus(void)
returns the line status as stored by the port function.  This function will retrieve the states
of the following lines: DCD, CTS, DSR, and RI.  On POSIX systems, the following additional lines
can be monitored: DTR, RTS, Secondary TXD, and Secondary RXD.  The value returned is an unsigned
long with specific bits indicating which lines are high.  The following constants should be used
to examine the states of individual lines:

\verbatim
Mask        Line
------      ----
LS_CTS      CTS
LS_DSR      DSR
LS_DCD      DCD
LS_RI       RI
\endverbatim

This function will return 0 if the port associated with the class is not currently open.
*/
ulong Win_QextSerialPort::lineStatus(void) 
{
    unsigned long status = 0;
    unsigned long temp = 0;

    LOCK_MUTEX();

    if (isOpen()) 
    {
        GetCommModemStatus(m_WinHandle, &temp);
        if (temp&MS_CTS_ON) 
        {
            status|=LS_CTS;
        }
        if (temp&MS_DSR_ON) 
        {
            status|=LS_DSR;
        }
        if (temp&MS_RING_ON) 
        {
            status|=LS_RI;
        }
        if (temp&MS_RLSD_ON) 
        {
            status|=LS_DCD;
        }
    }

    UNLOCK_MUTEX();

    return status;
}
예제 #4
0
파일: io_serial.c 프로젝트: KurtWoloch/fbc
static int fb_hSerialWaitSignal( HANDLE hDevice, DWORD dwMask, DWORD dwResult, DWORD dwTimeout )
{
    DWORD dwStartTime = GET_MSEC_TIME();
    DWORD dwModemStatus = 0;

    if( !GetCommModemStatus( hDevice, &dwModemStatus ) )
        return FALSE;

    while ( ((GET_MSEC_TIME() - dwStartTime) <= dwTimeout)
            && ((dwModemStatus & dwMask)!=dwResult) )
    {
        if( !GetCommModemStatus( hDevice, &dwModemStatus ) )
            return FALSE;
    }
    return ((dwModemStatus & dwMask)==dwResult);
}
void Tserial_event::OnEvent (unsigned long events)
{
	unsigned long ModemStat;

	GetCommModemStatus(serial_handle, &ModemStat);

	if ((events & EV_RING)!=0)
	{
		if ((ModemStat &  MS_RING_ON)!= 0)
		{
			if (manager!=0)
				manager((uint32) this, SERIAL_RING);
		}
	}

	if ((events & EV_RLSD)!=0)
	{
		if ((ModemStat &  MS_RLSD_ON)!= 0)
		{
			if (manager!=0)
				manager((uint32) this, SERIAL_CD_ON);
		}
		else
		{
			if (manager!=0)
				manager((uint32) this, SERIAL_CD_OFF);
		}
	}
}
예제 #6
0
COMPort::MSPack COMPort::getModemSignals() const {
	MSPack aPack;

	if ( !GetCommModemStatus ( (HANDLE)portHandle, (LPDWORD)&aPack ) ) {
	}
	return aPack;
}
예제 #7
0
int ndiSerialCheckDSR(HANDLE serial_port)
{
  DWORD bits;
  /* get the bits to see if DSR is set (i.e. if device is connected) */
  GetCommModemStatus(serial_port, &bits);
  return ((bits & MS_DSR_ON) != 0);
}
예제 #8
0
extern "C" __declspec (dllexport) bool SerialGate::GetLine(IN_LINES_NAME ln)
{
	if(!state)
		return 0;

	unsigned long ul = 0;

	GetCommModemStatus(m_hFile, &ul);
		
	if(ul == 0x10 && ln == CTS)
	{
		return true;
	}

	if(ul == 0x20 && ln == DSR)
	{
		return true;	
	}

	if(ul == 0x40 && ln == RING)
	{
		return true;
	}

	if(ul == 0x80 && ln == RLSD)
	{
		return true;
	}		

	return false;
}
예제 #9
0
파일: link_gry2.c 프로젝트: TC01/tilibs
static int gry_probe(CableHandle *h)
{
	DWORD status;			//MS_CTS_ON or MS_DTR_ON

	EscapeCommFunction(hCom, SETDTR);
	EscapeCommFunction(hCom, SETRTS);
	GetCommModemStatus(hCom, &status);	// Get MCR values
	if (status != 0x20)
	{
		return ERR_PROBE_FAILED;
	}

	EscapeCommFunction(hCom, SETDTR);
	EscapeCommFunction(hCom, CLRRTS);
	GetCommModemStatus(hCom, &status);
	if (status != 0x20)
	{
		return ERR_PROBE_FAILED;
	}

	EscapeCommFunction(hCom, CLRDTR);
	EscapeCommFunction(hCom, CLRRTS);
	GetCommModemStatus(hCom, &status);
	if (status != 0x00)
	{
		return ERR_PROBE_FAILED;
	}

	EscapeCommFunction(hCom, CLRDTR);
	EscapeCommFunction(hCom, SETRTS);
	GetCommModemStatus(hCom, &status);
	if (status != 0x00)
	{
		return ERR_PROBE_FAILED;
	}

	EscapeCommFunction(hCom, SETDTR);
	EscapeCommFunction(hCom, SETRTS);
	GetCommModemStatus(hCom, &status);
	if (status != 0x20)
	{
		return ERR_PROBE_FAILED;
	}

	return 0;
}
예제 #10
0
파일: rs232.c 프로젝트: kelayamatoz/DC8094A
int RS232_IsDSREnabled(int comport_number)
{
  int status;

  GetCommModemStatus(Cport[comport_number], (LPDWORD)((void *)&status));

  if(status&MS_DSR_ON) return(1);
  else return(0);
}
예제 #11
0
int IsCTSEnabled()
{
  int status;

  GetCommModemStatus(Cport, (LPDWORD)((void *)&status));

  if(status&MS_CTS_ON) return(1);
  else return(0);
}
예제 #12
0
int comGetModemStatus(COM_HANDLE handle)
{
	DWORD status=0;
	
	if(GetCommModemStatus(handle, &status))
		return status;
	else
		return COM_ERROR;
}
예제 #13
0
파일: NT_Uart.c 프로젝트: bochaqos/tol
/*------------------------------------------------------------------------------

 FUNCTION NAME: Uart_CTSReady

 DESCRIPTION: Checks CTS ready

 PARAMETERS:
   - INPUT:
     - NumChann (int): Port to check
   - OUTPUT:

 RETURN: TRUE  - CTS 1
         FALSE - CTS 0

 NOTES:

------------------------------------------------------------------------------*/
t_boolean Uart_CTSReady (int NumChann)
{
HANDLE hPort = GetPortHandle ( NumChann );
DWORD  ModemStat;

  GetCommModemStatus (hPort, &ModemStat);

  return (t_boolean) (MS_CTS_ON & ModemStat);

} /* Uart_CTSReady */
예제 #14
0
void CSerialPort::GetModemStatus(DWORD& dwModemStatus)
{
  ASSERT(IsOpen());

  if (!GetCommModemStatus(m_hComm, &dwModemStatus))
  {
    TRACE(_T("Failed in call to GetCommModemStatus\n"));
    AfxThrowSerialException();
  }
}
예제 #15
0
void CSerialServer::CheckModemStatus(BOOL bUpdateNow)
{
    if (!GetCommModemStatus(m_hComPort, &m_dwModemStatus))
        XDEBUG("GetCommModemStatus Error\r\n");

    // Report status if bUpdateNow is true or status has changed
    if (bUpdateNow || (m_dwModemStatus != m_dwOldModemStatus))
        OnUpdateModemStatus(m_dwModemStatus);

    m_dwOldModemStatus = m_dwModemStatus;
}
예제 #16
0
BOOL CSerialPort::GetDSR()
{
  DWORD result =0;
  if (!GetCommModemStatus(m_hComm, &result))
  {
    TRACE(_T("Failed in call to EscapeCommFunction\n"));
    AfxThrowSerialException();
  }

  return result&MS_DSR_ON?1:0;
}
예제 #17
0
static int SerialPort_getLineStatus(GORILLA_METHOD_PARAMETERS) {
    HANDLE win32Handle;
    int status;
    
    win32Handle = SerialPort_property__win32Handle_entity(GORILLA_METHOD_PARAM_PASSTHRU);
    if (GetCommModemStatus(win32Handle, (LPDWORD)&status) == FALSE) {
        zend_throw_exception(NULL, "failed to get line status", 641 TSRMLS_CC);
        return 0;
    }
    
    return status;
}
예제 #18
0
serial_raw::serial_raw(const char *devname)
{
#ifdef WIN32
  char portstr[MAX_PATH];
#ifdef WIN32_RECEIVE_RAW
  DWORD threadID;
#endif
#endif

  put ("SERR");
  settype (SERRLOG);
#ifdef WIN32
  memset(&dcb, 0, sizeof(DCB));
  dcb.DCBlength = sizeof(DCB);
  dcb.fBinary = 1;
  dcb.fDtrControl = DTR_CONTROL_ENABLE;
  dcb.fRtsControl = RTS_CONTROL_ENABLE;
  dcb.Parity = NOPARITY;
  dcb.ByteSize = 8;
  dcb.StopBits = ONESTOPBIT;
  dcb.BaudRate = CBR_115200;
  DCBchanged = FALSE;
  if (lstrlen(devname) > 0) {
    wsprintf(portstr, "\\\\.\\%s", devname);
    hCOM = CreateFile(portstr, GENERIC_READ|GENERIC_WRITE, 0, NULL,
                      OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
    if (hCOM != INVALID_HANDLE_VALUE) {
      present = 1;
      GetCommModemStatus(hCOM, &MSR_value);
      SetupComm(hCOM, 8192, 2048);
      PurgeComm(hCOM, PURGE_TXABORT | PURGE_RXABORT |
                PURGE_TXCLEAR | PURGE_RXCLEAR);
#ifdef WIN32_RECEIVE_RAW
      SetCommMask(hCOM, EV_BREAK | EV_CTS | EV_DSR | EV_ERR | EV_RING | EV_RLSD | EV_RXCHAR);
      memset(&rx_ovl, 0, sizeof(OVERLAPPED));
      rx_ovl.hEvent = CreateEvent(NULL,TRUE,FALSE,"receive");
      hRawSerialThread = CreateThread(NULL, 0, RawSerialThread, this, 0, &threadID);
#endif
    } else {
      present = 0;
      BX_ERROR(("Raw device '%s' not present", devname));
    }
  } else {
    present = 0;
  }
#else
  present = 0;
#endif
  set_modem_control(0x00);
  set_break(0);
  rxdata_count = 0;
}
예제 #19
0
void EIO_Get(uv_work_t* req) {
  GetBaton* data = static_cast<GetBaton*>(req->data);

  DWORD bits = 0;
  if (!GetCommModemStatus((HANDLE)data->fd, &bits)) {
    ErrorCodeToString("Getting control settings on COM port (GetCommModemStatus)", GetLastError(), data->errorString);
    return;
  }

  data->cts = bits & MS_CTS_ON;
  data->dsr = bits & MS_DSR_ON;
  data->dcd = bits & MS_RLSD_ON;
}
예제 #20
0
AREXPORT bool ArSerialConnection::getRing(void)
{
  DWORD modemStat;
  if (GetCommModemStatus(myPort, &modemStat))
  {
    return (bool) (modemStat & MS_RING_ON);
  }
  else
  {
    fprintf(stderr, "problem with GetCommModemStatus\n");
    return false;
  }
}
예제 #21
0
MX_EXPORT mx_status_type
mxi_win32com_get_signal_state( MX_RS232 *rs232 )
{
	static const char fname[] = "mxi_win32com_get_signal_state()";

	MX_WIN32COM *win32com;
	DWORD modem_status;
	BOOL status;

	MX_DEBUG(-2,("%s invoked for record '%s'.",
			fname, rs232->record->name ));

	win32com = (MX_WIN32COM *) rs232->record->record_type_struct;

	rs232->signal_state &= ~ MXF_WIN32COM_SIGNAL_READ_MASK;

	status = GetCommModemStatus( win32com->handle, &modem_status );

	if ( status == 0 ) {
		DWORD last_error_code;
		TCHAR message_buffer[MXU_ERROR_MESSAGE_LENGTH - 120];

		last_error_code = GetLastError();

		mx_win32_error_message( last_error_code,
			message_buffer, sizeof(message_buffer) );

		return mx_error( MXE_INTERFACE_IO_ERROR, fname,
			"Error getting RS-232 signal status from "
			"WIN32COM port '%s'.  "
			"Win32 error code = %ld, error message = '%s'",
			win32com->filename, last_error_code, message_buffer );
	}

	win32com->modem_status = (unsigned long) modem_status;

	if ( modem_status & MS_CTS_ON ) {
		rs232->signal_state |= MXF_232_CLEAR_TO_SEND;
	}
	if ( modem_status & MS_DSR_ON ) {
		rs232->signal_state |= MXF_232_DATA_SET_READY;
	}
	if ( modem_status & MS_RING_ON ) {
		rs232->signal_state |= MXF_232_RING_INDICATOR;
	}
	if ( modem_status & MS_RLSD_ON ) {
		rs232->signal_state |= MXF_232_DATA_CARRIER_DETECT;
	}

	return MX_SUCCESSFUL_RESULT;
}
void CDirectSerial::updateMSR () {
	DWORD dptr = 0;

	if (!GetCommModemStatus (hCom, &dptr)) {
#ifdef SERIALPORT_DEBUGMSG
//		LOG_MSG ("Serial port at %x: GetCommModemStatus failed!", base);
#endif
		//return;
	}
	setCTS((dptr & MS_CTS_ON)!=0);
	setDSR((dptr & MS_DSR_ON)!=0);
	setRI ((dptr & MS_RING_ON)!=0);
	setCD((dptr & MS_RLSD_ON)!=0);
}
예제 #23
0
파일: comm.c 프로젝트: Kelimion/wine
/* see knowledge base Q101417 */
static void COMM_MSRUpdate( HANDLE handle, UCHAR * pMsr )
{
    UCHAR tmpmsr=0;
    DWORD mstat=0;

    if(!GetCommModemStatus(handle,&mstat))
        return;

    if(mstat & MS_CTS_ON) tmpmsr |= MSR_CTS;
    if(mstat & MS_DSR_ON) tmpmsr |= MSR_DSR;
    if(mstat & MS_RING_ON) tmpmsr |= MSR_RI;
    if(mstat & MS_RLSD_ON) tmpmsr |= MSR_RLSD;
    *pMsr = (*pMsr & ~MSR_MASK) | tmpmsr;
}
int xbee_ser_get_cts( xbee_serial_t *serial)
{
	DWORD	dwModemStatus;

	XBEE_SER_CHECK( serial);

	if (!GetCommModemStatus( serial->hCom, &dwModemStatus))
	{
		#ifdef XBEE_SERIAL_VERBOSE
			printf( "%s: GetCommModemStatus error %lu\n", __FUNCTION__,
					GetLastError());
		#endif
		return -EIO;
	}
	return (dwModemStatus & MS_CTS_ON) ? 1 : 0;
}
예제 #25
0
파일: com.cpp 프로젝트: anosnowhong/phantom
BOOL    COM_ModemStatus( int item, DWORD *stat )
{
BOOL    ok=TRUE;

    if( !GetCommModemStatus(COM_Item[item].comH,stat) )
    {
        COM_errorf("COM_ModemStatus(COM%d) GetCommModemStatus() Failed (%s).\n",COM_Item[item].comX,COM_Error());
        ok = FALSE;
    }
    else
    {
        COM_debugf("COM_ModemStatus(COM%d) [%08lX] %s.\n",COM_Item[item].comX,*stat,STR_TextFlag(COM_ModemStatusText,*stat));
    }

    return(ok);
}
예제 #26
0
파일: serial.c 프로젝트: fishbaoz/flashrom
int sp_get_pin(enum SP_PIN pin) {
	int s;
#if IS_WINDOWS
	DWORD ctl;

	s = (pin == PIN_CTS) ? MS_CTS_ON : MS_DSR_ON;
	GetCommModemStatus(sp_fd, &ctl);
#else
	int ctl;
	s = (pin == PIN_CTS) ? TIOCM_CTS : TIOCM_DSR;
	ioctl(sp_fd, TIOCMGET, &ctl);
#endif

	return ((ctl & s) ? 1 : 0);

}
예제 #27
0
void _USERENTRY SerialStatusT(void *A)
	{
	SerialPortC *SP = (SerialPortC *) A;

	while (!SP->Closed)
		{
		Sleep(1000);
		WaitForSingleObject(SP->RMutex, INFINITE);

		if (!SP->Closed)
			{
			GetCommModemStatus(SP->hDev, &SP->ModemStatus);
			}

		ReleaseMutex(SP->RMutex);
		}
	}
예제 #28
0
파일: port.c 프로젝트: Ingenico/ruby-rs-232
VALUE lineStatusIO(VALUE self)
{

    PortDescriptor *port = NULL;

    Data_Get_Struct(self, PortDescriptor, port);

    unsigned long Status = 0, Temp = 0;

    GetCommModemStatus(port->fd, &Temp);

    if (Temp & MS_CTS_ON) Status |= LS_CTS;
    if (Temp & MS_DSR_ON) Status |= LS_DSR;
    if (Temp & MS_RING_ON) Status |= LS_RI;
    if (Temp & MS_RLSD_ON) Status |= LS_DCD;

    return LONG2FIX(Status);
}
예제 #29
0
BOOL CSerialPort::Get_RI_State()
  { 
    if (m_PortHandle != INVALID_HANDLE_VALUE)
      {
        DWORD ModemStat;
        if (GetCommModemStatus(m_PortHandle, &ModemStat))
          {
            return (ModemStat & MS_RING_ON) > 0;
          }
        else 
          {
            return FALSE;
          }
      }
    else 
      {
        return FALSE;
      }
  }
예제 #30
0
int wxSerialPort::GetLineState()
{
    BOOL ok = false;
    DWORD stat;
    int flags = 0;
    if(GetCommModemStatus(fd,&stat)) {
	   if(stat & MS_CTS_ON) 
		  flags |= wxSERIAL_LINESTATE_CTS;
	   if(stat & MS_DSR_ON) 
		  flags |= wxSERIAL_LINESTATE_DSR;
	   if(stat & MS_RING_ON) 
		  flags |= wxSERIAL_LINESTATE_RING;
	   if(stat & MS_RLSD_ON) 
		  flags |= wxSERIAL_LINESTATE_DCD;
	   ok = true;
    }
    if(!ok) return -1;
    return flags;
};