How To Send Rs232 Commands

Posted : admin On 5/14/2019

Thanks in advance for your help. I'm writing a lightweight C# program to write lines to a serial port (sending commands to a PLC) for work, and I'm not a programmer. My problem is that my button won't send the line to the serial port. Here is my code:

Aug 31, 2006  For information about how to read from a serial port in an asynchronous manner in PowerShell V2, use the DataReceived event on the port object with the Register-ObjectEvent cmdlet. Jeffrey Snover [MSFT]. RS-232 Setup Instructions Communication Configuration Baud Rate 19,200bps Data Bits 8. Three pins need to be terminated: ground, send and receive (5, 3, and 2 respectively). Function Pin Pin Function No Connection 1 1 No Connection. Some programs will allow you to assign RS-232 strings to hot keys or buttons. Companies such as Crestron.

How To Send Rs232 Commands

What can I do to make the button1 click send the text line to the serial port? The code must be as simple as possible as this is only run on one workstation. I've looked at all the examples, but have been unable to adapt them to my code. I also don't want to blatantly rip off others' code to get it working. Any advice would be appreciated.

EDIT: The code above is not everything, for example I'm initializing the port properly. I have another section of code that properly receives and processes strings, it's just the sender I'm having problems with. I also created the button method using the form designer, so there should be no disconnect there.

TerrorTechTerrorTech

2 Answers

I would suggest:

Rahul's wedding night was the night where he was disowned, considered never in existence by Yash. Rahul leaves the very house where he considered a haven, for what his mother taught him to believe in. Kabhi khushi kabhie gham full synopsis.

  1. Use the Click event instead of the MouseClick event.

  2. If you just copied your button1_MouseClick method from an example somewhere that method probably isn't subscribed to the click event properly. If you double click the button in Visual Studio designer it will set up a method subscribed to the click event correctly for you automatically. That's where you would put your COM1.WriteLine(command);

  3. If both of those suggestions are incorrect, you should probably be getting an Exception thrown somewhere (unless you're opening an incorrect port). In that case, you should describe that error in your question here. Download mortal kombat 8 game.

Kevin StrickerKevin Stricker

It looks like you are not initializing your Com Port. You need to set your BaudRate, Parity, DataBits, StopBits and Handshake property's. Look at the above MSDN examples for guidence. You can set the property's individualy or set them in the constructor.

According to MSDN the Default values for the above propertys are:

  • BuadRate = 9600
  • Parity = Parity.None
  • DataBits = 8
  • StopBits = StopBits.One
  • HandShake = HandShake.None
Mark HallMark Hall

Not the answer you're looking for? Browse other questions tagged c#serial-port or ask your own question.