473,899 Members | 2,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

serial_port_RTS _pin_problem in C#

14 New Member
Hello,

I try to do a simple application in Winforms C# to read or write some data on serial port under win XP.I try to communicate with an industrial controller on RS485.So I have an converter RS232- RS485 The signal who does the converter control is RTS (switch RX or TX for RS485 half duplex)
My communication protocol is a version of old BitBus by Intel. When I want to sent something(eg. Address, command) I have to set the RTS line like:
//here the serial port is defined with baud rate, parity, etc.
byte[] command = new byte[1];
command[0] = 0x03;
port.Open();
port.RtsEnable = true;
port.Write(comm and, 0, 1);
port.RtsEnable = false;
// here shold begin to receive dataÖ
Now commes my problem: I need immediatley after I set RTS line to send data.
I looked with an digital scope to signals and I have an aprox 7mS time delay between the switching of RTS line and the actual data sending (write fuction).
Actually Iím trying to replace with the C# program an old driver writen in x86 ASM (witch cannot be runned under XP).Under the DOS driver I donít have any delay and because of this my C# communication is not working. How to syncronise RTS line with the write to port data in C#??
Any suggestions will be greatly appreciated.

Thanks in advance and all the best
Svcc.
Sep 10 '07 #1
27 11563
Plater
7,872 Recognized Expert Expert
Are you saying you NEED to delay or that your device does not work WITH a delay?
At any rate you should be able to just what you stated.
Open, set pin level, write data, set pin level.
Sep 10 '07 #2
svcc
14 New Member
Are you saying you NEED to delay or that your device does not work WITH a delay?
At any rate you should be able to just what you stated.
Open, set pin level, write data, set pin level.
Hello,

first thank you for answering,
I don't need any delay between the RTS pin set moment and
write data to port. The time interval between RTSenable=true and RTSenable=false
in my C# app is 20mS and in the original dos(driver) is 1.5mS. In this interval
I have to send the command.How can I mannage this in C#??
All the best
Sep 10 '07 #3
Plater
7,872 Recognized Expert Expert
Won't your device halt until the RTS pin is set low?
So when you say RTS=high.
The device goes "ok i'm gonna get something so i'll wait for it"
Then you can send your command whenever.
Then when you're done, you signify it with RTS=low?

What happens when you try and do it?

I've only done rs232 without flow control, so my knowledge is a bit limited
Sep 10 '07 #4
svcc
14 New Member
Won't your device halt until the RTS pin is set low?
So when you say RTS=high.
The device goes "ok i'm gonna get something so i'll wait for it"
Then you can send your command whenever.
Then when you're done, you signify it with RTS=low?

What happens when you try and do it?

I've only done rs232 without flow control, so my knowledge is a bit limited
Yes thatís the idea, Here the RTS pin is not used actually for handshaking on RS232 is used for controlling data flow in the RS232_RS485 converter.(this is common for many converters). My connection with the controller on RS485 is half duplex. So when RTS goes to 0 logic (positive voltage) then the converter go to transmit mode. When RTS goes to 1 logic (negative voltage) converter goes in receive mode.
So in the moment I change the RTS pin status to low I have to transmit command and once I finish I have immediately put RTS to high.(all this cycle is around 1.5ms) This is the figure with the Dos app. In C# I tried a very simple test: Change the RTS pin to low and then to high (2 successive instructions) On the scope this is happening in around 20ms. So itís not the fault of serial out buffer or something. Anyway I write only one byte. The cycle is too long for my equipment even if I send in this interval the correct command. The controller reply only in the case of dos diver. In the other case no reply, even I'm sure I send the same command(I checked with scope).Why I have this dead time between changing the RTS pin and writing to serial port the command. ??
Sorry for this long poetry and thanks for paying up attention to my problem.
Sep 10 '07 #5
Plater
7,872 Recognized Expert Expert
I really don't know, it could be some sort of overhead for using SerialPort in a managed code setting, or just something kooky.

You could try setting your SerialPort object to USE flow control? (you might be able to set it up automatically so that it sets the RTS pin high, writes the command then sets the RTS low when it's done)
That might make the cycle a little faster?
Sep 10 '07 #6
svcc
14 New Member
I really don't know, it could be some sort of overhead for using SerialPort in a managed code setting, or just something kooky.

You could try setting your SerialPort object to USE flow control? (you might be able to set it up automatically so that it sets the RTS pin high, writes the command then sets the RTS low when it's done)
That might make the cycle a little faster?

Itís a good idea and I try it but when I set handshaking on RTSpin and run the
program something really bad happens into win XP. I see the blue screen and computer is restarting!!??? ?
Sep 11 '07 #7
svcc
14 New Member
Last info: I tried with the serial port build in my docking station(COM1) and seems to be working
No delay and response from RS485 controller. Cold the problem be generated by the FTDI chip(inside my USB to RS232 converter??). My interest is to have communication possibility with newer computers only from USB. And also another point: If I buy a converter fromUSB
direct to RS485 how can I load the dll from the converter manufacturer (eg FTD2xx.dll) and use it in C#??. The dll cannot be loaded in Ďreferencesí as a regular .dll. The situation is more complicated. See the link http://www.ftdichip.co m/Projects/CodeExamples/CSharp.htm

all the best
Sep 11 '07 #8
Plater
7,872 Recognized Expert Expert
ahha! Yes FTDI chips are great and usefull but they're full of kooky stuff.
For any significant serialport communication you would be better off with a natural hardware one rathern then a USB converter.
(I pretty much only use mine for hyperterminal-standard in/out- and use my real serial port for programming and data control)

As for using their DLL that is something I looked breifly at, then detered into using it like a COM port again.
FTDI has some documentation on using it's API functions on its website that you may find usefull.
Sep 11 '07 #9
svcc
14 New Member
Sadly for me I have to focus on USB port, newer computers and especially laptops donít have any more serial ports. I donít have any information on this matter concerning other cip manufacturers(o thers than FTDI). I only tested 2 models of USB to RS232 converters having inside FTDI cips. Situation is frustrating because the ĎBitbusĎ protocol is pretty slow at 9600baud. Even so because of the delay I miss the controller answer that is comming in 2ms. If I buy an USB to RS485 converter then I get rid of the RTS pin story (RS232-RS485 converter) but the questions are: How I program it in C# (I canít use serial port class) ?? is anyone here tried the communication on RS485 in C#. It will be fast enough to switch efficient between TX and RX mode on RS485 in my case??
kind regards,

svcc
Sep 11 '07 #10

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.