Error Code -201 when using ZKemKeeper.DLL - c#

I am creating a C# WinForm using ZKemKeeper.DLL to fetch data from a Biometric Device. But when I try connecting my App to the Device it always gives Error Code -201
Any Idea what could be causing this? I've read a guide document for ZKemKeeper.DLL but it doesn't list -201 as an error code. Any help would be much appreciated. Thank you.
private void btnConnect_Click(object sender, EventArgs e)
{
try
{
IsConnected = TimeKeeper.Connect_Net(txtIP.Text, 4370);
if (IsConnected == true)
{
MessageBox.Show("Device Connected Successfully.");
}
else
{
TimeKeeper.GetLastError(ref ErrorCode);
MessageBox.Show("Device Not Found. Error Code : " + ErrorCode.ToString(), "Error");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}

protected void btnConnect_Click(object sender, EventArgs e)
{
try
{
//this.Cursor = Cursors.WaitCursor;
//ShowStatusBar(string.Empty, true);
if (IsDeviceConnected)
{
IsDeviceConnected = false;
//this.Cursor = Cursors.Default;
return;
}
string ipAddress = txtIPAddress.Text.Trim();
string port = txtPort.Text.Trim();
if (ipAddress == string.Empty || port == string.Empty)
throw new Exception("The Device IP Address and Port is mandotory !!");
int portNumber = 4370;
if (!int.TryParse(port, out portNumber))
throw new Exception("Not a valid port number");
bool isValidIpA = UniversalStatic.ValidateIP(ipAddress);
if (!isValidIpA)
throw new Exception("The Device IP is invalid !!");
isValidIpA = UniversalStatic.PingTheDevice(ipAddress);
if (!isValidIpA)
throw new Exception("The device at " + ipAddress + ":" + port + " did not respond!!");
objZkeeper = new ZkemClient(RaiseDeviceEvent);
IsDeviceConnected = objZkeeper.Connect_Net(ipAddress, portNumber);
if (IsDeviceConnected)
{
string deviceInfo = manipulator.FetchDeviceInfo(objZkeeper, int.Parse(txtMachineNumber.Text.Trim()));
//lblDeviceInfo.Text = deviceInfo;
lblMessage.Text = deviceInfo + "is Connected";
}
}
catch (Exception ex)
{
throw(ex);
}
//this.Cursor = Cursors.Default;
}

Related

WFP all TextBlocks not updating

So my code was working just fine. But now, even though I can confirm the variables and strings are there through a Clipboard copy, the textblocks are not updating via TextBlock.Text. Did I turn something off? Every single one stopped doing it at the same time.
`private void actionPing_Click(object sender, RoutedEventArgs e)
{
try
{
Ping myPing = new Ping();
PingReply reply = myPing.Send(HostNameIPTyped.Text.ToString(), 500);
if (reply != null)
{
string tripTime = reply.RoundtripTime.ToString();
if (tripTime == "0")
{
PingStatus1.Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#660000"));
PingStatus1.Text = "Device not found"; <---NONE OF THESE ARE UPDATING ACROSS THE ENTIRE PROGRAM
}
else
{
PingStatus1.Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#17b05c"));
PingStatus1.Text = "Ping Successful, " + reply.RoundtripTime.ToString() + "ms roundtrip";
//// LET'S GET THE IP AND HOSTNAME OF WHATEVER THE HELL YOU PUT IN
////IPADDRESS
try
{
System.Net.IPAddress ip = System.Net.Dns.GetHostEntry(HostNameIPTyped.Text.ToString()).AddressList.Where(o => o.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).First();
ipAddress = ip.ToString();
}
catch (Exception ex)
{ }
////HOSTNAME
try
{
System.Net.IPHostEntry hostEntry = System.Net.Dns.GetHostEntry(ipAddress);
machineName = hostEntry.HostName;
string linkBuild = "http://" + machineName;
}
catch (Exception ex) { }
PingStatus1.Text += " " + machineName;
}
}
}
catch
{
{
PingStatus1.Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#660000"));
PingStatus1.Text = "Device not found";
}
}
}`
It was updating the fields. I had made an adjustment to the size of the grid which flattened all of the textblock fields to the left side. Once I drug them out they were no longer auto-sized.
Thanks for the help!

Arduino Led On/Off on Ethernet not working

I am trying to On/Off a led from desktop app on C# to Arduino using Ethernet (for serial port communication works), I am connecting to an IP Address to communicate with Arduino, but it looks something wrong with my code or my sketch for Arduino. (I am working with Ethernet shield)
my code Arduino
//////////INCLUDE HEADER FILES //////////////////
#include <Ethernet.h>
#include <SPI.h>
#include <EEPROM.h>
#include <LiquidCrystal.h>
#include <SD.h>
#include <Wire.h>
EthernetServer server(23 );
String content;
File myFile;
int ledPin = 7;
int outputpin = 0;
void setup()
{
IPAddress ip( 192, 168,1,110);
byte mac[] = {
0xDE,0xAE,0xBE,0xEF,0xFE,0xED
};
Ethernet.begin( mac, ip );
server.begin();
if ( ! SD.begin( 4 ) )
{
return;
}
Serial.begin(9600);
}
void loop()
{
waitIncommingConnection();
}
void waitIncommingConnection()
{
String pwd = "";
String inData = "";
EthernetClient client = server.available();
if ( client )
{
while ( client.connected() )
{
if ( client.available() > 0)
{
char recieved = client.read();
inData += recieved;
if (recieved == '\n')
{
switch( inData[0] )
{
case (char)'o' :
client.println("o");
digitalWrite(ledPin, HIGH);
break;
case (char)'f' :
client.println("f");
digitalWrite(ledPin, LOW);
break;
case (char)'*' :
Logout(client);
break;
default:
client.println('d');
break;
}
inData = "";
}
}
}
}
else
{
client.println('v');
}
}
void Logout(EthernetClient client )
{
client.print('x');
client.stop();
}
My C# code
public partial class Form1 : Form
{
public Client client;
public delegate void FeedBackCallback(string text);
public delegate void UpdateMessageBoxCallback(string text);
public Form1()
{
InitializeComponent();
}
private void connect_Click(object sender, EventArgs e)
{
string ipAddr = ip1.Text + "." + ip2.Text + "." + ip3.Text + "." + ip4.Text;
string port = portInput.Text;
if (IsValidIPAddress(ipAddr) == true)
{
try
{
if (client == null)
client = new Client(this);
client.Connect(ipAddr, port);
// client.Send(Encoding.GetEncoding(Constant.EncodingFormat).GetBytes("c"+'\n'));
disconect.Enabled = true;
connect.Enabled = false;
on.Enabled = true;
}
catch (SocketException se)
{
MessageBox.Show("Unable to Connect.\r\n" + se.ToString());
}
}
else
{
MessageBox.Show("Invaild Ip Adrress", "Invaild Ip Adrress", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private bool IsEmptyUserNamePasswordFields(string userName, string password)
{
if (userName.Length == 0 || password.Length == 0)
{
MessageBox.Show("Password and Username field is required!", "Required Fileds Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
else
{
return true;
}
}
private bool IsValidIPAddress(string ipaddr)//Validate the input IP address
{
try
{
IPAddress.Parse(ipaddr);
return true;
}
catch (Exception e)
{
return false;
}
}
private void on_Click(object sender, EventArgs e)
{
disconect.PerformClick();
connect.PerformClick();
try
{
if (client == null)
client = new Client(this);
client.Send(Encoding.GetEncoding(Constant.EncodingFormat).GetBytes("o" + '\n'));
off.Enabled = true;
on.Enabled = false;
}
catch (SocketException se)
{
MessageBox.Show("Unable to Connect.\r\n" + se.ToString());
}
}
private void off_Click(object sender, EventArgs e)
{
disconect.PerformClick();
connect.PerformClick();
try
{
if (client == null)
client = new Client(this);
client.Send(Encoding.GetEncoding(Constant.EncodingFormat).GetBytes("f" + '\n'));
on.Enabled = true;
off.Enabled = false;
}
catch (SocketException se)
{
MessageBox.Show("Unable to Connect.\r\n" + se.ToString());
}
}
private void disconect_Click(object sender, EventArgs e)
{
connect.Enabled = true;
disconect.Enabled = false;
client.Disconnect();
}
}
images for the Arduino
I don't know where is my problem, the app connect to the arduino, but the On/Off button not works for the led.
if u want to see the code foe serial port communication this is the link here, Serial Port

How to fix VS2013: Error: type or namespace 'Windows' could not be found?

I want to create a service for Wifi Direct. If I try to add Reference, I don't see core->windows option in VS2013. I have updated the winSDK.
How do I add the Windows.Devices.WifiDirect api ?
you can use
public sealed class WiFiDirectDevice : IDisposable
this is a sample code to handle connections
Windows.Devices.WiFiDirect.WiFiDirectDevice wfdDevice;
private async System.Threading.Tasks.Task<String> Connect(string deviceId)
{
string result = "";
try
{
// No device Id specified.
if (String.IsNullOrEmpty(deviceId)) { return "Please specify a Wi- Fi Direct device Id."; }
// Connect to the selected Wi-Fi Direct device.
wfdDevice = await Windows.Devices.WiFiDirect.WiFiDirectDevice.FromIdAsync(deviceId);
if (wfdDevice == null)
{
result = "Connection to " + deviceId + " failed.";
}
// Register for connection status change notification.
wfdDevice.ConnectionStatusChanged += new TypedEventHandler<Windows.Devices.WiFiDirect.WiFiDirectDevice, object>(OnConnectionChanged);
// Get the EndpointPair information.
var EndpointPairCollection = wfdDevice.GetConnectionEndpointPairs();
if (EndpointPairCollection.Count > 0)
{
var endpointPair = EndpointPairCollection[0];
result = "Local IP address " + endpointPair.LocalHostName.ToString() +
" connected to remote IP address " + endpointPair.RemoteHostName.ToString();
}
else
{
result = "Connection to " + deviceId + " failed.";
}
}
catch (Exception err)
{
// Handle error.
result = "Error occurred: " + err.Message;
}
return result;
}
private void OnConnectionChanged(object sender, object arg)
{
Windows.Devices.WiFiDirect.WiFiDirectConnectionStatus status =
(Windows.Devices.WiFiDirect.WiFiDirectConnectionStatus)arg;
if (status == Windows.Devices.WiFiDirect.WiFiDirectConnectionStatus.Connected)
{
// Connection successful.
}
else
{
// Disconnected.
Disconnect();
}
}
private void Disconnect()
{
if (wfdDevice != null)
{
wfdDevice.Dispose();
}
}

I keep getting an exception when Ping can't reach a host name C#

I'm trying to write something that picks up an input in a text box, then appends it with a prefix, then pings the two. Every time I run the script, if it cannot find the host name it gives me an exception. Is there any way I can force past the exception so that it goes onto the else statement? Or is there something simple that I'm missing?
public void button1_Click(object sender, EventArgs e)
{
if (String.IsNullOrWhiteSpace(textBox1.Text))
{
MessageBox.Show("Please enter an asset tag number.", "Dramatic failure", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
string assetTag = textBox1.Text;
Ping pingSender = new Ping();
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 1000;
PingOptions options = new PingOptions(64, true);
PingReply reply = pingSender.Send("WES0" + assetTag);
if (reply.Status == IPStatus.Success)
{
MessageBox.Show("The IP address is: ", "Great sucess!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
}
}
}
Catch the exeption with try / catch. Something like:
try
{
PingReply reply = pingSender.Send(nameOrAddress);
if (reply.Status == IPStatus.Success)
{
MessageBox.Show("The IP address is: ", "Great sucess!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
}
}
catch (PingException)
{
// Discard PingExceptions
}
The Ping class throws this exception to indicate that while sending an
Internet Control Message Protocol (ICMP) Echo request, a method called
by the Ping class threw an unhandled exception. Applications should
check the inner exception of a PingException object to identify the
problem.
The Ping class does not throw this exception if the ICMP Echo
request fails because of network, ICMP, or destination errors. For
such errors, the Ping class returns a PingReply object with the
relevant IPStatus value set in the Status property.
Find more information about the PingException here.
Try this:
public void button1_Click(object sender, EventArgs e)
{
if (String.IsNullOrWhiteSpace(textBox1.Text))
{
MessageBox.Show("Please enter an asset tag number.", "Dramatic failure", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
string assetTag = textBox1.Text;
Ping pingSender = new Ping();
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 1000;
PingOptions options = new PingOptions(64, true);
try
{
PingReply reply = pingSender.Send("WES0" + assetTag);
if (reply.Status == IPStatus.Success)
{
MessageBox.Show("The IP address is: ", "Great sucess!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
MessageBox.Show("Error on ping!", "Error on ping!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch(Exception ex)
{
MessageBox.Show("Error on ping:" + ex.Message, "Error on ping!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}

send data from .Net application to android app via network (socket programming)

I'm new in socket programming. I want to create an application for PC using C# and an application for android phones witch can communicate with other via wireless network(LAN).
For sending data to android app, I'm using this code in PC side:
private void sendButton_Click(object sender, EventArgs e)
{
try
{
Object objData = messageTextBox.Text;
byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString ());
_socket.Send (byData);
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_ipEndPoint = new IPEndPoint(IPAddress.Parse("192.168.1.18"), 2001);
_socket.Connect(_ipEndPoint);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
In android app, I want to receive data with this code:
Handler myUpdateHandler = new Handler()
{
public void handleMessage(Message msg)
{
Log.d(appTag, "setting textview");
TextView tv = (TextView) findViewById(R.id.messageText);
tv.setText(mClientMsg);
}
};
class CommsThread implements Runnable
{
public void run()
{
try
{
Socket s = null;
try
{
ss = new ServerSocket(2001);
}
catch (IOException e)
{
Log.d(appTag, e.toString());
}
while (!Thread.currentThread().isInterrupted())
{
Message m = new Message();
Log.d(appTag, "message m = new message()");
try
{
if (s == null) s = ss.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line = null;
while ((line = in.readLine()) != null)
{
Log.d(appTag, line);
mClientMsg = line;
}
myUpdateHandler.sendMessage(m);
}
catch (IOException e)
{
Log.d(appTag, e.toString());
}
}
}
catch (Exception e)
{
Log.d(appTag, e.toString());
}
}
}
But android application will not receive any data.
can anyone help me to solve my problem?
I'm very noob in socket programming.
sorry for bad english.
thanks.
If you update your reader to just read characters, and spit them out, what does it show? e.g.
try
{
if (s == null) s = ss.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
char[] recvd = new char[1];
while (in.read(recvd, 1, 1) != -1)
{
String line = new String(recvd);
Log.d(appTag, line);
mClientMsg = line;
}
myUpdateHandler.sendMessage(m);
}
catch (IOException e)
{
Log.d(appTag, e.toString());
}

Categories