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

moelski

  • Full Member
  • ***
  • Posts: 122
    • View Profile
RS485 Mode not working !
« on: April 20, 2011, 07:05:21 am »
Hi Roman,

today i did a small test with the RS485 Mode. But I think this is not working.

But first some suggestions for RS485 Mode:
1) Please let the user choose if RTS has to be Set or Reset for Sending Data through the RS485.
I think this should be very easy to implement.
2) please let the user choose which Pin he uses for RS485 direction (you can have DTR and RTS !!).

And now me problem...
I use HHD Device monitor Studio to get information about the port activities. And I can´t see any changes for the RTS line:
000070: Create Request (DOWN), 20.04.2011 08:59:49.919 +66.772
Process 0x187c (nromm_RS485.vshost.exe) attempted to open the device
000071: Create Request (UP), 20.04.2011 08:59:50.084 +0.165
Process 0x187c (nromm_RS485.vshost.exe) create request status: 0x00000000
000072: I/O Request (DOWN), 20.04.2011 08:59:50.085 +0.001
IOCTL_SERIAL_SET_WAIT_MASK: Set current event mask
  WaitMask=RXCHAR: Any Character received, CTS: CTS changed state, DSR: DSR changed state, RLSD: RLSD changed state, BREAK: BREAK received, ERR: Line status error occurred, RING: Ring signal detected
000073: I/O Request (UP), 20.04.2011 08:59:50.085 +0.0
IOCTL_SERIAL_SET_WAIT_MASK: Set current event mask

000082: I/O Request (DOWN), 20.04.2011 08:59:50.086 +0.0
IOCTL_SERIAL_SET_BAUD_RATE: Set baud rate
  Baud Rate=9600
000083: I/O Request (UP), 20.04.2011 08:59:50.086 +0.0
IOCTL_SERIAL_SET_BAUD_RATE: Set baud rate

000084: I/O Request (DOWN), 20.04.2011 08:59:50.086 +0.0
IOCTL_SERIAL_SET_DTR: Set DTR

000085: I/O Request (UP), 20.04.2011 08:59:50.086 +0.0
IOCTL_SERIAL_SET_DTR: Set DTR

000086: I/O Request (DOWN), 20.04.2011 08:59:50.086 +0.0
IOCTL_SERIAL_SET_LINE_CONTROL: Set line control
  WordLength=8
  StopBits=1 stop bit
  Parity=Even parity
000087: I/O Request (UP), 20.04.2011 08:59:50.087 +0.0
IOCTL_SERIAL_SET_LINE_CONTROL: Set line control

000088: I/O Request (DOWN), 20.04.2011 08:59:50.087 +0.0
IOCTL_SERIAL_SET_CHARS: Set special characters
  EofChar=0x0
  ErrorChar=0x0
  BreakChar=0x0
  EventChar=0x0
  XonChar=0x0
  XoffChar=0x0
000089: I/O Request (UP), 20.04.2011 08:59:50.087 +0.0
IOCTL_SERIAL_SET_CHARS: Set special characters

000090: I/O Request (DOWN), 20.04.2011 08:59:50.087 +0.0
IOCTL_SERIAL_SET_HANDFLOW: Set handshake information
  ControlHandShake=2147483649
  FlowReplace=192
  XonLimit=0
  XoffLimit=0

000091: I/O Request (UP), 20.04.2011 08:59:50.087 +0.0
IOCTL_SERIAL_SET_HANDFLOW: Set handshake information

000092: I/O Request (DOWN), 20.04.2011 08:59:50.088 +0.0
IOCTL_SERIAL_SET_TIMEOUTS: Set timeouts
  ReadIntervalTimeout=0
  ReadTotalTimeoutMultiplier=0
  ReadTotalTimeoutConstant=0
  WriteTotalTimeoutMultiplier=0
  WriteTotalTimeoutConstant=0

000093: I/O Request (UP), 20.04.2011 08:59:50.088 +0.0
IOCTL_SERIAL_SET_TIMEOUTS: Set timeouts

000094: Write Request (DOWN), 20.04.2011 08:59:53.240 +3.151
Buffer size: 0x7 bytes


000096: Close Request (DOWN), 20.04.2011 08:59:57.276 +4.036
Buffer size: 0x0 bytes

000097: Close Request (UP), 20.04.2011 08:59:57.278 +0.002
Buffer size: 0x0 bytes
Status: 0x00000000


As you can see ... The data is send but there is nothing about SET RTS or Rest RTS ...

Could you please verify this?

My code is fairly simple:
Code: [Select]
        private void button1_Click(object sender, EventArgs e)
        {
            byte[] buffer = new byte[] { 0xAA, 0xBB, 0x01, 0xFF, 0x0C, 0x0A, 0x30 };
            nrComm1.Write(buffer, 0, buffer.Length);
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            nrComm1.Active = !nrComm1.Active;
        }

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: RS485 Mode not working !
« Reply #1 on: April 20, 2011, 08:57:48 am »
Hello

Thank you for information.

Please try following initialization:

Code: [Select]
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
            nrComm1.Protocol = StreamProtocol.None;
            nrComm1.RS485Mode = true;
            nrComm1.Active = !nrComm1.Active;
}

If it will not help, you can try use something  like this:

