Online Development Notebook > Index > Programming Overview > RobotBASIC

RobotBASIC


RobotBASIC from RobotBASIC.org supports the U4xx (versions greater than 3.2.0) through the USBm.dll file. RobotBASIC can be used as a BASIC language for simulating robot movement and sensing. It can also be used as a general-purpose utility language for interfacing with the U4xx device. And - best of all - RobotBASIC is FREE!

Commands that control the U4x1 are built in to RobotBASIC. These functions are listed below. These functions mirror the commands that would be called in the DLL (from VB or C, for example). Some of the DLL commands are combined into a single RobotBASIC function.

In the following list ne_ means numerical expression, se_ means string expression.

DLL Specific Functions

usbm_DllSpecs()

Returns a string that contains information about the DLL. There are four sections separated by the | character. You can use the Extract() function to extract each section separately if desired. The sections are:

         About, Copyright, and Version Date, Version Number

usbm_ErrorSpecs()

Returns a string that contains information about the recent error string and debug string if any in the DLL. There are two sections separated by the | character. You can use the Extract() function to extract each section separately if desired. The sections are:

         Recent Error, DEbug String

usbm_ClearRecentError()

Always returns -1. The function clears any recent error data in the DLL.

usbm_FindDevices()

Returns -1 (true) if there are U4x1 devices connected to the PC. Returns 0 (false) otherwise. You should call this function before you do anything with devices.

usbm_NumberOfDevices()

Returns the number of U4x1 devices connected to the PC. 0 means there are no devices connected.

usbm_SetReadTimeout(ne_Time)

Returns true if successful, false otherwise. This function sets the timeout for all the read commands. The value should be in milliseconds. The default is 1000 msecs = 1 sec.

Device Information Functions

usbm_DeviceSpecs(ne_DeviceNumber)

Returns a string that contains information about the device. There are 7 sections separated by the | character. You can use the Extract() function to extract each section separately if desired. The sections are:

           DID, PID, VID, Mfr, Prod, Serial Number, and Firmware Version.

usbm_DeviceValid(ne_DeviceNumber)

Returns true if the device number refers to a connected and active device. False otherwise.

usbm_CloseDevice(ne_DeviceNumber)

Returns true if the device was successfully closed. False otherwise.

Device I⁄O Functions

usbm_DeviceCmd(ne_DeviceNumber,se_Data)

Returns a string that contains the results of the response to the command specified in the se_Data string. The data string passed is a set of 8 bytes. The first byte specifies the command code and the next 7 bytes are any byte data required by the command. The returned string contains the first byte as the command number (again) and then the next 7 bytes are any data returned by the command. Not all the bytes may have significance in either the passed string or the returned string.

The passed string will be truncated to 8 bytes if it is longer. It can be shorter if not all the byte positions are required.

Use ArraStr() function to extract the byte values from the string. If you wish to print the data as hexadecimal values then use the Hex() function.

When creating the string of byte values use the Char(desired byte numeric value)  to convert the byte numerical value to a character so that it can be added to the string.

usbm_InitPorts(ne_DeviceNumber)

Returns true if successful, false otherwise. This function resets the A and B ports as Input Ports, which is the default state upon connecting the device to the PC.

usbm_DirectionA(ne_DeviceNumber,ne_PinsDirection,ne_PinsFormat)

usbm_DirectionB(ne_DeviceNumber,ne_PinsDirection,ne_PinsFormat)

Returns true if successful, false otherwise. This function sets the direction of each specific pin in the port. A 1 in the pin position means output, a 0 is input. The format byte should contain a 1 for each pin's position if it is output. If it is input you can have a 1 if you want an input pin with a pull up resistor, a 0 if you want the pin to have no pull up resistor.

usbm_WriteA(ne_DeviceNumber,ne_ByteValue)

usbm_WriteB(ne_DeviceNumber,ne_ByteValue)

Returns true if successful, false otherwise. The byte value is written to Port A⁄B.

usbm_ReadA(ne_DeviceNumber)

