TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Chitresh Suman
1.5k
279
990
ESD (Electronic signature device) communication issue using socket
Dec 10 2020 1:06 AM
device not responding i.e I am unable to receive any response
public
void
GetStatus()
{
try
{
string
server =
"*********"
;
string
message;
Int32 port = ****;
TcpClient client =
new
TcpClient(server, port);
if
(client.Connected)
{
ushort
Head1 = 0x1a;
ushort
Head2 = 0x5d;
ushort
Command = 0x01;
ushort
l = 0x00;
ushort
l2 = 0x00;
ushort
l3 = 0x00;
ushort
l4 = 0x5f;
//byte[] vOut = BitConverter.GetBytes(l);
//byte[] vOut1 = BitConverter.GetBytes(l2);
//byte[] vOut2 = BitConverter.GetBytes(l3);
//byte[] vOut3 = BitConverter.GetBytes(l4);
//if (BitConverter.IsLittleEndian) Array.Reverse(vOut);
//var lvout = ToHex(vOut);
//if (BitConverter.IsLittleEndian) Array.Reverse(vOut1);
//var lvout1 = ToHex(vOut1);
//if (BitConverter.IsLittleEndian) Array.Reverse(vOut2);
//var lvout2 = ToHex(vOut2);
//if (BitConverter.IsLittleEndian) Array.Reverse(vOut3);
//var lvout3 = ToHex(vOut3);
string
len = l.ToString() + l2.ToString() + l3.ToString() + l4.ToString();
StringBuilder str3 =
new
StringBuilder();
foreach
(
ushort
item
in
table)
{
str3.Append(item);
}
// message = str3.ToString();
message = Head1.ToString() + Head2.ToString() + Command.ToString() + len + str3.ToString();
Byte[] crcbytes = Encoding.ASCII.GetBytes(message);
//var teststr = ToHex(crcbytes);
var calcCRC = ToHex(GetCrc(crcbytes));
ushort
crc = 0x1a;
ushort
crc1 = 0x0aa;
message = message + crc + crc1;
Byte[] data = Encoding.ASCII.GetBytes(ConvertToHex(message));
var final = ConvertToHex(message);
NetworkStream stream = client.GetStream();
// Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length);
Console.WriteLine(
"Sent: {0}"
, message);
// Receive the TcpServer.response.
if
(stream.CanRead)
{
byte
[] myReadBuffer =
new
byte
[1024];
StringBuilder myCompleteMessage =
new
StringBuilder();
int
numberOfBytesRead = 0;
// Incoming message may be larger than the buffer size.
do
{
numberOfBytesRead = stream.Read(myReadBuffer, 0, myReadBuffer.Length);
myCompleteMessage.AppendFormat(
"{0}"
, Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead));
}
while
(stream.DataAvailable);
// Print out the received message to the console.
Console.WriteLine(
"You received the following message : "
+
myCompleteMessage);
}
else
{
Console.WriteLine(
"Sorry. You cannot read from this NetworkStream."
);
}
stream.Close();
client.Close();
}
}
catch
(Exception)
{
throw
;
}
}
Reply
Answers (
1
)
Update doesnt work
simple way to export gridview as pdf?