• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 
April 19, 2024, 05:45:59 pm

News:

SMF - Just Installed!


RS485 Mode not working !

Started by moelski, April 20, 2011, 04:05:21 am

Previous topic - Next topic

moelski

Hi Roman,

Ok these are my settings:
            nrComm1.Protocol = StreamProtocol.None;
            nrComm1.RS485Mode = RS485Modes.DTRLow;
            nrComm1.Parity = Parity.Even;
            nrComm1.MonitorThreadMode = DataMonitorMode.Enable;
            nrComm1.Active = !nrComm1.Active;


And this is how I send data:
            byte[] buffer = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x54, 0x45, 0x53, 0x54, 0x64, 0x61, 0x74, 0x61, 0x21 };
            nrComm1.Write(buffer, 0, buffer.Length);


This works only if I first set / reset the DTR line. Otherwise there will no data send.

Maybe the startcondition is not correct for RS485 mode ?

Greetz Dominik

Roman Novgorodov

Hello

It depends on your connected device.
If it needs some special states of signal lines you need do it before transmission.
Other device can request other conditions for data transfer.

nrComm in RS485 changes line states only for send operations.

Roman Novgorodov
DeepSoftware.Com
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

moelski

Hi !

Even if I try this:
                        nrComm1.Active = !nrComm1.Active;
            Thread.Sleep(100);
            nrComm1.SetStateDTR(false);
            nrComm1.SetStateDTR(true);

it will not work.

Bus RS485 controller need DTR reset for sending (which means 3,3V at the DTR Pin). And DTR set (0V) for receiving.

If I use:
nrComm1.RS485Mode = RS485Modes.DTRLow;
nrcomm knows everything about my bus ... It´s controlled by DTR and I need DTR = reset (0) for sending data.


Oh I think I got the problem ...
I use this: nrComm1.RS485Mode = RS485Modes.DTRLow;

So my controlling line for Read / write is DTR. But look at my serial Monitor:
Quote4613287: I/O Request (DOWN), 24.04.2011 14:44:00.385 +23.885
IOCTL_SERIAL_CLR_RTS: Clear RTS
4613288: I/O Request (UP), 24.04.2011 14:44:00.385 +0.0
IOCTL_SERIAL_CLR_RTS: Clear RTS
4613289: Write Request (DOWN), 24.04.2011 14:44:00.385 +0.0
Buffer size: 0xd bytes
4613294: I/O Request (DOWN), 24.04.2011 14:44:00.386 +0.0
IOCTL_SERIAL_SET_RTS: Set RTS
4613295: I/O Request (UP), 24.04.2011 14:44:00.386 +0.0
IOCTL_SERIAL_SET_RTS: Set RTS


You still controlling RTS !!!!

That´s not so good  ???

moelski

Hi Roman,

there is another Problem with RS485 mode ...

I switch back from DTR to RTS to test the RS485Mode property with this code:
nrComm1.RS485Mode = RS485Modes.RTSLow;

And this for sending data:
byte[] buffer = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x54, 0x45, 0x53, 0x54, 0x64, 0x61, 0x74, 0x61, 0x21 };
nrComm1.Write(buffer, 0, buffer.Length);


It simple does not work. The timing is wrong. In my µController I got only a FFhex as result.

If I use a delay and controll the RTS line by myself all is fine:
        private void button1_Click(object sender, EventArgs e)
        {
            nrComm1.SetStateRTS(false);
            byte[] buffer = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x54, 0x45, 0x53, 0x54, 0x64, 0x61, 0x74, 0x61, 0x21 };
            nrComm1.Write(buffer, 0, buffer.Length);
        }

        private void nrComm1_OnDataSent(object sender, EventArgs e)
        {
            do
            {
                Thread.Sleep(40);
            } while (nrComm1.SizeNotYetSent != 0);
            nrComm1.SetStateRTS(true);
        }


So I think there are still 2 Problems with nrcomm and RS485 actually:
1) DTR is not handled correct (nrcomm uses RTS instead of DTR). -> see posting above
2) Timing is wrong in RS485Mode

Greetz
    Dominik

Roman Novgorodov

Hello Dominik

Thank you for your detail information.

Quote1) DTR is not handled correct (nrcomm uses RTS instead of DTR). -> see posting above


Yes, you are right. Fixed. I hope we will release new version asap.

Quote2) Timing is wrong in RS485Mode


We are using portmon for intercept serial port changes. It shows all correctly.
We will check more.

Roman Novgorodov
DeepSoftware.Com

DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

moelski

QuoteWe are using portmon for intercept serial port changes. It shows all correctly.

You are right. My serial monitor shows it also in a correct way.

But I think these tools din´t not show when the sendbuffer is empty. And if your serialport is still sending data you toggle the Read / write Pin. And then your data gets corrupted.
For sure in the monitor tool all looks nice. My HDD Device Monitor Studio also shows only successful sendings. But it´s not working correct because of the wrong timing.

Roman Novgorodov

Hello

The new nrComm NET v3.3.0.13 is available on our site.
Please try it.

Roman Novgorodov
DeepSoftware.Com
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

moelski

Hi Roman,

the new installer is 4MB smaller  :o
I will try it later.