usbm_ReadB(ne_DeviceNumber)

Returns the byte value representing the states of the pins on Port A⁄B. The value returned is not a valid value if the device is not a validly active device.

usbm_SetBit(ne_DeviceNumber,ne_PinNumber)

usbm_ResetBit(ne_DeviceNumber,ne_PinNumber)

Returns true if successful, false otherwise. This function makes high⁄low a particular pin on any of the ports. The pin number is 0 for A0 1 for A1...7 for A7...8 for B0, ....15 for B7.

usbm_WriteABit(ne_DeviceNumber,ne_AndingMask, ne_OringMask)

usbm_WriteBBit(ne_DeviceNumber,ne_AndingMask, ne_OringMask)

Returns true if successful, false otherwise. This function reads the current status of the pins in the A⁄B port and then ands the value with the anding mask, then the new value is ored with the oring mask, then the result is written to port A⁄B.  Note: you can also use the ReadA⁄B() function then manipulate the byte returned using RB functions or operators and then use Write⁄AB() to write the result to the port. This performs  the same action.

usbm_InitLCD(ne_DeviceNumber,ne_Sel, ne_Port)

Returns true if successfull, false otherwise. It specifies the port to use for the data port and the pins to use for the R⁄W, RS, and E lines for controlling an LCD.

usbm_LCDCmd(ne_DeviceNumber,ne_CommandByte)

Returns true if successfull, false otherwise. Sends a command code to the LCD.

usbm_LCDData(ne_DeviceNumber,ne_DataByte)

Returns true if successfull, false otherwise. Sends a data byte to the LCD.

usbm_Reset1Wire(ne_DeviceNumber,ne_Specs)

Returns the status of any devices on the 1wire line. Returns 0 if any device responded and 1 if none did. This function sets up the 1wire line to be used.

usbm_Write1Wire(ne_DeviceNumber,ne_Data)

Returns true if successfull, false otherwise. Writes a byte to the 1wire device.

usbm_Read1Wire(ne_DeviceNumber)

Returns a byte value that is read from the 1wire device.

usbm_Write1WireBit(ne_DeviceNumber,ne_BitValue)

Returns true if successfull, false otherwise. Writes a 0 or 1 to the 1wire device.

usbm_Read1WireBit(ne_DeviceNumber)

Returns a bit value that is read from the 1wire device.

usbm_InitSPI(ne_DeviceNumber,ne_Specs)

Returns true if successfull, false otherwise. It sets the attributes of the SPI system.

usbm_SPISlaveRead(ne_DeviceNumber)

Returns a string of byte data from the Slave buffer (maximum 6 bytes). You can use the ArrayStr() function to extract the individual bytes.

usbm_SPISlaveWrite(ne_DeviceNumber,se_DataBytes)

Returns true if successful, false otherwise. Writes 1 to 6 bytes to the SPI slave buffer. The length of the data string determines the number of bytes written. Use Char() to create the data string.

usbm_SPIMaster(ne_DeviceNumber,se_DataBytes)

Returns a string of byte values inputted from the SPI master after it has read the corresponding number of bytes from the data string. Use ArrayStr() to extract the byte values and Char() to create the data string.

usbm_Stepper(ne_DeviceNumber,se_DataSpecs)

Returns true if successful, false otherwise. The byte data string specifies the channel and so forth.

usbm_StrobeWrite(ne_DeviceNumber,se_ByteData)

Returns true if successful, false otherwise. Writes a byte to a port based on a strobing line and timing. the byte data string specifies the setup and so forth.

usbm_StrobeRead(ne_DeviceNumber,se_ByteData)

Returns a byte value of data read from a port based on a strobing line and timing. the byte data string specifies the setup and so forth.

usbm_StrobeWrites(ne_DeviceNumber,se_ByteData)

Returns true if successful, false otherwise. Writes multiple bytes (1 to 6) to a port based on a strobing line and timing. the byte data string specifies the setup and the data to be written.

usbm_StrobeReads(ne_DeviceNumber,se_ByteData)

