Example #1
0
HRESULT
    CUSBSimEndpoint::Init (CUSBSimDevice * pDevice,
                           USBENDPOINTDESC * pEndpointDesc)
{
    HRESULT hr;

    hr = CoCreateInstance (CLSID_SoftUSBEndpoint, NULL, CLSCTX_INPROC_SERVER,
                           __uuidof (ISoftUSBEndpoint),
                           reinterpret_cast < void **>(&m_pSoftUSBEndpoint));
    if (FAILED (hr)) {
        TRACE_ERR ("CoCreateInstance", hr);
    } else {
        m_pSoftUSBEndpoint->put_EndpointAddress (pEndpointDesc->Address.Byte);
        m_pSoftUSBEndpoint->put_Attributes (pEndpointDesc->Attributes.Byte);
        m_pSoftUSBEndpoint->put_MaxPacketSize (pEndpointDesc->MaxPacket.Word);
        m_pSoftUSBEndpoint->put_Interval (pEndpointDesc->bInterval);
        hr = InitEvents ();
        if (SUCCEEDED (hr)) {
            m_pDevice = pDevice;
            hr = InitPipe (pEndpointDesc->Address.Byte,
                           pEndpointDesc->Attributes.Bits.TransferType,
                           pEndpointDesc->MaxPacket.Bits.Size);
        }
    }
    return hr;
}
Example #2
0
WatcherNoticePipe::WatcherNoticePipe(EventLoop* evLoop,Framework* pFw) 
: WatcherBase(evLoop,pFw)
{
    RegCallBack();
    InitPipe();
    m_noticeTail = NULL;
    m_noticeHead = NULL;
}
Example #3
0
void PageDetail::InitTree()
{
	m_tree.DeleteAllItems();
	CString strText;
	strText.Format(_T("管道(%d)"),m_pCompManager->GetPipeNum());
	HTREEITEM hPipeitem = m_tree.InsertItem(strText);
	m_tree.SetItemData(hPipeitem,1);
	InitPipe(hPipeitem);
	
    strText.Format(_T("节点(%d)"),m_pCompManager->GetJunNum());
	HTREEITEM hJunItem = m_tree.InsertItem(strText);
	InitJun(hJunItem);
}
Example #4
0
void pipeThread (PVOID nsr)
{
	CStdString parsedMsg[MAX_WORDS_PIPEMSG];
	char *pipeNameStr = (char *)nsr;
	DWORD dw, ecode;
	HANDLE hPipe;
	int res, nArg;
	char PipeName[256], buffer[MAX_PATH], errstr[MAX_PATH], inBuf[MAX_PATH*4], inBuf2[MAX_PATH*4];
	HWND hDlg = hMainDlg;

	wsprintf(PipeName, "\\\\.\\pipe\\%s", pipeNameStr);

	if ((hPipe=InitPipe(hDlg, PipeName, errstr))==NULL)
	{ MessageBox (hDlg, errstr, "pipeThread", MB_OK);		_endthread();		return;	}

	_beginthread (pipeThread, 0, (void*)ACEPLAYER_CONSOLE_PIPENAME);

	while (1)
	{
		if (!ConnectNamedPipe (hPipe, NULL))
		{
			if (GetLastError() != ERROR_PIPE_CONNECTED)
			{	GetLastErrorStr(errstr);
				MessageBox (hDlg, "ERROR in ConnectNamedPipe()", errstr, MB_OK);
				_endthread();				return;			}
		}
		res = ReadFile (hPipe, inBuf, sizeof(inBuf), &dw, NULL);	inBuf[dw]='\0';
		if (!res)
		{
			 
			if ((ecode=GetLastError())==234)  /*More data is available.*/
			{
				ReadFile (hPipe, inBuf2, sizeof(inBuf), &dw, NULL);
				strcat(inBuf, inBuf2);
			}
			else
			{
				sprintf(buffer, "Erorr code=%d", ecode);
				MessageBox (hDlg, "ReadFile fails for pipe communication", buffer, MB_OK);
				break;
			}
		}
		nArg = str2array (parsedMsg, MAX_WORDS_PIPEMSG, inBuf, " ");
		SendMessage (GetDlgItem(hMainDlg, IDC_STATUSBAR), SB_SETTEXT, 1, (LPARAM)inBuf);
		EditPrintf (GetDlgItem(hPipeLog, IDC_MSG), "(incoming) %s\r\n", inBuf);
		ProcessParsedString (hPipe, parsedMsg, nArg);
		DisconnectNamedPipe(hPipe); // For Stateless named pipe connection, turn this line on.
		FlushFileBuffers(hPipe);
	}
}
Example #5
0
HRESULT
    CUSBSimEndpoint::Init (CUSBSimDevice * pDevice,
                           ISoftUSBEndpoint * pSoftUSBEndpoint)
{
    HRESULT hr;

    hr = pSoftUSBEndpoint->QueryInterface (__uuidof (ISoftUSBEndpoint),
                                           reinterpret_cast <
                                           void **>(&m_pSoftUSBEndpoint));
    if (FAILED (hr)) {
        TRACE_ERR ("QueryInterface", hr);
    } else {
        hr = InitEvents ();
        if (SUCCEEDED (hr)) {
            m_pDevice = pDevice;
            hr = InitPipe (0, CONTROL_ENDPOINT, 64);
        }
    }
    return hr;
}
Example #6
0
TTYIO *ttyioOpen(
    char *port,
    BOOL lock,
    INT32 ibaud,
    INT32 obaud,
    int parity,
    int flow,
    int sbits,
    INT32 to,
    INT32 pipe,
    LOGIO *lp
){
TTYIO *tp;
static char *fid = "ttyioOpen";

    if (port == NULL || strlen(port) > MAXPATHLEN) {
        logioMsg(lp, LOG_ERR, "%s: bad port arg", fid);
        errno = EINVAL;
        return NULL;
    }

    if (ibaud != obaud) {
        logioMsg(lp, LOG_ERR, "%s: ibaud(%d) != obaud(%d): %s", fid, ibaud, obaud);
        errno = EINVAL;
        return NULL;
    }

    if ((tp = (TTYIO *) malloc(sizeof(TTYIO))) == NULL) {
        logioMsg(lp, LOG_ERR, "%s: malloc: %s", fid, strerror(errno));
        return NULL;
    }
    MUTEX_INIT(&tp->mutex);
    tp->lp = lp;

    strcpy(tp->name, port);
    tp->attr = TTYIO_DEFAULT_ATTR;
    tp->attr.at_lock   = lock;
    tp->attr.at_ibaud  = ibaud;
    tp->attr.at_obaud  = obaud;
    tp->attr.at_flow   = flow;
    tp->attr.at_parity = parity;
    tp->attr.at_sbits  = sbits;
    tp->attr.at_to     = to;
    tp->attr.at_pipe   = pipe > 0 ? pipe : 0;

/* Open device and save current settings */

    if ((tp->fd = CreateFile(tp->name,
        GENERIC_READ | GENERIC_WRITE,
        0,
        NULL,
        OPEN_EXISTING,
        0,
        NULL
    )) == INVALID_HANDLE_VALUE) {
        logioMsg(lp, LOG_ERR, "%s: CreateFile: %s", fid, strerror(errno));
        return ttyioClose(tp);
    }
    tp->dcb.oldDcb.DCBlength = tp->dcb.oldDcb.DCBlength = sizeof(DCB);
    GetCommState(tp->fd, &tp->dcb.oldDcb);
    GetCommState(tp->fd, &tp->dcb.newDcb);

/* Reconfigure port to desired settings */

    /* Raw 8-bit i/o */

    tp->dcb.newDcb.fBinary   = TRUE;
    tp->dcb.newDcb.ByteSize  = 8;

    /* stop bits */

    tp->dcb.newDcb.StopBits  = (tp->attr.at_sbits == 1) ? ONESTOPBIT : TWOSTOPBITS;

    /* baud rate */

    tp->dcb.newDcb.BaudRate  = tp->attr.at_ibaud;

    /* flow control */

    switch (tp->attr.at_flow) {
      case TTYIO_FLOW_HARD:
        tp->dcb.newDcb.fInX            = FALSE;
        tp->dcb.newDcb.fOutX           = FALSE;
        tp->dcb.newDcb.fOutxCtsFlow    = TRUE;
        tp->dcb.newDcb.fRtsControl     = RTS_CONTROL_HANDSHAKE;
        tp->dcb.newDcb.fOutxDsrFlow    = TRUE;
        tp->dcb.newDcb.fDtrControl     = DTR_CONTROL_HANDSHAKE;
        break;
      case TTYIO_FLOW_SOFT:
        tp->dcb.newDcb.fInX            = TRUE;
        tp->dcb.newDcb.fOutX           = TRUE;
        tp->dcb.newDcb.XonLim          = 50;
        tp->dcb.newDcb.XoffLim         = 200;
        tp->dcb.newDcb.XonChar         = 17;
        tp->dcb.newDcb.XoffChar        = 19;
        tp->dcb.newDcb.fOutxDsrFlow    = FALSE;
        tp->dcb.newDcb.fDtrControl     = DTR_CONTROL_DISABLE;
        tp->dcb.newDcb.fOutxCtsFlow    = FALSE;
        tp->dcb.newDcb.fRtsControl     = RTS_CONTROL_DISABLE;
        break;
      case TTYIO_FLOW_NONE:
        tp->dcb.newDcb.fInX            = FALSE;
        tp->dcb.newDcb.fOutX           = FALSE;
        tp->dcb.newDcb.fOutxDsrFlow    = FALSE;
        tp->dcb.newDcb.fDtrControl     = DTR_CONTROL_DISABLE;
        tp->dcb.newDcb.fOutxCtsFlow    = FALSE;
        tp->dcb.newDcb.fRtsControl     = RTS_CONTROL_DISABLE;
        break;
      default:
        errno = EINVAL;
        logioMsg(lp, LOG_ERR, "%s: unsupported at_flow=%d", fid, tp->attr.at_flow);
        return ttyioClose(tp);
    }

    /* parity */

    switch (tp->attr.at_parity) {
      case TTYIO_PARITY_NONE:
        tp->dcb.newDcb.fParity = FALSE;
        tp->dcb.newDcb.Parity  = NOPARITY;
        break;
      case TTYIO_PARITY_ODD:
        tp->dcb.newDcb.fParity = TRUE;
        tp->dcb.newDcb.Parity  = ODDPARITY;
        break;
      case TTYIO_PARITY_EVEN:
        tp->dcb.newDcb.fParity = TRUE;
        tp->dcb.newDcb.Parity  = EVENPARITY;
        break;
      case TTYIO_PARITY_MARK:
        tp->dcb.newDcb.fParity = TRUE;
        tp->dcb.newDcb.Parity  = MARKPARITY;
        break;
      case TTYIO_PARITY_SPACE:
        tp->dcb.newDcb.fParity = TRUE;
        tp->dcb.newDcb.Parity  = SPACEPARITY;
        break;
      default:
        errno = EINVAL;
        logioMsg(lp, LOG_ERR, "%s: unsupported at_parity=%d", fid, tp->attr.at_parity);
        return ttyioClose(tp);
    }

    /* load the attributes */

    if (!SetCommState(tp->fd, &tp->dcb.newDcb)) {
        logioMsg(lp, LOG_ERR, "%s: SetCommState: %s", fid, strerror(errno));
        return ttyioClose(tp);
    }

    /* Set timeout interval */

    ttyioSetTimeout(tp, tp->attr.at_to);

    /* Set internal i/o buffer lengths */

    SetupComm(tp->fd, 32768, 32768);

    /* EscapeCommFunction(tp->fd, CLRDTR); */

/* Create pipe and fire up read thread if non-zero pipe length specified */

    tp->pipe.active = tp->pipe.failed = FALSE;
    if (tp->attr.at_pipe > 0 && (!InitPipe(tp) || !ttyioStartReadThread(tp))) {
        logioMsg(lp, LOG_ERR, "%s: failed to create pipe and start read thread", fid);
        return ttyioClose(tp);
    }

/* Return handle */

    return tp;
}