예제 #1
0
void DwListDevices(void) {
  if (PortCount <= 0) {
    Fail("No devices available.");
  } else {
    int i;
    for (i=0; i<PortCount; i++) {
      if (Ports[i]->baud >= 0) {ConnectPort(i, 0);}
    }
    for (i=0; i<PortCount; i++) {
      if (Ports[i]->baud > 0) {DescribePort(i);}
    }
  }
  CurrentPort = -1;
}
예제 #2
0
void DwFindPort(char kind, int index, int baud) {
  int i = 0;
  //Ws("Debug. DwFindPort("); Wc(kind); Ws(", "); Wd(index,1); Ws(", "); Wd(baud,1); Wsl(")");
  while (i<PortCount) {
    if (Ports[i]->kind) {
      if (    ((kind == 0)  || (kind  == Ports[i]->kind))
          &&  ((index == -1) || (index == Ports[i]->index))) {
        ConnectPort(i, baud);
        if (Ports[i]->baud > 0) break;
      }
    }
    i++;
  }
  if (i < PortCount  &&  Ports[i]->baud > 0) {
    CurrentPort = i;
    ResetDumpStates();
    DwReconnect();
  } else {
    CurrentPort = -1;
  }
}
예제 #3
0
파일: conport.c 프로젝트: hoangduit/reactos
VOID
TryConnectPort(char *port_name)
{
	DWORD			Status = 0;
	HANDLE			Port = 0;
	int			i;
	UNICODE_STRING		PortName;
	OBJECT_ATTRIBUTES	ObjectAttributes;
	WORD			Name [BUF_SIZE] = {0};
	int			dwx = 0;
	char			* port_name_save = port_name;

	/*
	 * Convert the port's name to Unicode.
	 */
	for (
		PortName.Length = 0;
		(	*port_name
			&& (PortName.Length < BUF_SIZE)
			);
		)
	{
		Name[PortName.Length++] = (WORD) *port_name++;
	}
	Name[PortName.Length] = 0;

	PortName.Length = PortName.Length * sizeof (WORD);
	PortName.MaximumLength = PortName.Length + sizeof (WORD);
	PortName.Buffer = (PWSTR) Name;
	/*
	 * Prepare the port object attributes.
	 */
	ObjectAttributes.Length =
		sizeof (OBJECT_ATTRIBUTES);
	ObjectAttributes.RootDirectory =
		NULL;
	ObjectAttributes.ObjectName =
		NULL /*& PortName */;
	ObjectAttributes.Attributes =
		OBJ_CASE_INSENSITIVE;
	ObjectAttributes.SecurityDescriptor =
		NULL;
	ObjectAttributes.SecurityQualityOfService =
		NULL;
	/*
	 * Try to issue a connection request.
	 */
	Port = 0;
	Status = ConnectPort(
			& Port,			/* & PortHandle */
			& PortName,		/* & PortName */
			& ObjectAttributes,	/* & PortAttributes */
			NULL,			/* & SecurityQos */
			NULL,			/* & SectionInfo */
			NULL,			/* & MapInfo */
			NULL,			/* & MaxMessageSize */
			LPC_CONNECT_FLAG5	/* & ConnectInfoLength */
			);
	if (Status == STATUS_SUCCESS)
	{
		DumpInfo(
			Name,
			Status,
			"connected",
			Port
			);
		/* Hot waiting */
		for (dwx=0; dwx<MAXARG; ++dwx)
		{
			YieldExecution();
		}
		if (FALSE == CloseHandle(Port))
		{
			printf(
				"Could not close the port handle %08X.\n",
				Port
				);
		}
		return;
	}
	printf(
		"Connection to port \"%s\" failed (Status = %08X).\n",
		port_name_save,
		Status
		);
}