Subject:
|
Re: Using USB Tower with Alternative Firmware
|
Newsgroups:
|
lugnet.robotics.rcx
|
Date:
|
Sat, 16 Feb 2002 13:56:19 GMT
|
Viewed:
|
3235 times
|
| |
| |
Hi,
AFAIK only the following changes need to be made to a COMM-driver to work with
USB (Windows only):
First of all the Lego-USB-Driver has to be installed (happens automatically
when you install the MindStorms/RIS-software).
(In Control Panel the Lego-USB-Tower icon should be visible)
Instead of opening "COMx", open "\\.\LEGOTOWER1".
[note that in C that has to be quoted as "\\\\.\\LEGOTOWER1" ...]
Skip all COMM-specific stuff (setting baud rate, parity, timeouts, etc.).
Sample (C):
handle = CreateFile( "\\\\.\\LEGOTOWER1", GENERIC_READ | GENERIC_WRITE, 0, 0,
OPEN_EXISTING, 0, 0 );
When reading the tower you cannot simply use ReadFile(); instead use something
like this:
(the code is based on Jin Satos modifications to the legOS download utils; )
#define LNP_BYTE_TIME 5 // time to transmit a byte
#define REPLY_TIMEOUT 750000 // timeout for reply (usec)
#define BYTE_TIME (1000*LNP_BYTE_TIME) // time to transmit a byte (usec)
int USBReadFile( HANDLE h , unsigned char *pBuffer, int nBufferSize, LPDWORD
pReadSize, LPVOID pX )
{
// we use MILLIseconds here
int nRet = 0;
DWORD count = 0;
DWORD startticks,nowticks;
unsigned long total,elapsed;
total=(REPLY_TIMEOUT+nBufferSize*BYTE_TIME + 500) / 1000;
startticks = GetTickCount();
while ( count == 0 ) {
nRet = ReadFile( h, pBuffer, nBufferSize, &count , (LPOVERLAPPED)pX );
nowticks = GetTickCount();
if (nowticks < startticks) startticks = nowticks;
// in case system timer has just wrapped around
// [~after 50 days continues run]...
elapsed = (nowticks - startticks);
if ( elapsed > total ) break;
}
*pReadSize = count;
return nRet;
}
Basically that's all of it.
I was able to successfully patch WinLNP to work with an USB-Tower using the
described method.
Looking forward to see a USB-enabled version of pbForth :)
Regards,
--Alex
Refs:
Jin Satos modifications to legOS utils:
http://www.mi-ra-i.com/JinSato/MindStorms/deep/programing-of-ir-tower.html
(use babelfish or a similar translator to translate it; however double-check
the code-snippets with the original site!)
WinLNP by Yannis Jeannotat:
http://www.geocities.com/winlnp/
|
|
Message is in Reply To:
| | Using USB Tower with Alternative Firmware
|
| Hi All, I have some questions about alternative firmware support for USB towers. As the author of pbForth, I'm getting lots of requests to integrate USB tower support into the package. The old tower plugged into a seraial port, and for some MAc (...) (23 years ago, 22-Nov-01, to lugnet.robotics.rcx)
|
4 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|