Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Problems with ANTAP2DK1 on Linux 2.6.20

Rank

Total Posts: 1

Joined 2010-08-27

PM

I'm trying to write some software for an ANTAP2DK1 kit under Linux and I'm having some issues. I successfully added the vendor/product id to the cp2102 driver, and the usb stick is recognized when inserted into the system. I can open and write without and reported error, but I never receive a response from the ANT. Below is the code I'm using to set up the port. Can anyone tell me what I'm doing wrong?

static ant_t *ant_open(const char *dev)
{
    struct termios ios
;
    
ant_t *ant NULL;
    
int ifd;

    if (
== dev[0] || (fd open(devO_RDWR O_NOCTTY)) < 0)
        return 
NULL;

    if (!(
ant calloc(1sizeof(ant[0]))))
        return 
NULL;

    
ios.c_cflag B57600 CS8 CLOCAL CREAD;
    
ios.c_iflag IGNBRK IGNPAR;
    
ios.c_lflag 0;
    
ios.c_oflag 0;
    
ios.c_cc[VMIN] 1;
    
ios.c_cc[VTIME] 0;

    
// Not sure if necessary, but shouldn't hurt
    
cfsetispeed(&iosB57600);
    
cfsetospeed(&iosB57600);

    
tcsetattr(fdTCSANOW, &ios);

    
ioctl(fdTIOCMGET, &i);
    
|= TIOCM_RTS;
    
ioctl(fdTIOCMSET, &i);

    
ioctl(fdF_SETOWNgetpid());
    
    
ant->fd fd;

    return 
ant;
     
Avatar
RankRank

Total Posts: 40

Joined 2009-03-20

PM

Greetings fellow Linux user!

Here are two test programs that work (for me anyway, 2.6.32-21-generic #32-Ubuntu SMP Fri Apr 16 08:10:02 UTC 2010 i686 GNU/Linux)

The first one is a Python script which uses pyserial.

The second one is a C translation of the Python script.

(The C program is five times longer...)

See also quarqd/src/main.c, posted in the ANT+ achievers forum.

Regards,
Mark
.(JavaScript must be enabled to view this email address)
markrages@gmail      
Avatar
RankRank

Total Posts: 40

Joined 2009-03-20

PM

Greetings fellow Linux user!

Here are two test programs that work (for me anyway, 2.6.32-21-generic #32-Ubuntu SMP Fri Apr 16 08:10:02 UTC 2010 i686 GNU/Linux)

The first one is a Python script which uses pyserial.

The second one is a C translation of the Python script.

(The C program is five times longer...)

See also quarqd/src/main.c, posted in the ANT+ achievers forum.


EDIT: This forum is a nightmare. Did the file attach this time? I will paste them in as text...

Regards,
Mark
.(JavaScript must be enabled to view this email address)
markrages@gmail

[file name=test_ant.gz size=1333]http://www.thisisant.com/images/fbfiles/files/test_ant.gz[/file]

test_ant.py:
#!/usr/bin/python

import serialsystime

sp
=serial.Serial(sys.argv[1]baudrate=57600)

sp.setDTR(0); # remove from reset
time.sleep(0.5); # AP1 modules need time after reset before they hear serial
                 # AP2 modules have a startup message, wait for that instead

def send_message(msg):
    
message=[0xa4len(msg)-1] msg
    message
.append(reduce(lambda x,yx^ymessage)) # checksum
    
sp.write(''.join([chr(c) for c in message]))

ANT_Request_Message 0x4d
ANT_Capabilities 
0x54

send_message
([ANT_Request_Message0ANT_Capabilities])
sp.setTimeout(1)
print 
" ".join(["%02x"%ord(c) for c in sp.read(1000)]


test_ant.c:
#include <stdio.h>
#include <termios.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>

int ant_fd;

int setdtr (int on)
{
  int controlbits 
TIOCM_DTR;
  if(
on)
    return(
ioctl(ant_fdTIOCMBIS, &controlbits));
  else
    return(
ioctl(ant_fdTIOCMBIC, &controlbits));


void init_tty
(char *dev{
  struct termios tty_conf
;
  
  
ant_fd open(devO_RDWR O_NOCTTY );
  
  if(
ant_fd 0{
    fprintf
(stderr,"Error opening %s \\n"dev);
    
perror(dev);
    exit(
ant_fd);
  
}
  
  tcgetattr
(ant_fd, &tty_conf);
  
  
cfsetspeed(&tty_confB57600);  
  
cfmakeraw(&tty_conf);
  
  
// Set the new options for the port...
  
tcsetattr(ant_fdTCSANOW, &tty_conf);

  
setdtr(0);
}

char readchar
void {
  char c
;
  
read(ant_fd, &c1);
  return 
c;
}

char chksum
=0;

void writechar(char c{
  write
(ant_fd, &c1);
  
chksum ^= c;
}

void sendchk
void {
  writechar
(chksum);
  
// now chksum is zero
}

void send_message
(char *msgint len{
  int i
;

  
writechar(0xa4);
  
writechar(len);
  
  for (
i=0i<len+1i++) writechar(msg[i]);

  
sendchk();
}


void receive_message
(char bufferint *len{

  int i
;

  do 
{
    
*buffer=readchar();
  
while ((char)0xa4 != *buffer);
  
  *(++
buffer)=readchar(); // len

  
*len=1+1+1+*buffer+1// sync,id,len,data,chksum
  
  
for (i=1+*bufferi>0i--) {
    
*(++buffer)=readchar(); // id,data
  
}

  
*(++buffer)=readchar(); // chksum

}

int main
(int argcchar *argv[]{

  char buffer[100]
;
  
char *bp;
  
int len;

  if (
argc<2{
    fprintf
(stderr"Use like this: %s /dev/ttyUSBx\\n"argv[0]);
    exit(-
1);
  
}

  init_tty
(argv[1]);

  
sleep(1);
  
send_message("\\x4d\\x00\\x54"2);
    
  
receive_message(buffer, &len);
  
  
bp=buffer;
  while (--
len{
    printf
("%02X ",(unsigned char)*(bp++));
  
}
  printf
("\\n");
  
  return 
0;
     
Avatar
RankRank

Total Posts: 40

Joined 2009-03-20

PM

Also, I got the USB ids added to Linux 2.6.26 or later, so no kernel patching is required for the ANT dev kit.      
RankRankRankRank

Total Posts: 523

Joined 2012-11-15

PM

I reveived 2 ant usb key and i want test communation between them.

In Windows the software is easy to use.

But on Linux, i don't know use the key.

All tuto presents in thi forum ? Search dont give me à reponse.
Some body can help me ?      
RankRankRank

Total Posts: 95

Joined 2010-05-03

PM

Hi,

Unfortunately, we are not very familiar with Linux development and are unable to support this development. However, some of our users have been successful working with ANT on Linux. The following posts from our forum might be helpful:

http://www.thisisant.com/component/option,com_fireboard/Itemid,146/func,view/id,134/catid,25/#134

http://www.thisisant.com/component/option,com_fireboard/Itemid,146/func,view/id,799/catid,25/#799

http://www.thisisant.com/component/option,com_fireboard/Itemid,146/func,view/catid,25/id,812/