C# - Send ENQ, CR, LF to COM Port

Hello everybody.

Using this environment:
Windows, C#, Conveter USB/RS485.

How to send ENQ, ID, CR, LF to COM PORT using C#?

Thank's in advance,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You have to use SerialPort Class which is part of Namespace:  System.IO.Ports.

Basically you use Serial port Write-line method to send an string to it.

For example for CR  use write method with "\r"
For LF  use write method with "\n"

For a example take a look here:

ocaccyAuthor Commented:
Thank you.
I'm using C# with System.IO.Ports.
The manual device, tells us that we need to send this sequence, but without citing the language.
[ENQ, 3, 0, CR, LF]

[enquiry, ID, CR, LF] // "3,0" is the ID of device "30"

I use the code below and works with others devices.
 private void timer1_Tick(object sender, EventArgs e)
                string ID = "30";
                CommPort com = CommPort.Instance;
                ID = ConvertEscapeSequences(ID);

Open in new window

Thanks in advance,
Minh Võ CôngCommented:
Us Write method of SerialPort class of C#, you can fill ENQ, ID, CR, LF.. every thing you want to command and send it.

public void SendCommand(byte[] command)
        string chars = "";
        foreach (byte charbyte in command) chars += (char)charbyte;
        Console.WriteLine(" -> " + chars);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ocaccyAuthor Commented:
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.