Page 1 of 1

Identifying multiple Sub-20s

Posted: Fri Mar 18, 2011 5:15 am
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

Re: Identifying multiple Sub-20s

Posted: Fri Mar 18, 2011 6:41 am
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)

Re: Identifying multiple Sub-20s

Posted: Fri Mar 18, 2011 8:47 am
by soumajit
Thank you for the reply:):):)

Re: Identifying multiple Sub-20s

Posted: Thu Apr 28, 2011 9:31 am
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:)

Re: Identifying multiple Sub-20s

Posted: Fri Apr 29, 2011 4:22 am
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.