Returns a string of byte data read from a port based on a strobing line and timing. the byte data string specifies the setup and so forth.

Simple code example for output

The very minimum application would be to use RobotBASIC to open the USB device and transmit a single command or two. This example shows the code that it takes to use RobotBASIC to open the U401⁄U421 device, initialize the ports, and output a value.

MainProgram:

    ⁄⁄---------------------------
    ⁄⁄ Discover the devices
    ⁄⁄---------------------------

    n = usbm_finddevices()

    ⁄⁄ Set dir of port A of dev 0 to out
    n = usbm_DirectionA(0, 255, 255)

    n = usbm_WriteA(0, 255)


End

Find serial numbers of all attached U4x1 devices

A more sophisticated example shows what it takes to use RobotBASIC to open all attached U4x1 devices and get their serial numbers.



⁄⁄---------------------------------------------------------------------------
⁄⁄
⁄⁄ Main Program
⁄⁄
⁄⁄---------------------------------------------------------------------------

MainProgram:

    ⁄⁄ Allow screen double buffering
    Flip On


    ⁄⁄---------------------------
    ⁄⁄ Get information for DLL
    ⁄⁄---------------------------

    xyText 5, 20, "USBmicro DLL Data", "Verdana", 15, fs_Bold|fs_Underlined

    m = usbm_DLLSpecs()


    ⁄⁄---------------------------
    ⁄⁄ Display discovered information
    ⁄⁄---------------------------

    ⁄⁄ About this DLL
    xyText 25, 60, "About:" + Extract(m,"|",1), "Verdana", 10

    ⁄⁄ DLL Version and Date
    xyText 25, 80, "DLL Version: " + Extract(m,"|",4), "Verdana", 10
    xyText 25, 100, "DLL Version date: " + Extract(m,"|",3), "Verdana", 10


    ⁄⁄---------------------------
    ⁄⁄ Get information about
    ⁄⁄ connected devices.
    ⁄⁄---------------------------

    ⁄⁄ Discover the devices
    n = usbm_finddevices()


    ⁄⁄ Count devices
    n = usbm_numberofdevices()
    m = ""
    if n != 1 then m = "s"
    xyText 5, 150, "Found " + n + " Device" + m, "Verdana", 10


    ⁄⁄ Display devices
    xyText 5, 180, "Device", "Verdana", 10, fs_Bold|fs_Underlined
    xyText 80, 180, "Made By", "Verdana", 10, fs_Bold|fs_Underlined
    xyText 220, 180, "Type", "Verdana", 10, fs_Bold|fs_Underlined
    xyText 300, 180, "Serial Number", "Verdana", 10, fs_Bold|fs_Underlined


    ⁄⁄ Loop through all of the devices
    for loop = 1 to n

        ⁄⁄ Get device info
        m = usbm_DeviceSpecs(loop - 1)

        ⁄⁄ Print device info
        xyText 5, 190 + (20 * loop), loop, "Verdana", 10
        xyText 80, 190 + (20 * loop), extract(m,"|",4), "Verdana", 10
        xyText 220, 190 + (20 * loop), extract(m,"|",5), "Verdana", 10
        xyText 300, 190 + (20 * loop), extract(m,"|",6), "Verdana", 10

    next loop


    ⁄⁄ Show buffered screen
    flip

    Waitkey " ", n


End


Hardware:  U401 USB Interface    U421 USB Interface   U451 USB Interface

Programming:  USBm DLL Programming    Download Files

Application Notes:  U4x1 Application Notes    Misc Applications and Information    FAQ

While every effort has been made to make sure that the information posted on this site is correct, the author can not be held liable for any damages whatsoever for losses as a result of the application of this information. Use this information at your own risk.

USBmicro can design your custom and semi-custom USB product. Email about USB design can be directed to " Robert " at usbmicro.com.

Copyright © USBmicro, L.L.C., 2002-2010

Previous  |  Next ]     [ Up  |  First  |  Last ]     (Article 23 of 126)

This page is created with TreePad