At the forefront of Artificial Intelligence
  Home Articles Reviews Interviews JDK Glossary Features Discussion Search
Home » Articles » Robotics » LEGO Mindstorms

CRipComm - RCX IR Protocal Communications Class

CRipComm is a wrapper class for communication with the LEGO RCX. For the details of RCX Communications see the AISolutions article and the CRipComm implementation.


This code is preliminary code (v0.6), please expect some bugs and other quirks. A lot of problems might be resolved by editing the wait time (see documentation), but if any other problems are found I'd appreciate it if you sent me a mail.

Public Interfaces

    CRipComm();
    ~CRipComm();

    bool    CheckTower();
    bool    Close();
    bool    Initialize(int);
    bool    SendOpcodes(const char *, int, bool bFormat = true);
    int     RetrieveReply(char *, int, bool bStrip = true);
		
    uint    GetWaitTime();
    void    SetWaitTime(uint wt);

    operator HANDLE() const;

CRipComm(), ~CRipComm()

Constructors and destructors. The destructor will close the port if you have not done so.

bool CheckTower()

Checks whether the tower is connected to the computer by checking the RTS and CTS signals. Note, if you have a fast computer, calling CheckTower repeatedly will cause it to fail (return false).

Return Value
True if tower is connected, otherwise false.

bool Initialize(int iPort)

Initializes the class and the serial port. It initializes the serial port to 2400 baud, Odd Parity, 8 databits, 1 stop bit and no flow control.

Return Value
True if serial port initializes, otherwise false.

Parameters
iPort
The port number (1-255).

bool SendOpcodes(const char *pszOpcodes, int iSize, bool bFormat = true)

Send specified number opcodes to the RCX, and will format them correctly if necessary. The function will attempt to send the data MAX_RCX_TRANS times. Note that this function also retrieves the reply 'silently'.

Returns Value
True if transmitted with a reply received, otherwise false.

Parameters:
pszOpcodes
The opcodes to be sent.

iSize
The number of bytes to send.

bFormat
Format the opcodes (add message header, complements and checksum). For example, these two calls will send the same data to the RCX:

	m_cRCX.SendOpcodes("\x30", 1);
	m_cRCX.SendOpcodes("\x55\xff\x00\x30\xcf\x30\xcf", 7, false);

int RetrieveReply(char *pszReply, int iSize, bool bStrip = true)

Retrieves the reply the RCX gave by copying iSize bytes into pszReply. If bStrip is true, the the message header, complements and checksums are removed.

Return Value
Number of bytes copied.

Parameters
pszReply
A pointer to a string to store the reply.

iSize
The number of bytes to copy into pszReply.

bStrip
Strip the header, complements and checksum from reply.

int GetWaitTime(), void SetWaitTime(uint)

Sets the wait time used in the class. Computers are reaching speeds that serial ports cannot easily cope with, therefore the class has a WaitTime implemented. For the test computer (PIII-933), a value of 25 millisecond was required to allow the code to execute properly. Faster computers might require a longer time, and slower computers may not require a wait time.

operator HANDLE() const

Returns a handle to the com port.

Return Value
A HANDLE to the com port in use by the class.

Last Updated: 21/04/2001

Article content copyright © James Matthews, 2001.
 Article Toolbar
Print
BibTeX entry

Search

Latest News
- Generation5 10-year Anniversary (03/09/2008)
- New Generation5 Design! (09/04/2007)
- Happy New Year 2007 (02/01/2007)
- Where has Generation5 Gone?! (04/11/2005)
- NeuroEvolving Robotic Operatives (NERO) (25/06/2005)

What's New?
- Back-propagation using the Generation5 JDK (07/04/2008)
- Hough Transforms (02/01/2008)
- Kohonen-based Image Analysis using the Generation5 JDK (11/12/2007)
- Modelling Bacterium using the JDK (19/03/2007)
- Modelling Bacterium using the JDK (19/03/2007)


All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -