Identifying multiple Sub-20s

All about Sub-20 Multi Interface USB Adapter USB to I2C, SPI, GPIO, RS232, RS485, Ir, LCD

Moderator: serg

Post Reply
soumajit
Posts: 12
Joined: Thu Feb 03, 2011 3:26 am

Identifying multiple Sub-20s

Post by soumajit »

My computer is connected to two or more sub-20 devices. One of the device is configured as master and the other in slave mode. We are doing SPI as well as GPIO transactions. How do I identify which device descriptor corresponds to which device. Please help

xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: Identifying multiple Sub-20s

Post by xol »

Each SUB-20 device has unique serial number.
To distinguish devices you need to use it's serial number:
http://www.xdimax.com/sub20/doc/HTML/su ... number.htm

Code: Select all

int sub_get_serial_number( sub_handle hndl, char *buf, int sz)
Will quire serial number of the device with given handle(descriptor)

soumajit
Posts: 12
Joined: Thu Feb 03, 2011 3:26 am

Re: Identifying multiple Sub-20s

Post by soumajit »

Thank you for the reply:):):)

soumajit
Posts: 12
Joined: Thu Feb 03, 2011 3:26 am

Re: Identifying multiple Sub-20s

Post by soumajit »

Hi,
I have two sub-20s connected to my computer. So I stored its serial number in a file and while running the program, I open the device and get its serial number and check it with the file, and if it is same continues, otherwise closes that device and continues searching for the next device. And I am running two instances of that program (lets call it pgm1 and pgm2), one for each sub-20. But there is some problem. If I run pgm1 first and then pgm2, there is no problem. But if I run pgm2 first and then pgm1, pgm1 is not able to open the device.
The code is given below

all necessary variables are initialised globally
//Function to open the SUB-20 device

int gpio_sub_dev_open()

{

dev = NULL;

int i=0;

char sn_buf[5];

int error_port;

sub_hnd = NULL;



while(dev = sub_find_devices( dev ))

{

sub_hnd = sub_open( dev );

if(!sub_hnd)

{

printf("ERROR: Cannot open handle to device\n" );

return -1;

}

rc = sub_get_serial_number( sub_hnd, sn_buf, sizeof(sn_buf) );

if(rc<0)

{

printf("ERROR: Cannot obtain serial number: %d\n", rc );

return -1;
}



if(strncmp(sn_buf,file_sub20_serial_num,strlen(file_sub20_serial_num)) == 0)

{

break;

}

else

{

sub_close(sub_hnd);


}



}




}


Please help:)

serg
Posts: 143
Joined: Mon Aug 31, 2009 9:17 pm

Re: Identifying multiple Sub-20s

Post by serg »

When pgm2 runs at first place it looks like it doesn't close the first device handle. Please send a compilable project, so we will be able to reproduce your issue and debug it.

Post Reply