• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 
April 16, 2024, 07:33:41 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,

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:
        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

Hello

Thank you for information.

Please try following initialization:


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:


        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

Hi Roman,

            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:
Quote000090: Write Request (DOWN), 20.04.2011 11:35:45.705 +3.883
Buffer size: 0x7 bytes


            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

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

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

Hi Roman,

just to let you know ... This works:
            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

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

Hi,

QuoteBut 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 ....

            do
            {
                Thread.Sleep(1);
            } while (nrComm1.SizeNotYetSent != 0);

This won´t work.

So have you a small example how to do that ?

Roman Novgorodov

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

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

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

April 22, 2011, 01:22:40 am #11 Last Edit: April 22, 2011, 01:27:13 am by moelski
Hi Roman,

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

Look at the data:
Quote000048: 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)

Roman Novgorodov

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

Hi !

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

Roman Novgorodov

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.