To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcxOpen lugnet.robotics.rcx in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / 2364
2363  |  2365
Subject: 
Get/SetCommTimeouts
Newsgroups: 
lugnet.robotics.rcx
Date: 
Sun, 29 Feb 2004 17:46:08 GMT
Viewed: 
3903 times
  
I am trying to write a C program (using VC++ 6.0) to talk to RCX 2.0 on my
Win XP (Home Ed) box.

Everything seems to be OK except the get/set of Communication parameters. I
cannot understand why.

I have attached the minimal C program which does _not_ work (along with the
execution listing at the end).
It generates the "The parameter is incorrect" error.

Surprisingly it doesn't seem to matter since I can send and receive mesgs
just fine, even though the calls fail.

Any help will be highly appreciated.
TIA,
-- Shashank

/*************************************************************/
#include <windows.h>
#include <stdio.h>

#define DEBUG(x)  do{printf x;}while(0)

#define LEGO_USB_TOWER "\\\\.\\LEGOTOWER1"

HANDLE UsbPort; /* used for USB comm      */
char msg[255];  /* to hold the error mesg */

int show_error(int error_code)
{

int ret = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM +
FORMAT_MESSAGE_ARGUMENT_ARRAY,
            (LPCVOID)"",
            error_code,
            0,
            (LPTSTR)msg,
            255,
            (va_list *)NULL
         );
return ret;
}

int OpenUsbPort()
{
  int ret;
  COMMTIMEOUTS timeout;

  UsbPort = CreateFile(LEGO_USB_TOWER, GENERIC_READ | GENERIC_WRITE, 0, 0,
OPEN_EXISTING, 0, NULL);

  if (UsbPort == INVALID_HANDLE_VALUE)
  {int e;
    e = GetLastError();
show_error(e);
DEBUG(("Error = %d, %s\n",e,msg));
return 1;
  }


  DEBUG(("HANDLE = %d\n",UsbPort));

  ret = GetCommTimeouts(UsbPort,&timeout);
  DEBUG(("GetCommTimeouts returns %d \n",ret));
  if(ret == 0)
  {int e;
    e = GetLastError();
show_error(e);
DEBUG(("Error = %d, %s\n",e,msg));
  }
  timeout.ReadIntervalTimeout=100;
  timeout.ReadTotalTimeoutConstant=100;
  timeout.ReadTotalTimeoutMultiplier=0;
  timeout.WriteTotalTimeoutConstant=0;
  timeout.WriteTotalTimeoutMultiplier=0;
  ret = SetCommTimeouts(UsbPort,&timeout);

  DEBUG(("SetCommTimeouts returns %d \n",ret));
  if(ret == 0)
  {int e;
    e = GetLastError();
show_error(e);
DEBUG(("Error = %d, %s\n",e,msg));
  }

  return(0);
}

int CloseUsbPort()
{
int result;
result = CloseHandle(UsbPort);
DEBUG(("CloseHandle = %d\n",result));
    return result;
}

int main(int argc, char **argv)
{

if(OpenUsbPort()==0)
  CloseUsbPort();

return 0;
}

/* --------------------------------------
C:\atest\comm\Debug>comm
HANDLE = 2024
GetCommTimeouts returns 0
Error = 87, The parameter is incorrect.

SetCommTimeouts returns 0
Error = 87, The parameter is incorrect.

CloseHandle = 1

C:\atest\comm\Debug>
-----------------------------------------*/



Message has 1 Reply:
  Re: Get/SetCommTimeouts
 
"Shashank Date" <sdate@everestkc.net> wrote in message news:Htuzyn.6qG@lugnet.com... (...) parameters. I (...) The "SetCommTimeout" function only applies to "COMx" serial ports. You are trying to use it on a USB port! (21 years ago, 29-Feb-04, to lugnet.robotics.rcx)

3 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR