Click here to Skip to main content
16,012,468 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I try to send hex data to a LCD monitor over TCP.But I could not send.
For exampla "32 00 01" is a test hex for monitor.
How can ı send it over tcp.
Thank you

I use this cod but itis not working
do you any other idea
thank you
        m_socClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
string szIPSelected  = txtIPAddress.Text;
String szPort = txtPort.Text;
int  alPort = System.Convert.ToInt16 (szPort,10);

System.Net.IPAddress    remoteIPAddress  = System.Net.IPAddress.Parse(szIPSelected);
System.Net.IPEndPoint   remoteEndPoint = new System.Net.IPEndPoint(remoteIPAddress, alPort);
m_socClient.Connect(remoteEndPoint);
        byte[] message = new byte[] { 32, 0, 1 };
        m_socClient.Send(message);


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 29-Mar-11 0:53am
v3

"Hex" is not something you send, it is just a way of looking at the numbers. For example, 112 is the same number as one hundred and twelve - they are just in different representations.

Instead, use bytes and send those (assuming it is Hex 32 you want to send):
byte start = 0x32;
byte middle = 0x00;
byte end = 0x01;
Now send those bytes and see if it works!

You can create them as an array and send that instead:
byte[] message = new byte[] { 0x32, 0x0, 0x1};



"I use this cod but itis not working
do you any other idea
thank you"



Look at your code, then look at my equivalent:
byte[] message = new byte[] { 32, 0, 1 };

byte[] message = new byte[] { 0x32, 0x0, 0x1};
The "0x" prefix says that the data to follow is Hexadecimal - i.e. base sixteen.
If you do not specify, then decimal is assumed - i.e. base 10.
32 Hex is 50 in decimal!

It's like saying that 112 is the same number as two hundred and seventy-four!
(112 in hexadecimal is 274 in decimal)
 
Share this answer
 
v2
Comments
Rajesh Anuhya 29-Mar-11 5:29am    
well explained.., Good one +5
sabridemirel 29-Mar-11 6:42am    
I use this cod but itis not working
do you any other idea
thank you

m_socClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
String szIPSelected = txtIPAddress.Text;
String szPort = txtPort.Text;
int alPort = System.Convert.ToInt16 (szPort,10);

System.Net.IPAddress remoteIPAddress = System.Net.IPAddress.Parse(szIPSelected);
System.Net.IPEndPoint remoteEndPoint = new System.Net.IPEndPoint(remoteIPAddress, alPort);
m_socClient.Connect(remoteEndPoint);
byte[] message = new byte[] { 32, 0, 1 };
m_socClient.Send(message);
OriginalGriff 29-Mar-11 6:57am    
Answer updated
sabridemirel 29-Mar-11 7:05am    
I changed the code and try again.
ı send the message like this
byte[] message = new byte[] { 0x32, 0x0, 0x1};
but its not working
thank you for your support but do you any other idea.
i have to do it
OriginalGriff 29-Mar-11 7:11am    
First, check you are in any form of communication with the device. Is there a way to make it talk to you? If so, then check if it is. If not, then you are down to the manual - is there a fragment which talks about communicating via TCP you could post (not the whole manual, please!)
use byte array to send the Hex data to the Hardware
byte[] mybyte = new byte[] { 32, 0, 1 };


use the above byte array to send data to the LCD Screen
 
Share this answer
 
Comments
sabridemirel 29-Mar-11 6:45am    
I use this cod but itis not working
do you any other idea
thank you

m_socClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
String szIPSelected = txtIPAddress.Text;
String szPort = txtPort.Text;
int alPort = System.Convert.ToInt16 (szPort,10);

System.Net.IPAddress remoteIPAddress = System.Net.IPAddress.Parse(szIPSelected);
System.Net.IPEndPoint remoteEndPoint = new System.Net.IPEndPoint(remoteIPAddress, alPort);
m_socClient.Connect(remoteEndPoint);
byte[] message = new byte[] { 32, 0, 1 };
m_socClient.Send(message);
Rajesh Anuhya 29-Mar-11 6:46am    
what is the Error Message your are Getting
sabridemirel 29-Mar-11 6:58am    
nothing,it seems working but nothing change onthe LCD monitor

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900