C# / pseudo ethernet/tcp code example – Hatteland Display 26 inch - HD 26T21 MMC (Widescreen) User Manual

Page 42

Advertising
background image

42

IND100077-124

C# / Pseudo Ethernet/TCP Code example

{

// Create SCOM package

byte

[] cmd = enc.GetBytes(

"BRT"

);

byte

[] data =

new byte

[1] { 0x99 };

// 60% brightness

COMMessage

message =

new

COMMessage

(cmd, data);

// Transmitting SCOM package to TCP

SendTCPCommand(message);

}

private

Byte

[] SendTCPCommand(

COMMessage

commessage)

{

// Creating new TCPclient

TcpClient

tcpClient =

new

TcpClient

();

// Byte version of the SCOM package

byte

[] byteMessage = (

byte

[])commessage.Message.ToArray(

typeof

(

byte

));

//Display IP adresse

IPAddress

displayAddr =

IPAddress

.Parse(DisplayIPAddress);

Int32

port = 10001;

//constant

//Connecting

tcpClient.Connect(displayAddr, port);

// Create a stream from TCPClient

NetworkStream

stream = tcpClient.GetStream();

//Write the SCOM package into stream

stream.Write(byteMessage, 0, byteMessage.Length);


// Wait for response

Thread

.Sleep(GlobalWaitTime);

// Read Response

// To be compliant with SCOM package (ATTN, ADDR, CMD, CMD, CMD, LEN, IHCHK, DATA, IDCHK)

stream.Read(data, 0, data.Length);

}

Advertising