Share via

Inputs Over a Com Port

Tammen 26 Reputation points
2022-11-11T00:41:19.317+00:00

Hi i am currently trying to make an application to access a device over a COM port but have run into some trouble to access the soft ware on the device the application needs to hit enter twice then input a password followed by hitting enter again this is the code i have so far. any suggestions would be appreciated thanks in advance.` static void Main()
{

        Port = new SerialPort();  
        Port.PortName = "COM21";  
        Port.BaudRate = 1200;  
        Port.DataBits = 8;  
        Port.Parity = Parity.None;  
        Port.StopBits = StopBits.One;  
        buoyPort.Open();  


        Port.Write(new byte[] { 13 }, 0, 1);  
        Thread.Sleep(250);  
        Port.Write(new byte[] { 13 }, 0, 1);  
        Thread.Sleep(250);  
        Port.Write("111047");  
        Thread.Sleep(250);  
        Port.Write(new byte[] { 13 }, 0, 1);`  
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Tammen 26 Reputation points
    2022-11-11T01:24:19.263+00:00

    Hi just thought i would share that i just found the solution to this problem what was happening is the information was being sent to fast and the firmware on the device wasn't reading it in time so i ended up splitting the 111047 into separate parts and had spaced out by about half a second. Port.Write(new byte[] { 13 }, 0, 1); Thread.Sleep(250); Port.Write(new byte[] { 13 }, 0, 1); Thread.Sleep(500); Port.Write("1"); Thread.Sleep(500); Port.Write("1"); Thread.Sleep(500); Port.Write("1"); Thread.Sleep(500); Port.Write("0"); Thread.Sleep(500); Port.Write("4"); Thread.Sleep(500); Port.Write("7"); Thread.Sleep(500); Port.Write(new byte[] { 13 }, 0, 1);

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.