[prev in list] [next in list] [prev in thread] [next in thread] 

List:       rxtx
Subject:    [Rxtx] RE: 485 port
From:       Trent Jarvi <taj () undine ! linuxgrrls ! org>
Date:       2003-04-29 19:28:14
[Download RAW message or body]



On Tue, 29 Apr 2003, Ricardo Trindade wrote:

> Hi,
> 
> 	Regarding my recent issues with 485 without a converter, I found this email
> you sent me a while ago.
> 
> 	I found that the 485 port on my pc doesn't do any type of send data
> control, so it's not really the same as a converter. The port requires that
> the DTR or RTS (not sure wich or even if both) be raised before writes and
> droped after. In this situation I imagine such a port would require low
> level software support.

I'm a little confused here.  How do you know the port on your PC is RS485?
Its rather unusual to have on a PC.  It is possible to try making a RS232
port talk to an RS485 port.

What do you know about port?  Are you sure it isnt a RS232 UART?
I'm going to guess this is RS232 from what you have said.  Maybe you have 
a link to the specs of the product mentioned?

> 
> 	I have been trying to use it as a 232 port (just to test, didn't expect it
> to work), but of course doing the timing in java didn't work properly. I get
> readings from the driver, but most of the time the data has errors.
> 
> 	So my questions are :
> 
> 	-do you know if there is any support in linux/windows for 485 ?

Over time, people have hacked together solutions either in the kernel or 
in C libraries.  If you look at the RXTXImp.c you will see the code in 
write() that does this in userland.

It sounds like you have been bit by timing problems trying to do this from 
Java.  The native code can do it faster but from what I am able to gather, 
moving to userland C may not always work.

It may work.  You can just put the code to raise and lower the control 
lines right into SerialImp.c for testing.  I can help some there.

It may not work.  The suggested solution is to use a hardware converter.


> 	-do you think that the support in native rxtx lib will be "low level"
> enough to work properly ?

The kernel can be made to support this.  If you ask the kernel developers, 
they will suggest its not a priority.  You could also look at using real 
time linux.  Quickly, the converter looks like a more convenient solution.

> 	-is the fact that my pc reports a 232 port a consequence of me using
> /dev/tty ? is there another device for a 485 port ?

There may be some confusion here.  The RS485 classes are there for people 
that would like to modify them.  I think the code is essentially there but 
stopped working on them after digging through old serial and linux kernel 
mail lists.

So rxtx does not try to enumerate 'RS485' ports.  The intention of the 
classes was to make RS232 work like RS485.  You can see the hack here from 
RS485Imp.c

