ts-7000
[Top] [All Lists]

[ts-7000] Help with RS485 on 7200?

To:
Subject: [ts-7000] Help with RS485 on 7200?
From: "whiffwaffle" <>
Date: Sun, 01 Jul 2007 03:23:18 -0000
I am having a heck of a time getting a simple Modbus command to work 
on the 7200. 

I can see the receive light flashing on the device, it just doesn't 
accept the command. I get no response at all.

The code I'm using is a stripped down version of the readmeter demo 
with some other changes I added while experimenting.

I'm using Modbus RTU devices (8-bit binary commands, not ASCII).

The device is set for 9600, N,8,1.

Here is the code I'm using:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include <unistd.h>

#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <assert.h>
#include <signal.h>

#include <time.h>

#include "ts_sbc.h"
#include "ioctls.h"

#define port485 "/dev/ttyAM1"
#define TIOC_SBCC485 _IOW('T',0x70,int) /*TS RTS/485 mode Clear*/
#define TIOC_SBCS485 _IOW('T',0x71, int) /*TS RTS/485 mode Set */

typedef unsigned char uchar;
typedef volatile unsigned char vuchar;

typedef uchar   bool;
#define TRUE    1
#define FALSE   0

int com;
struct termios options;

int openPort(char* port);
bool has485();
int init();
//-------------------------------------
bool has485(){
    uchar ccc;
    vuchar *chip;
    int fd;

    fd = open( "/dev/mem", O_RDWR );
    chip = (vuchar*)mmap( 0, getpagesize(), PROT_READ|PROT_WRITE,
                      MAP_SHARED, fd, 0x22c00000 );
    ccc = *chip;
    printf("mr=%d\n",ccc);

    chip = (vuchar*)mmap( 0, getpagesize(), PROT_READ|PROT_WRITE,
                                            MAP_SHARED, fd, 
0x22400000 );
    ccc = *chip;
    close( fd );
    return (ccc & 0x02) ? TRUE:FALSE;
}
//-------------------------------------
int openPort(char* port){
    int mcr;
    int err;
    
    if((com=open(port, O_RDWR | O_NOCTTY | O_NDELAY))!=-1){
        tcgetattr(com, &options);
        options.c_cflag=(CS8 | CLOCAL | CREAD);
        options.c_iflag=(IGNBRK | IGNPAR | IGNCR);
        options.c_oflag=OPOST;
        options.c_lflag=0;
        cfsetispeed(&options, B9600);
        cfsetospeed(&options, B9600);
        tcsetattr(com, TCSANOW, &options);

        tcflush( com, TCIFLUSH);
        
        printf("Setting mode    \n");
        mcr=AUTO485HD;  
        err=ioctl(com, TIOC_SBCS485, &mcr);
        if(err) 
            printf("err = %d\n", err);
    
        printf("Mode OK\n");
        return 0;
    }
    printf("OPEN FAILED!\n");
    return 1;
}
//-------------------------------------
int init(){
    if(has485())
        return openPort(port485);
    else
        return 1;
}
//-------------------------------------
int main(){
    int n,i;
    uchar buf[512];
    
    init();
//03/05/00/01/ff/00/dc/18   on
//03/05/00/01/00/00/9d/e8   off
    buf[0]=0x03;  //slave address 3
    buf[1]=0x05;  //force single coil
    buf[2]=0x00;  //coil #0001
    buf[3]=0x01;
    buf[4]=0xff;  //turn it ON (ff00)
    buf[5]=0x00;
    buf[6]=0xdc;  //crc hi
    buf[7]=0x18;  //crc lo
    for(n=0; n<10; n++){
        printf("\nWriting %d...\n",n);
        write( com, buf, 8);
        sleep(1);
    }
    sleep(1);
    memset(buf,0,512);
    read(com, buf, 512);   
    for(n=0;n<20;n++){
        printf("%d\n",buf[n]);
    }
    exit(0);
}

Any help would be greatly appreciated.



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ts-7000/join
    (Yahoo! ID required)

<*> To change settings via email:
     
    

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU