Author Topic: RS485 Mode not working !  (Read 4878 times)

moelski

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: RS485 Mode not working !
« Reply #15 on: April 24, 2011, 12:17:42 pm »
Hi Roman,

Ok these are my settings:
Code: [Select]
            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:
Code: [Select]
            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

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: RS485 Mode not working !
« Reply #16 on: April 24, 2011, 12:32:09 pm »
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

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: RS485 Mode not working !
« Reply #17 on: April 24, 2011, 12:46:45 pm »
Hi !

Even if I try this:
Code: [Select]
                        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:
Code: [Select]
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:
Quote
4613287: 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

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: RS485 Mode not working !
« Reply #18 on: April 25, 2011, 01:37:20 am »
Hi Roman,

there is another Problem with RS485 mode ...

I switch back from DTR to RTS to test the RS485Mode property with this code:
Code: [Select]
nrComm1.RS485Mode = RS485Modes.RTSLow;
And this for sending data:
Code: [Select]
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:
Code: [Select]
        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

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: RS485 Mode not working !
« Reply #19 on: April 26, 2011, 09:24:49 am »
Hello Dominik

Thank you for your detail information.

Quote
1) 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.

Quote
2) 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

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: RS485 Mode not working !
« Reply #20 on: April 26, 2011, 09:31:06 am »
Quote
We 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

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: RS485 Mode not working !
« Reply #21 on: April 26, 2011, 05:04:11 pm »
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

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: RS485 Mode not working !
« Reply #22 on: April 26, 2011, 05:15:32 pm »
Hi Roman,

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