Code: [Select]
        private void button1_Click(object sender, EventArgs e)
        {
            byte[] buffer = new byte[] { 0xAA, 0xBB, 0x01, 0xFF, 0x0C, 0x0A, 0x30 };
            nrComm1.SetStateRTS(true);
            nrComm1.Write(buffer, 0, buffer.Length);
            nrComm1.SetStateRTS(false);
        }

We will check all and fix asap.

Roman Novgorodov
DeepSoftware
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 #2 on: April 20, 2011, 09:40:18 am »
Hi Roman,

Code: [Select]
            nrComm1.Protocol = StreamProtocol.None;
            nrComm1.RS485Mode = true;
            nrComm1.Active = !nrComm1.Active;
That makes no difference. No state changing at RTS. this is what I got while sending data:
Quote
000090: Write Request (DOWN), 20.04.2011 11:35:45.705 +3.883
Buffer size: 0x7 bytes

Code: [Select]
            nrComm1.SetStateRTS(true);
            nrComm1.Write(buffer, 0, buffer.Length);
            nrComm1.SetStateRTS(false);
Ok that is a solution. But I hope this will be done by nrcomm, soon  ;)

Anyway ... Did write return when all data is send or will write copy the data to the send buffer and return immediately?
Because I had a lot of trouble with the normal .NET serialPort Component.
Write returns to fast and not all data was send. At the end RTS was reset to fast and some data get lost.  :o

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: RS485 Mode not working !
« Reply #3 on: April 20, 2011, 09:51:31 am »
Hello

Thank you for quick feedback.

It seems like we need to change RTS state back in OnDataSent event handler.

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 #4 on: April 20, 2011, 09:56:03 am »
Hi !

Quote
It seems like we need to change RTS state back in OnDataSent event handler.
And set it befor sending.

And hopefully you can add the inverse functionallity, too.
(And the choice between RTS / DTR)  :)

moelski

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: RS485 Mode not working !
« Reply #5 on: April 21, 2011, 04:56:54 am »
Hi Roman,

just to let you know ... This works:
Code: [Select]
            nrComm1.SetStateDTR(false);
            byte[] buffer = new byte[] { 0x30, 0x31, 0x3E, 0x3F, 0x40, 0x41, 0x30 };
            nrComm1.Write(buffer, 0, buffer.Length);
            Thread.Sleep(100);
            nrComm1.SetStateDTR(true);
But if I delete the sleep it will not work !

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: RS485 Mode not working !
« Reply #6 on: April 21, 2011, 05:02:12 am »
Hello

Thank you for information.

Yes time delay can help.
But this delay can be various for different speeds (baud rate).
Best way is change signal line after output buffer is empty.

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 #7 on: April 21, 2011, 05:09:47 am »
Hi,

Quote
But this delay can be various for different speeds (baud rate).
Correct. It was only a test. The best way would be to use OnDataSend ... But see me new posting ....

Code: [Select]
            do
            {
                Thread.Sleep(1);
            } while (nrComm1.SizeNotYetSent != 0);
This won´t work.

So have you a small example how to do that ?

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: RS485 Mode not working !
« Reply #8 on: April 21, 2011, 12:41:57 pm »
Hello

Please download newest release 3.3.0.12
Now RS485Mode property has enum type and OnDataSend works more correctly.

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 #9 on: April 21, 2011, 12:49:24 pm »
Hi !

Ok I will try it later in the evening.
I can use the normal download link:
http://deepsoftware.ru/nrcommnet/nrcomm_net.zip ?

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: RS485 Mode not working !
« Reply #10 on: April 21, 2011, 12:51:21 pm »
Hello

Yes.
You can see build number in Version info of setup.exe

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 #11 on: April 22, 2011, 04:22:40 am »
Hi Roman,

the RS485 gets better. The enum is fine but there is still a problem ...

Look at the data:
Quote
000048: I/O Request (DOWN), 22.04.2011 06:17:48.287 +5.667
IOCTL_SERIAL_CLR_RTS: Clear RTS
000049: I/O Request (UP), 22.04.2011 06:17:48.287 +0.0
IOCTL_SERIAL_CLR_RTS: Clear RTS
000050: Write Request (DOWN), 22.04.2011 06:17:48.290 +0.003
Buffer size: 0xd bytes
000054: I/O Request (DOWN), 22.04.2011 06:18:00.501 +12.189
IOCTL_SERIAL_CLR_RTS: Clear RTS
000055: I/O Request (UP), 22.04.2011 06:18:00.501 +0.0
IOCTL_SERIAL_CLR_RTS: Clear RTS
000056: Write Request (DOWN), 22.04.2011 06:18:00.501 +0.0
Buffer size: 0xd bytes

As you can see there is a Clear RTS before sending. That´s ok because I set
nrComm1.RS485Mode = RS485Modes.DTRLow;

But there is no Set of RTS after that.

I meight be wrong but it should look like this:
* Reset RTS (in my case to enable writing to RS485)
* Send data
* Set RTS (Disable writing)
« Last Edit: April 22, 2011, 04:27:13 am by moelski »

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: RS485 Mode not working !
« Reply #12 on: April 24, 2011, 04:48:10 am »
Hello

Please check property MonitorThreadMode. It should be Enable or Auto.

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 #13 on: April 24, 2011, 06:18:03 am »
Hi !

It is set to Auto.
But maybe it is the same problem as with my OnSendData Posting ... ?

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: RS485 Mode not working !
« Reply #14 on: April 24, 2011, 06:20:40 am »
Hello

Please set it to Enable and try again.

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.