C# Serial Port Rs-485

AcquiSuite uses Modbus over RS-485 serial to communicate with the various Modbus devices This type of converter draws power from the serial port.

Serial Programming/RS-485. From Wikibooks, Again many thought that the UART protocol used in the serial port were part of the RS-485 standard.

Electronics Control Projects. Search this site. Stephen Zahra. Home. Blog. Downloads. Contact Me. Sitemap. Notes Tutorials. Tutorials. C Serial Port.

How to send and recieve over rs-485 serial port?

ADONTEC offers comm port rs-232, rs-485 RS232, RS485 Multidrop, C, VB NET class NET-Framework Serial Communication Class Library. SerialPort compatible.

I m trying to communicate to a device using RS-485 through the serial port. Everything works fine, until we re trying to boost the communication to test the speed limit of the card then weird problem seem to occur. We are basically sending a first command with an image as arguments, and then another command to display this image. After every command, the card answers saying that the command was well received. But we are reaching limits too soon and the card is supposed to handle much more.

So I m wondering since the transmission and the reception are going through the same wire, if there is some sort of collision of data. And should I wait to receive all the data. Is the SerialDataReceivedEventHandler too slow of this situation and should I keep reading the bytes in a while true loop in seperate thread and signal other thread once a complete message is arrived.

We already have a protocol for communication : startdelimiter, data,

Sending in 2 commands is the way we do it and cannot be changed.

The engineer is still working on the program in the card so problem might also be on his end.

English is not my first language so feel free to ask if I was not clear :

I recognize SerialPort programming is not my strength, and I ve been trying to find some sort of wrapper but I haven t found any that would fit my needs. If someone has one to propose to me that d be great or maybe someone has an idea of what could be wrong.

Anyway here is a bit of coding :

timerLast Stopwatch.GetTimestamp ;

while . Paused conn.ClientConnState Connexion.ConnectionState.Connected

timerNow Stopwatch.GetTimestamp ;

if timerNow - timerLast / double Stopwatch.Frequency 1 / double fps

averageFPS.Add int double Stopwatch.Frequency / timerNow - timerLast 1 ;

if averageFPS.Count 10 averageFPS.RemoveAt 0 ;

conn.Write VIP16.bytesToVIP16 0x70C1, VIP16.Request.SendImage, toSend atFrame ;

conn.Write VIP16.bytesToVIP16 0x70C1, VIP16.Request.DisplayImage, VIP16.DisplayOnArg ;

So the WaitForResponse is crucial because if I send another command before the card answered it would go nuts. Although I hate to use Thread.Sleep because it is not very accurate plus it d limit my speed to 20fps, and if I use something lower than 25ms, risks of crash is much more likely to occur. So I was about to change the Thread.Sleep to Read bytes until whole message is received and ignore the DataReceivedEvent just wondering if I m completely off track here.

First Thank you Brad and 500 - Internal Server Error. But I ve decide to stick with the. NET Serial Port for now and improve the Thread.Sleep accuracy with timebeginperiod. I ve decided to wait for the full response to be received and I synchronized my threads like so using ManualResetEventSlim for speed :

public static ManualResetEventSlim _waitHandle new ManualResetEventSlim false ;

Then I changed SendColorIMage to :

conn.Write VIP16.bytesToVIP16 0x70C1, VIP16.Requetes.SendImage, toSend atFrame ;

conn.Write VIP16.bytesToVIP16 0x70C1, VIP16.Requetes.DisplayImage, VIP16.DisplayOnArg ;

Connexion._waitHandle.Wait 100 ;

With SerialDataReceivedEventHandler calling :

public void Recevoir object sender, SerialDataReceivedEventArgs e

byte byteMsg new byte sp.BytesToRead ;

sp.Read byteMsg, 0, byteMsg.Length ;

So I found out that after the second command I didn t need to call Thread.Sleep at all and after the first one I needed to sleep for at least 20ms for the card not to crash. So I guess it s the time the card needs to receive/process the whole image to it s pixel. AND collision of data shouldn t really occur since I wait until whole message has arrived which means the problem is not on my end. YES. :p.

c# - SerialPort RS-485 and communication limits

I want to communicate between my PC and some controller boards.

The expectation is that the PC will send an identifier of the board on RS-485 and then it should receive the answer from the board.

When I try to receive the response, I receive the wrong data.

SerialPort sp new SerialPort COM1 ;

byte id new byte 0,0,0,0,0,0,0,0,0,0 ;

It works if I am using RS-232, but not when I am using RS-485.

Serial Communication Library for Windows. Serial communication Library and serial component,RS232 comm port,rs485 Multidrop,asynchronous,autodownload with.

Simple Serial Communication Code for Microsoft Visual C Express. Simple Serial Communication with now includes a serial port class that eliminates.