Trouble with Read Module Type in C#

LK/ELK/VK/PK/OK/MX/GLK/EGLK/GVK/GLT Series

Moderators: Henry, Mods

Post Reply
PaulBMO
LCD!
Posts: 19
Joined: Fri Mar 28, 2014 8:28 am

Trouble with Read Module Type in C#

Post 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??
With kind regards,
Paul Joosten

BMO Offshore Measurements Systems BV
Rotterdam, the Netherlands

Tino
Matrix Orbital
Matrix Orbital
Posts: 158
Joined: Wed May 22, 2013 9:04 am
Location: Matrix Orbital

Re: Trouble with Read Module Type in C#

Post 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
Martino DeLeon
Matrix Orbital
Technical Support Representative

PaulBMO
LCD!
Posts: 19
Joined: Fri Mar 28, 2014 8:28 am

Re: Trouble with Read Module Type in C#

Post 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
Last edited by PaulBMO on Tue Apr 08, 2014 7:39 am, edited 1 time in total.
With kind regards,
Paul Joosten

BMO Offshore Measurements Systems BV
Rotterdam, the Netherlands

Tino
Matrix Orbital
Matrix Orbital
Posts: 158
Joined: Wed May 22, 2013 9:04 am
Location: Matrix Orbital

Re: Trouble with Read Module Type in C#

Post 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
Martino DeLeon
Matrix Orbital
Technical Support Representative

Post Reply