Page 1 of 1

Trouble with Read Module Type in C#

Posted: Fri Mar 28, 2014 8:35 am
by PaulBMO
When I execute this code (visual studio, C#):

//Read module type
commando[0] = 254;
commando[1] = 55;
port.Write(commando, 0, commando.Length);

int length = port.BytesToRead;
byte[] buf = new byte[length];
port.Read(buf, 0, length);
Console.WriteLine("Received data: " + buf);

I don't get the expected answer from the LCD.
Putting text on the screen and changing the font types etc, is no problem but receiving the Module type is./
What am I missing??

Re: Trouble with Read Module Type in C#

Posted: Fri Mar 28, 2014 10:37 am
by Tino
Hi Paul,

I assume you are getting something along the lines of 'System.Byte[]' being wrtten to your console.

Try this:

//Read module type
byte[] commando = new byte[2];
commando[0] = 254;
commando[1] = 55;
port.Write(commando, 0, commando.Length);

int length = port.BytesToRead;
byte[] buf = new byte[length];
port.Read(buf, 0, length);
Console.WriteLine("Received data: " + buf[0]);

Note the change I made above in red.
This should work for you. You will see the response written on the console.

If you have any other questions or concerns please feel free to ask.
Thank you for posting on your forums.
Martino

Re: Trouble with Read Module Type in C#

Posted: Tue Apr 01, 2014 2:56 am
by PaulBMO
Hi Martino,

Thanks for your reply.

The problem was that I had to wait 50 milliseconds for the display.
So I added this line:

comport.Write(commando2Bytes, 0, commando2Bytes.Length);
int milliseconds = 50;
Thread.Sleep(milliseconds);


regards
Paul

Re: Trouble with Read Module Type in C#

Posted: Tue Apr 01, 2014 8:10 am
by Tino
Hi Paul,

That's great that you found a solution.

Again thank you for posting on our forums.
If you have any other questions or concerns please feel free to ask.
Thank you
Martino