aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTero Kontkanen <tero.kontkanen@granitedevices.fi>2017-08-19 17:05:51 +0300
committerTero Kontkanen <tero.kontkanen@granitedevices.fi>2017-08-19 17:34:34 +0300
commit6ef9e8c44e29d270c64c22b73ae00508966b4892 (patch)
treeda4561d6e961d0403689dc175ab288d8e127f134
parentd78fb3d4aac4ed7c28311a69ae86ffb88d03b972 (diff)
downloadSimpleMotionV2-6ef9e8c44e29d270c64c22b73ae00508966b4892.tar.gz
SimpleMotionV2-6ef9e8c44e29d270c64c22b73ae00508966b4892.zip
Add functions to list compatible bus device (ftdi d2xx only)
-rw-r--r--busdevice.c22
-rw-r--r--busdevice.h8
-rw-r--r--drivers/ftdi_d2xx/sm_d2xx.c65
-rw-r--r--drivers/ftdi_d2xx/sm_d2xx.h3
-rw-r--r--simplemotion.c33
-rw-r--r--simplemotion.h30
6 files changed, 157 insertions, 4 deletions
diff --git a/busdevice.c b/busdevice.c
index eff5ccc..85a5b0e 100644
--- a/busdevice.c
+++ b/busdevice.c
@@ -373,3 +373,25 @@ smbool smBDRead( const smbusdevicehandle handle, smuint8 *byte )
return smfalse;
}
+
+//BUS DEVICE INFO FETCH FUNCTIONS:
+
+//Return number of bus devices found. details of each device may be consequently fetched by smGetBusDeviceDetails()
+smint smBDGetNumberOfDetectedBuses()
+{
+ //only supports FTDI D2XX at the moment
+#ifdef FTDI_D2XX_SUPPORT
+ return d2xxGetNumberOfDetectedBuses();
+#endif
+ return 0;
+}
+
+smbool smBDGetBusDeviceDetails( smint index, SM_BUS_DEVICE_INFO *info )
+{
+ //only supports FTDI D2XX at the moment
+#ifdef FTDI_D2XX_SUPPORT
+ return d2xxGetBusDeviceDetails(index,info);
+#endif
+ return smfalse;
+
+}
diff --git a/busdevice.h b/busdevice.h
index 6a02a26..3cb4e24 100644
--- a/busdevice.h
+++ b/busdevice.h
@@ -31,5 +31,13 @@ smbool smBDTransmit(const smbusdevicehandle handle);
smbool smBDRead( const smbusdevicehandle handle , smuint8 *byte );
+//BUS DEVICE INFO FETCH FUNCTIONS:
+
+// Return number of bus devices found. details of each device may be consequently fetched by smBDGetBusDeviceDetails()
+smint smBDGetNumberOfDetectedBuses();
+
+//return smtrue if success
+smbool smBDGetBusDeviceDetails( smint index, SM_BUS_DEVICE_INFO *info );
+
#endif
diff --git a/drivers/ftdi_d2xx/sm_d2xx.c b/drivers/ftdi_d2xx/sm_d2xx.c
index 20c8405..db180de 100644
--- a/drivers/ftdi_d2xx/sm_d2xx.c
+++ b/drivers/ftdi_d2xx/sm_d2xx.c
@@ -11,13 +11,11 @@
#include "simplemotion_private.h" //needed for timeout variable
#include "drivers/ftdi_d2xx/ftd2xx.h"
#include <string.h>
+#include <simplemotion.h>
smbool handles_initialized=smfalse;
FT_HANDLE handles[MAX_OPEN_PORTS];//FT_HANDLE type is just a pointer
-#if defined(__unix__) || defined(__APPLE__)
-
-#else
static int stringToNumber( const char *str, smbool *ok )
{
@@ -180,4 +178,63 @@ void d2xxPortClose(smint32 serialport_handle)
}
-#endif//windows
+
+//BUS DEVICE INFO FETCH FUNCTIONS:
+
+//Return number of bus devices found. details of each device may be consequently fetched by smGetBusDeviceDetails()
+smint d2xxGetNumberOfDetectedBuses()
+{
+ FT_STATUS ftStatus;
+ DWORD numDevs;
+ // Get the number of devices currently connected
+ ftStatus = FT_ListDevices(&numDevs,NULL,FT_LIST_NUMBER_ONLY);
+ if (ftStatus == FT_OK)
+ {
+ return numDevs;
+ }
+ else
+ {
+ return 0;
+ }
+
+ return 0;
+}
+
+smbool d2xxGetBusDeviceDetails( smint index, SM_BUS_DEVICE_INFO *info )
+{
+ DWORD devIndex = index;
+ char description[64]; // more than enough room
+ FT_STATUS ftStatus = FT_ListDevices((PVOID)devIndex, description, FT_LIST_BY_INDEX|FT_OPEN_BY_DESCRIPTION);
+ if (ftStatus == FT_OK)
+ {
+ smbool compatible=smfalse;
+ if(strncmp(description,"TTL232R",7)==0
+ || strncmp(description,"SMV2USB",7)==0
+ || strncmp(description,"USB-SMV2",8)==0
+ || strncmp(description,"FT230X",6)==0
+ || strncmp(description,"IONICUBE",8)==0
+ || strncmp(description,"ATOMI",5)==0)
+ compatible=smtrue;
+
+ info->is_simplemotion_device=compatible;
+
+ if(compatible==smtrue)
+ {
+ sprintf(info->description,"SimpleMotion USB (%s)",description);
+ sprintf(info->device_name,"FTDI%d",index);
+ }
+ else//some unknown device with FTDI chip
+ {
+ sprintf(info->description,"Unknown FTDI device (%s)",description);
+ sprintf(info->device_name,"FTDI%d",index);
+ }
+ return smtrue;
+ }
+ else
+ {
+ return smfalse;
+ }
+
+ return smfalse;
+}
+
diff --git a/drivers/ftdi_d2xx/sm_d2xx.h b/drivers/ftdi_d2xx/sm_d2xx.h
index f8e8a1b..289ae8a 100644
--- a/drivers/ftdi_d2xx/sm_d2xx.h
+++ b/drivers/ftdi_d2xx/sm_d2xx.h
@@ -27,6 +27,9 @@ smint32 d2xxPortWriteByte(smint32 serialport_handle, unsigned char byte);
smint32 d2xxPortWriteBuffer(smint32 serialport_handle, unsigned char *buf, smint32 size);
void d2xxPortClose(smint32 serialport_handle);
+//Return number of bus devices found. details of each device may be consequently fetched by smGetBusDeviceDetails()
+smint d2xxGetNumberOfDetectedBuses();
+smbool d2xxGetBusDeviceDetails( smint index, SM_BUS_DEVICE_INFO *info );
#ifdef __cplusplus
}
diff --git a/simplemotion.c b/simplemotion.c
index 30220cf..45c7697 100644
--- a/simplemotion.c
+++ b/simplemotion.c
@@ -954,3 +954,36 @@ SM_STATUS resetCumulativeStatus( const smbus handle )
return SM_OK;
}
+
+/** Return number of bus devices found. details of each device may be consequently fetched by smGetBusDeviceDetails() */
+smint smGetNumberOfDetectedBuses()
+{
+ return smBDGetNumberOfDetectedBuses();
+}
+
+/** Fetch information of detected bus nodes at certain index. Example:
+
+ smint num=smGetNumberOfDetectedBuses();
+ for(int i=0;i<num;i++)
+ {
+ SM_BUS_DEVICE_INFO info;
+ SM_STATUS s=smGetBusDeviceDetails(i,&info);
+ if(s==SM_OK)
+ {
+ ...do something with info...
+ }
+ else
+ {
+ ...report error...
+ }
+ }
+*/
+LIB SM_STATUS smGetBusDeviceDetails( smint index, SM_BUS_DEVICE_INFO *info )
+{
+ smbool ok=smBDGetBusDeviceDetails(index,info);
+
+ if(ok==smtrue)
+ return SM_OK;
+ else
+ return SM_ERR_NODEVICE;
+}
diff --git a/simplemotion.h b/simplemotion.h
index c189af8..80db602 100644
--- a/simplemotion.h
+++ b/simplemotion.h
@@ -46,10 +46,18 @@ typedef int32_t smint32;
typedef int16_t smint16;
typedef int8_t smint8;
typedef int8_t smbool;
+typedef smint32 smint;
#define smtrue 1
#define smfalse 0
typedef int SM_STATUS;
typedef smuint8 smaddr;
+typedef struct
+{
+ smbool is_simplemotion_device;//smtrue if usable in SM lib
+ char device_name[64];//name that should be fed to smOpenBus
+ char description[128];//such as "SimpleMotion USB"
+} SM_BUS_DEVICE_INFO;
+
//comment out to disable, gives smaller & faster code
#define ENABLE_DEBUG_PRINTS
@@ -147,6 +155,28 @@ LIB SM_STATUS smGetBufferClock( const smbus handle, const smaddr targetaddr, smu
*content are application specific and defined . */
LIB SM_STATUS smFastUpdateCycle( smbus handle, smuint8 nodeAddress, smuint16 write1, smuint16 write2, smuint16 *read1, smuint16 *read2);
+/** Return number of bus devices found. details of each device may be consequently fetched by smGetBusDeviceDetails() */
+LIB smint smGetNumberOfDetectedBuses();
+
+/** Fetch information of detected bus nodes at certain index. Example:
+
+ smint num=smGetNumberOfDetectedBuses();
+ for(int i=0;i<num;i++)
+ {
+ SM_BUS_DEVICE_INFO info;
+ SM_STATUS s=smGetBusDeviceDetails(i,&info);
+ if(s==SM_OK)
+ {
+ ...do something with info...
+ }
+ else
+ {
+ ...report error...
+ }
+ }
+*/
+LIB SM_STATUS smGetBusDeviceDetails( smint index, SM_BUS_DEVICE_INFO *info );
+
#ifdef __cplusplus
}
#endif