libroboint
|
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <semaphore.h>
#include <termios.h>
#include <fcntl.h>
#include <usb.h>
#include <sys/timerfd.h>
#include "crc.h"
#include "roboint.h"
Functions | |
long int | GetLibVersion () |
Returns lib version. More... | |
char * | GetLibVersionStrg () |
Returns lib version. More... | |
long int | InitFtLib () |
Library initialization (dummy) More... | |
long int | InitFtUsbDeviceList () |
Initiates and scans the USB bus. More... | |
unsigned int | GetNumFtUsbDevice () |
Get the count of found ft Interfaces over USB. More... | |
FT_HANDLE | GetFtUsbDeviceHandle (unsigned char Num) |
Gets the handle to a ft USB device. More... | |
FT_HANDLE | GetFtUsbDeviceHandleSerialNr (long int dwSN, long int dwTyp) |
Gets the handle to a ft USB device with a specific serial number. More... | |
FT_HANDLE | OpenFtCommDevice (char *sDevice, long int dwTyp, long int dwZyklus) |
Gets the handle to a ft serial device. More... | |
long int | GetFtDeviceTyp (FT_HANDLE hFt) |
Returns type of the interface. More... | |
long int | GetFtDeviceTypeString (FT_HANDLE hFt, char *dest, int len) |
Returns a string that identifies the interface with human words. More... | |
long int | OpenFtUsbDevice (FT_HANDLE hFt) |
Opens this USB device. More... | |
long int | CloseFtDevice (FT_HANDLE hFt) |
Close the ft Device. More... | |
long int | CloseFtLib () |
Library deinitialization (dummy) More... | |
long int | IsFtLibInit () |
Check for Library initialization (dummy) More... | |
long int | ResetFtTransfer (FT_HANDLE hFt) |
reset outputs More... | |
long int | StartFtTransferArea (FT_HANDLE hFt, NOTIFICATION_EVENTS *ignored) |
Starts the communication thread. More... | |
long int | StartFtTransferAreaWithCommunication (FT_HANDLE hFt, NOTIFICATION_EVENTS *ignored) |
Starts the communication thread. More... | |
FT_TRANSFER_AREA * | GetFtTransferAreaAddress (FT_HANDLE hFt) |
Get the transfer area. More... | |
long int | StopFtTransferArea (FT_HANDLE hFt) |
Stops the communication thread. More... | |
long int | IsFtTransferActiv (FT_HANDLE hFt) |
check if transfer is active. More... | |
long int | DownloadFtProgram (FT_HANDLE hFt, long int dwMemBlock, unsigned char *pbArray, long int dwSize, long int dwParameter, unsigned char *pbName, long int dwNameLen) |
Upload a program to the interface. More... | |
long int | StartFtProgram (FT_HANDLE hFt, long int dwMemBlock) |
Start a program. More... | |
long int | StopFtProgram (FT_HANDLE hFt) |
Stop a program. More... | |
long int | DeleteFtProgram (FT_HANDLE hFt, long int dwMemBlock) |
Delete a program. More... | |
long int | SetFtProgramActiv (FT_HANDLE hFt, long int dwMemBlock) |
Activate a program. More... | |
long int | GetFtProgramName (FT_HANDLE hFt, long int dwMemBlock, long int dwSize, void *pName) |
Get the name of a program. More... | |
int | GetFtStatus (FT_HANDLE hFt, int *num) |
Checks if a program is running. More... | |
long int | GetFtFirmware (FT_HANDLE hFt) |
Get the firmware number of this interface. More... | |
char * | GetFtFirmwareStrg (FT_HANDLE hFt) |
Get the firmware number of this interface. More... | |
long int | GetFtSerialNr (FT_HANDLE hFt) |
Get the serial number of this interface. More... | |
char * | GetFtSerialNrStrg (FT_HANDLE hFt) |
Get the serial number of this interface. More... | |
long int | CloseAllFtDevices () |
Close all ft devices. More... | |
long int | SetFtDistanceSensorMode (FT_HANDLE hFt, long int dwMode, long int dwTol1, long int dwTol2, long int dwLevel1, long int dwLevel2, long int dwRepeat1, long int dwRepeat2) |
Set the inputs D1 and D2 to distance oder voltage measuring. More... | |
long int | SetRFMode (FT_HANDLE hFt, long int frequency, long int callSign) |
Sets the frequency and call sign for a Robo Interface or RF Data Link. More... | |
long int | GetRFMode (FT_HANDLE hFt, long int *frequency, long int *callSign) |
Gets the frequency and call sign of a Robo Interface or RF Data Link. More... | |
long int | SetRealSerial (FT_HANDLE hFt, unsigned char bOn) |
Switches between the real serial and 0001 of a device. More... | |
char * | GetFtManufacturerStrg (FT_HANDLE hFt) |
Gets the Manufacturer of the Interface. More... | |
char * | GetFtShortNameStrg (FT_HANDLE hFt) |
Gets the short name of the Interface. More... | |
char * | GetFtLongNameStrg (FT_HANDLE hFt) |
Gets the long name of the Interface. More... | |
char | IsFtInterfaceConnected (FT_HANDLE hFt) |
Tells if we successfuly got a connection to the Interface. More... | |
char * | GetFtLibErrorString (long int dwErrorCode, long int dwTyp) |
Gets the description of an error. More... | |
Copyright (C) 2013 Erik Andresen erik@ vont aene. de
Open Source version of the fischertechnik ROBO Interface Library for Unix like systems
Communication is done through a "transfer area" this is constantly updated.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
long int CloseAllFtDevices | ( | ) |
Close all ft devices.
Dummy. Can't be supported. Only used in original library.
long int CloseFtDevice | ( | FT_HANDLE | hFt | ) |
Close the ft Device.
This function will close the ft Device and free its memory. Warning: CloseFtDevice() will also free() the allocated memory for this device! Meaning, that you should not call OpenFtUsbDevice() after CloseFtDevice().
hFt | Handle of the Device to close. |
References ft_handle_devices::device, ft_handle_devices::saveioset, ft_handle_devices::sdev, ft_handle_devices::transfer_area, _FT_TRANSFER_AREA::TransferAktiv, and ft_handle_devices::type.
Referenced by GetFtUsbDeviceHandleSerialNr().
long int CloseFtLib | ( | ) |
Library deinitialization (dummy)
Dummy for compatibility. Only used in original library.
long int DeleteFtProgram | ( | FT_HANDLE | hFt, |
long int | dwMemBlock | ||
) |
Delete a program.
Will delete a program that has been uploaded to the interface.
hFt | Handle of the Interface |
dwMemBlock | Destination 0 (Flash 1), 1 (Flash 2) or 2 (Ram) |
References ft_handle_devices::device, ft_handle_devices::sdev, and ft_handle_devices::type.
long int DownloadFtProgram | ( | FT_HANDLE | hFt, |
long int | dwMemBlock, | ||
unsigned char * | pbArray, | ||
long int | dwSize, | ||
long int | dwParameter, | ||
unsigned char * | pbName, | ||
long int | dwNameLen | ||
) |
Upload a program to the interface.
Upload (download from the perspective of the interface) a program to the interface.
hFt | Handle of the Interface |
dwMemBlock | Destination 0 (Flash 1), 1 (Flash 2) or 2 (Ram) |
pbArray | Pointer to the program to upload |
dwSize | Size of the program to upload |
dwParameter | 1 to Autostart this program, else 0. |
pbName | Name of the program to upload |
dwNameLen | Length of the name |
References ft_handle_devices::device, and ft_handle_devices::type.
long int GetFtDeviceTyp | ( | FT_HANDLE | hFt | ) |
Returns type of the interface.
This function will return the type of the interface that is behind the handle.
hFt | Handle of the device |
References ft_handle_devices::type.
Referenced by GetFtDeviceTypeString().
long int GetFtDeviceTypeString | ( | FT_HANDLE | hFt, |
char * | dest, | ||
int | len | ||
) |
Returns a string that identifies the interface with human words.
This function will give you a human readable string like "Robo Interface" you can work with.
hFt | Handle of the device |
dest | Buffer we can write the string to |
len | Maximum length of this buffer |
References GetFtDeviceTyp().
long int GetFtFirmware | ( | FT_HANDLE | hFt | ) |
Get the firmware number of this interface.
Returns the firmware number of the interface squashed into a single int.
hFt | Handle of the Interface |
References ft_handle_devices::device, _FT_TRANSFER_AREA::RfModulNr, ft_handle_devices::sdev, ft_handle_devices::transfer_area, and ft_handle_devices::type.
Referenced by GetFtFirmwareStrg().
char* GetFtFirmwareStrg | ( | FT_HANDLE | hFt | ) |
Get the firmware number of this interface.
Returns the firmware number of the interface with this handle. The allocated space should be freed with free() later.
hFt | Handle of the Interface |
References GetFtFirmware().
char* GetFtLibErrorString | ( | long int | dwErrorCode, |
long int | dwTyp | ||
) |
Gets the description of an error.
Will return a description of an error. The allocated space should be freed with free() later.
The return value is the constant as string if parameter dwTyp is 0, else a verbose description of the error.
dwErrorCode | Error Code |
dwTyp | Type of the return value (see description) |
char* GetFtLongNameStrg | ( | FT_HANDLE | hFt | ) |
Gets the long name of the Interface.
Will return the long name of a fischertechnik USB device. The allocated space should be freed with free() later.
hFt | Handle of the Interface |
References ft_handle_devices::device, and ft_handle_devices::type.
char* GetFtManufacturerStrg | ( | FT_HANDLE | hFt | ) |
Gets the Manufacturer of the Interface.
Will return the Manufacturer of a fischertechnik USB device. The allocated space should be freed with free() later.
hFt | Handle of the Interface |
References ft_handle_devices::device, and ft_handle_devices::type.
long int GetFtProgramName | ( | FT_HANDLE | hFt, |
long int | dwMemBlock, | ||
long int | dwSize, | ||
void * | pName | ||
) |
Get the name of a program.
Will write the name of a program that has been uploaded to the interface to a given area.
hFt | Handle of the Interface |
dwMemBlock | Destination 0 (Flash 1), 1 (Flash 2) or 2 (Ram) |
pName | Pointer to the area where we can store the name |
dwSize | Size of the area to store the name to |
References ft_handle_devices::device, ft_handle_devices::sdev, and ft_handle_devices::type.
long int GetFtSerialNr | ( | FT_HANDLE | hFt | ) |
Get the serial number of this interface.
Returns the serial number of the interface squashed into a single int.
hFt | Handle of the Interface |
References ft_handle_devices::device, _FT_TRANSFER_AREA::RfModulNr, ft_handle_devices::sdev, ft_handle_devices::transfer_area, and ft_handle_devices::type.
Referenced by GetFtSerialNrStrg(), and GetFtUsbDeviceHandleSerialNr().
char* GetFtSerialNrStrg | ( | FT_HANDLE | hFt | ) |
Get the serial number of this interface.
Returns the serial number of the interface with this handle. The allocated space should be freed with free() later.
hFt | Handle of the Interface |
References GetFtSerialNr().
char* GetFtShortNameStrg | ( | FT_HANDLE | hFt | ) |
Gets the short name of the Interface.
Will return the short name of a fischertechnik USB device. The allocated space should be freed with free() later.
hFt | Handle of the Interface |
References ft_handle_devices::device, and ft_handle_devices::type.
int GetFtStatus | ( | FT_HANDLE | hFt, |
int * | num | ||
) |
Checks if a program is running.
Checks if a program is currently running.
hFt | Handle of the Interface |
num | Area where we can store the number of the running program. |
References ft_handle_devices::device, ft_handle_devices::sdev, and ft_handle_devices::type.
FT_TRANSFER_AREA* GetFtTransferAreaAddress | ( | FT_HANDLE | hFt | ) |
Get the transfer area.
This function will return a pointer to the transfer area of the given handle.
hFt | Handle of the device. |
References ft_handle_devices::transfer_area.
FT_HANDLE GetFtUsbDeviceHandle | ( | unsigned char | Num | ) |
Gets the handle to a ft USB device.
doxygen ignore end
Get the handle for the ft USB device with this number. Passing just 0 as argument will use the first device found.
Count the interfaces with GetNumFtUsbDevice()
Num | selected Interface. If unsure try 0. |
References ft_handle_devices::dev, ft_handle_devices::device, ft_handle_devices::interface_connected, ft_handle_devices::lock, ft_handle_devices::query_time, _FT_TRANSFER_AREA::RfModulNr, ft_handle_devices::sdev, ft_handle_devices::transfer_area, _FT_TRANSFER_AREA::TransferAktiv, and ft_handle_devices::type.
Referenced by GetFtUsbDeviceHandleSerialNr().
FT_HANDLE GetFtUsbDeviceHandleSerialNr | ( | long int | dwSN, |
long int | dwTyp | ||
) |
Gets the handle to a ft USB device with a specific serial number.
Get the handle for the ft USB device with this number. Serial is 1 for most devices, unless explicitly changed in the device. Second argument can be FT_AUTO_TYPE.
dwSN | Serial of the USB Device |
dwTyp | Type of the USB Device: FT_AUTO_TYPE, FT_ROBO_IF_USB, FT_ROBO_IO_EXTENSION, FT_ROBO_IF_OVER_RF or FT_ROBO_RF_DATA_LINK |
References CloseFtDevice(), GetFtSerialNr(), GetFtUsbDeviceHandle(), GetNumFtUsbDevice(), OpenFtUsbDevice(), and ft_handle_devices::type.
long int GetLibVersion | ( | ) |
Returns lib version.
doxygen ignore end
Returns the library version.
Referenced by GetLibVersionStrg().
char* GetLibVersionStrg | ( | ) |
Returns lib version.
Returns the library version. The allocated space should be freed with free() later.
References GetLibVersion().
unsigned int GetNumFtUsbDevice | ( | ) |
Get the count of found ft Interfaces over USB.
doxygen ignore end
If we find a Robo RF Data Link we will count the devices attached to it instead
Referenced by GetFtUsbDeviceHandleSerialNr().
long int GetRFMode | ( | FT_HANDLE | hFt, |
long int * | frequency, | ||
long int * | callSign | ||
) |
Gets the frequency and call sign of a Robo Interface or RF Data Link.
Sets the frequency and call sign which allows to control multiple Interfaces at one RF Data Link.
hFt | Handle of the Interface |
frequency | Points to a place to store the frequency. |
callSign | Points to a place to store the callSign. (Value will be 0 for the RF Data Link) |
References ft_handle_devices::device, ft_handle_devices::sdev, and ft_handle_devices::type.
long int InitFtLib | ( | ) |
Library initialization (dummy)
Dummy for compatibility. Only used in original library.
long int InitFtUsbDeviceList | ( | ) |
Initiates and scans the USB bus.
This function has to be called before any other USB action. It will set up USB basic variables and then scan the USB bus.
char IsFtInterfaceConnected | ( | FT_HANDLE | hFt | ) |
Tells if we successfuly got a connection to the Interface.
hFt | Handle of the Interface |
References ft_handle_devices::interface_connected.
long int IsFtLibInit | ( | ) |
Check for Library initialization (dummy)
Dummy for compatibility. Only used in original library.
long int IsFtTransferActiv | ( | FT_HANDLE | hFt | ) |
check if transfer is active.
Check if we are currently communicating with the device.
hFt | Handle of the Interface. |
References ft_handle_devices::transfer_area, and _FT_TRANSFER_AREA::TransferAktiv.
FT_HANDLE OpenFtCommDevice | ( | char * | sDevice, |
long int | dwTyp, | ||
long int | dwZyklus | ||
) |
Gets the handle to a ft serial device.
Get the handle for the ft Serial device at the selected serial port.
sDevice | filename of your serial device, like /dev/ttyS0. |
dwTyp | Interface type. FT_INTELLIGENT_IF, FT_INTELLIGENT_IF_SLAVE or FT_ROBO_IF_COM. |
dwZyklus | Cycle to retrieve analog values (only II). Try 10. |
References ft_handle_devices::analogcycle, _FT_TRANSFER_AREA::BusModules, ft_handle_devices::dev, ft_handle_devices::device, ft_handle_devices::interface_connected, ft_handle_devices::lock, ft_handle_devices::newioset, ft_handle_devices::query_time, _FT_TRANSFER_AREA::RfModulNr, ft_handle_devices::saveioset, ft_handle_devices::sdev, ft_handle_devices::transfer_area, _FT_TRANSFER_AREA::TransferAktiv, and ft_handle_devices::type.
long int OpenFtUsbDevice | ( | FT_HANDLE | hFt | ) |
Opens this USB device.
This function will try to open the ft USB device that belongs to the ft handle hFt. You can get the ft handle with GetFtUsbDeviceHandle() or GetFtUsbDeviceHandleSerialNr().
hFt | ft USB Device to open |
References ft_handle_devices::dev, and ft_handle_devices::device.
Referenced by GetFtUsbDeviceHandleSerialNr().
long int ResetFtTransfer | ( | FT_HANDLE | hFt | ) |
reset outputs
doxygen ignore end
Will clear all outputs.
References _FT_TRANSFER_AREA::M_Main, _FT_TRANSFER_AREA::M_Sub1, _FT_TRANSFER_AREA::M_Sub2, _FT_TRANSFER_AREA::M_Sub3, and ft_handle_devices::transfer_area.
long int SetFtDistanceSensorMode | ( | FT_HANDLE | hFt, |
long int | dwMode, | ||
long int | dwTol1, | ||
long int | dwTol2, | ||
long int | dwLevel1, | ||
long int | dwLevel2, | ||
long int | dwRepeat1, | ||
long int | dwRepeat2 | ||
) |
Set the inputs D1 and D2 to distance oder voltage measuring.
This function allows to enable the inputs D1 and D2 to measure distances. Must be called before StartFtTransferArea()
Note by Hardware Vendor: "Since the operating mode of the D1 / D2 inputs can be set by means of software, we recommend that no voltage be supplied 'directly' to these connections in order to avoid damage to the interface during software errors. Since the inputs are highly resistive, a resistance of approximately 200 Ohm - 470 Ohm should be directly connected to the D1 / D2 socket (series connection). We recommend to connect the voltage range to be measured 'behind' it."
hFt | Handle of the Interface |
dwMode | Set mode to IF_DS_INPUT_VOLTAGE (measure voltage) or IF_DS_INPUT_DISTANCE (measure distance) |
dwTol1 | Range of tolerance for D1. Try IF_DS_INPUT_TOL_STD (20). |
dwTol2 | Range of tolerance for D2. Try IF_DS_INPUT_TOL_STD (20). |
dwLevel1 | Threshold for D1. Try 100. |
dwLevel2 | Threshold for D2. Try 100. |
dwRepeat1 | Repition value for D1. Try IF_DS_INPUT_REP_STD (3). |
dwRepeat2 | Repition value for D2. Try IF_DS_INPUT_REP_STD (3). |
References ft_handle_devices::device, _FT_TRANSFER_AREA::RfModulNr, ft_handle_devices::sdev, ft_handle_devices::transfer_area, and ft_handle_devices::type.
long int SetFtProgramActiv | ( | FT_HANDLE | hFt, |
long int | dwMemBlock | ||
) |
Activate a program.
Will activate a program that has been uploaded to the interface.
hFt | Handle of the Interface |
dwMemBlock | Destination 0 (Flash 1) or 1 (Flash 2) |
References ft_handle_devices::device, ft_handle_devices::sdev, and ft_handle_devices::type.
long int SetRealSerial | ( | FT_HANDLE | hFt, |
unsigned char | bOn | ||
) |
Switches between the real serial and 0001 of a device.
Every ft Interface is shipped with 0001 as serial. Nevertheless each has its own serial which can be activated.
hFt | Handle of the Interface |
bOn | 0 to use 0001, else the real serial |
References ft_handle_devices::device, ft_handle_devices::sdev, and ft_handle_devices::type.
long int SetRFMode | ( | FT_HANDLE | hFt, |
long int | frequency, | ||
long int | callSign | ||
) |
Sets the frequency and call sign for a Robo Interface or RF Data Link.
Sets the frequency and call sign which allows to control multiple Interfaces at one RF Data Link. The value won't be lost on power failure.
hFt | Handle of the Interface |
frequency | to use. May be between 2 and 80. |
callSign | call sign for this Interface. May be between 1 and 8. (ignored for the RF Data Link) |
References ft_handle_devices::device, ft_handle_devices::sdev, and ft_handle_devices::type.
long int StartFtProgram | ( | FT_HANDLE | hFt, |
long int | dwMemBlock | ||
) |
Start a program.
Will start a program that has been Successfully uploaded to the interface.
hFt | Handle of the Interface |
dwMemBlock | Destination 0 (Flash 1), 1 (Flash 2) or 2 (Ram) |
References ft_handle_devices::device, ft_handle_devices::sdev, and ft_handle_devices::type.
long int StartFtTransferArea | ( | FT_HANDLE | hFt, |
NOTIFICATION_EVENTS * | ignored | ||
) |
Starts the communication thread.
This function is needed to start the communication with the interface in passive mode. Get the handle with GetFtUsbDeviceHandle(), GetFtUsbDeviceHandleSerialNr() or OpenFtCommDevice().
hFt | Handle of the interface. |
ignored | The second argument is ignored in this version. |
References ft_handle_devices::t.
Referenced by StartFtTransferAreaWithCommunication().
long int StartFtTransferAreaWithCommunication | ( | FT_HANDLE | hFt, |
NOTIFICATION_EVENTS * | ignored | ||
) |
Starts the communication thread.
Since notification are ignored in this version, will just call StartFtTransferArea().
References StartFtTransferArea().
long int StopFtProgram | ( | FT_HANDLE | hFt | ) |
Stop a program.
Will stop the current running program that has been uploaded to the interface.
hFt | Handle of the Interface |
References ft_handle_devices::device, ft_handle_devices::sdev, and ft_handle_devices::type.
long int StopFtTransferArea | ( | FT_HANDLE | hFt | ) |
Stops the communication thread.
This function will stop the communication thread.
hFt | Handle of the Interface. |
References ft_handle_devices::t, ft_handle_devices::transfer_area, and _FT_TRANSFER_AREA::TransferAktiv.