JNIEXPORT void JNICALL Java_gnu_io_RS485Port_writeByte( JNIEnv *env,
        jobject jobj, jint ji )
{
        unsigned char byte = (unsigned char)ji;
        int fd = get_java_var( env, jobj,"fd","I" );
        int result=0,count=0;

        /* turn on the DTR */
        ioctl(fd, TIOCMGET, &result);
        result |= TIOCM_DTR;
        ioctl(fd, TIOCMSET, &result);

        /* send the data */
	...
        /* shut down the DTR */
        ioctl(fd, TIOCMGET, &result);
        result &= ~TIOCM_DTR;
        ioctl(fd, TIOCMSET, &result);

This could easily be placed in SerialImp.c to try the 'low level' 
solution.  If you have a card that requires some low level call that
replaces the above automatically with DTR/RTS, that would be more of a 
kernel driver issue.  The kernel driver would then support an ioctl() call
to do that.

> 
> 	I've been trying to test the rxtx 485 code, but I can't use it because my
> os (linux) reports my 485 port as a 232 port, and rxtx only gives me a
> 485Port class if the os reports a 485 port (am I right on this ?)

If it truely is an RS485 port (on the PC side), the raising and lowering 
of control lines should just happen on write.  At least thats my 
understanding.

To keep things simple, I'd put the RS485 classes on the side for now and 
just look at the above change suggested for SerialImp.c.  See if you can 
get writeByte() to work.

I'll forward this to the rxtx mail-list.  Perhaps others will have 
comments that could help.

> 
> any ideas about this ?
> 
> hope to be able to work with you to provide adequate 485 support in rxtx.
> 
> -----Mensagem original-----
> De: Trent Jarvi [mailto:taj@hex.linuxgrrls.org]
> Enviada: quinta-feira, 3 de Abril de 2003 23:21
> Para: Ricardo Trindade
> Cc: Crucius, Wesley; rxtx@hex.linuxgrrls.org
> Assunto: RE: 485 port
> 
> 
> On Thu, 3 Apr 2003, Ricardo Trindade wrote:
> 
> > Thanks.
> >
> > I already use 232-485 converters that handle that themselves. I was
> guessing
> > that if advantech markets a 485 port, it would also do it, but I'm not
> sure
> > anymore...
> >
> > Ricardo
> >
> > -----Mensagem original-----
> > De: owner-rxtx@hex.linuxgrrls.org
> > [mailto:owner-rxtx@hex.linuxgrrls.org]Em nome de Crucius, Wesley
> > Enviada: quinta-feira, 3 de Abril de 2003 15:20
> > Para: 'Ricardo Trindade'; 'rxtx@hex.linuxgrrls.org'
> > Assunto: RE: 485 port
> >
> >
> > Ricardo,
> >
> > Don't know anything about that particular hardware, but the problem that
> > usually bites anyone using RS-485 hardware is transmitter enable.  If you
> > try to do it in software, you almost always have problems if you operate
> at
> > higher baud rates, and the definition of higher baud rates depends on your
> > hardware, your OS, and even your code.  Get an RS-485 board that does
> > hardware based transmitter enable and your life will be MUCH easier.
> Check
> > out the 7404 from www.sealevel.com as a very good example of this.  I've
> > used it extensively and have had very good results.
> >
> > Wes
> >
> 
> I think there is a little confusion.  Since this email is going on both on
> and off the list I'll try to answer the questions here.
> 
> Wes's idea is going to be the most foolproof.  It should work.  But it
> sounds like you have something like this so it should be fine.  If your
> rs232-485 converter is not working with rxtx Serial communication then the
> port is either not set up properly or there is a bug in rxtx.
> 
> If you remove the 485-232 converter, I'd not expect things to work too
> well but there is some (untested) code in rxtx that may work.  It will
> probably require modification.  If one wants to look into this I can help.
> You will need to use something like:
> 
> 	portId = (CommPortIdentifier) portList.nextElement();
> 		if (portId.getPortType() == CommPortIdentifier.PORT_RS485
> 		...
> 
> This class has native code that raises and drops DTR on writes.  In
> RS485Imp.c the code looks like:
> 
>         /* turn on the DTR */
>         ioctl(fd, TIOCMGET, &result);
>         result |= TIOCM_DTR;
>         ioctl(fd, TIOCMSET, &result);
> 
> 	..write data
> 
>         ioctl(fd, TIOCMGET, &result);
>         result &= ~TIOCM_DTR;
>         ioctl(fd, TIOCMSET, &result);
> 
> (these calls should work on w32 with the termios.c)
> 
> There will probably need to be other changes.  That was what I put in.
> 
> but for this to work properly, RXTXCommDriver.java will need to have the
> RS485 port type setup for enumeration here:
> 
> ~line 299
> for (int
> PortType=CommPortIdentifier.PORT_SERIAL;PortType<=CommPortIdentifier.PORT_PA
> RALLEL;PortType++)
> 
> 
> Finally, you could try using the PORT_SERIAL without the 485-232 converter
> and do the line control from Java but I suspect you will find the timing
> is not adequate.
> 
> If you are just trying to get RS485 working somehow, use the converter and
> us PORT_SERIAL.  Treat it as another 232 port.
> 
> 
_______________________________________________
Rxtx mailing list
Rxtx@linuxgrrls.org
http://undine.linuxgrrls.org/mailman/listinfo/rxtx
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic