ZKTeco, and how to connect to the device - c#

My efforts to connect to the ZKTeco device for access by key card goes unsuccessful for couple of days now. I am using .dll file that came with the device zkemkeeper.dll, add the reference in my simple .NET console API.
This my simple code.
static void Main(string[] args)
{
zkemkeeper.CZKEM machineObj = new zkemkeeper.CZKEM();
var status = machineObj.Connect_Net("Device IP", 4370);
Console.WriteLine(status);
Console.ReadLine();
}
As you can see its just Connect_Net("Device IP", 4370) that does all the work, but for some case I keep getting false for status value.
Can someone help, thank you.

The default IP address is 192.168.1.124
Are you able to ping successfully? If not check your network settings. Also note a crossover cable or switch is required.
Are you able to connect with the provided Access software?

Related

Get users current location

Have been working on WPF application where users current location had to be identified (it is configurable in settings = no anonymous tracking for private data). Several solutions has been tested.
Alternative number 1 - works fine on different computers, also with VPN is on. Location is tracked based on IP address and everything seems to be good. However downside of this is that it uses external sources, like third party websites for getting IP address and then read that IP address to get the location.
public string GetPublicIP()
{
String direction = string.Empty;
WebRequest request = WebRequest.Create("http://website/");
using (WebResponse response = request.GetResponse())
using (StreamReader stream = new StreamReader(response.GetResponseStream()))
{
direction = stream.ReadToEnd();
}
//Search for the ip in the html
// code here
return direction;
}
Alternative number 2 - C# Geolocator class. This works fine with additional JSON file with geolocation coordinates and location data. However on corporate computer PositionChanged event is not firing for some reason. Not sure is it blocked somehow. No exceptions, but location is not recognized due to event is not firing. On my personal computer same solution works fine (same Windows version - Windows 10). Geolocator.ReportInterval = 1000; is also not force firing event every 1 second.
private void RunGeoTracker()
{
if (Geolocator == null)
{
Geolocator = new Geolocator();
Geolocator.DesiredAccuracy = PositionAccuracy.High;
Geolocator.MovementThreshold = 100; // The units are meters.
Geolocator.ReportInterval = 1000;
Geolocator.PositionChanged += this.PositionChanged;
}
}
private async void PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
await Dispatcher.InvokeAsync(() =>
{
// code here
}
}
Are there are any alternatives, preferably without using any REST API or websites. Preferably using JSON or database for getting location data. I heard there is some PowerShell solution? Can't find examples. I mean basically Latitude and Longitude are needed. All the rest can be already achieved.
The Windows-native Geolocator API is limited by the wide variety of states a Windows laptop can be in - airplane mode, location settings disabled in common Windows settings, disabled in application-specific settings, or merely that no data providers are available to the OS (GPS satellites, WiFi triangulation, internet connectivity, OEM hardware and firmware etc.). So, any strategy to use OS-specific Geolocator API is contingent on your application (a) needing high-accuracy GPS fix, (b) involving mobility - e.g a worker driving with their open laptop in a car, or (c) ability to guide the user through UX that helps them get a location fix.
That said, do check if your Geolocator object initialization is done correctly via the steps in Microsoft's documentation - they matter!
IP geolocation has its limitations around VPN users, but it has much fewer ways of failing once you ship the software to real-world PCs and laptops. The following REST API for example will not only auto-detect the device's public IP but also respond with the approximate city-level location, including coarse latitude+longitude.
https://ep.api.getfastah.com/whereis/v1/json/auto?fastah-key=<trial_key>
The JSON response may look as follows, where the public IP is echoed back to your client application:
{
"ip": "146.75.209.1",
"isEuropeanUnion": false,
"locationData": {
"countryName": "Australia",
"countryCode": "AU",
"cityName": "Canberra",
"cityGeonamesId": 2172517,
"lat": -35.28,
"lng": 149.13,
"tz": "Australia/Sydney",
"continentCode": "OC"
}
}
The trick is to use IP location APIs that constantly update themselves as the internet and mobile landscape evolve fast.
Disclaimer: I am the developer of the above Fastah API service, so I may be a bit biased here :)

Read data via bluetooth using c#

I am using Lecia Disto e7100i which basically measures distance and area using laser. This device has bluetooth and can be paired with windows.
I am trying to develop an wpf app that reads the mesaured data using c#
There is no sdk that comes along with the device.
I have tried to use 32feet.Net but since there is no proper documentation I don't know where to start.
Is there any way that I can do to solve my problem?
This is not a full response, instead its more of a guideline on how to resolve your issue:
Pair the device with your Computer
Run the included software that displays the data somehow
Use WireShark to analyze the traffic
see if it is a standard protocol type or something custom
understand the protocol and reimplement it using c# and BluetoothSockets
To get started, you can try:
var client = new BluetoothClient();
// Select the bluetooth device
var dlg = new SelectBluetoothDeviceDialog();
DialogResult result = dlg.ShowDialog(this);
if (result != DialogResult.OK)
{
return;
}
BluetoothDeviceInfo device = dlg.SelectedDevice;
BluetoothAddress addr = device.DeviceAddress;
Console.WriteLine(device.DeviceName);
BluetoothSecurity.PairRequest(addr, "PIN"); // set the pin here or take user input
device.SetServiceState(BluetoothService.HumanInterfaceDevice, true);
Thread.Sleep(100); // Precautionary
if (device.InstalledServices.Length == 0)
{
// handle appropriately
}
client.Connect(addr, BluetoothService.HumanInterfaceDevice);
Also make sure that
Device appears in "Bluetooth devices" in the "Control panel".
Device is HID or change code accordingly.
Hope it helps. Cheers!
Try this demo project, and the following articles after that one.
Try to follow this tutorial
Here you can see a direct answer by the mantainer of 32feet, with which you can get in touch
Check also this answer

How to resolve the host / machine name with an IP address on windows phone

Anyone know if it can recover the ( hostname/machine name ) with a local IP address ? I know that the resolution reverse 'hostname -> ip' works perfectly with DeviceNetworkInformation.ResolveHostNameAsync (endpoint, OnNameResolved, null).
Is it possible to do the same thing but in reverse? Given the IP of a Local Machine and retrieve its hostname? A thousand thanks
Here is my code , but it's doesn't work the host is always called "192.168.1.5" like the ip . And it's should return "computer0001"
DeviceNetworkInformation.ResolveHostNameAsync("192.168.1.5", OnNameResolved, null);
private void OnNameResolved(NameResolutionResult result)
{
IPEndPoint[] endpoints = result.IPEndPoints;
if (endpoints != null)
{
if (endpoints.Length > 0)
{
//Host always return ip adress and not the machine name
host = endpoints[0].ToString();
}
}
}
Not sure if there is specific API on Windows Phone for that purpose.
I suggest you looking into similar question 'DNS lookup from custom DNS server in c#'.
If you're okay with going only WP8, then you should study this part of MSDN - Supported Win32 APIs for Windows Phone 8.
For example, getpeername function might return you information you're looking for. Or you might create new HostName object passing IP address there and trying to read DisplayName, CanonicalName or RawName properties of it.
Make sure you test with both emulator and real device as WP8 emulator has a little bit complex network configuration.
Would be great if you can update us if you have any success with the task.

C# - Windows Mobile - Pairing with Zebra RW 420

Update: This may not be "Pairing". This may just need to have a service started and bound to a port. However, this code is not storing it either. I need the device to be stored even after the application is closed.
I am building a program specifically suited for Zebra RW 420's on a Windows Mobile 6 Handheld device. The application needs to allow a mobile device to pair with the printer on COM1. I believe I am very close to getting it, but I can't get the pair request to work.
I am able to communicate with the printer and even print by directly connecting and printing, but I can't get the mobile device to actually pair with it. I've tried a variation of pins to include null, "1", "0000", and "1234". No matter what, the method always returns false. Any suggestions or ideas why this might be failing? I can pair the device just find in the WM6 Bluetooth menu, but not in my application.
It might be important to note that the little light bulb icon on the printer comes on when the program says it is attempting to pair, but after about 5 to 10 seconds, it fails.
BluetoothSecurity.PairRequest(device, "1"))
Additional Information:
I've successfully paired with my Android phone using this code.
I then logged in and set a PIN on the Zebra printer. However, this code still fails to pair with the printer even when I know the pin is correct / set in the printer.
From https://km.zebra.com/kb/index?page=answeropen&type=open&searchid=1336682809706&answerid=16777216&iqaction=5&url=https%3A%2F%2Fkm.zebra.com%2Fkb%2Findex%3Fpage%3Dcontent%26id%3DSO8031%26actp%3Dsearch%26viewlocale%3Den_US&highlightinfo=6292341,26,43#
Zebra Bluetooth enabled mobile printers are 'slave' devices only. The printers will pair with any 'master' device that tries to make a valid connection. Since only a master device can initiate a connection, the printer does not store pairing data, that function is always done on the master device. The printer can only be connected to one master device at a time, but any number of master devices that have stored pairing information for the printer would be able to initiate a connection to the printer without having to rediscover it.
I'm guessing that this means the InTheHand.Net BluetoothSecurity.PairRequest might not work for this type of pairing?
In the Bluetooth section of the WM handheld, under the "Devices" tab, I can add the device. I need to essentially do that. I need to register the device in that list and then set it to use COM 1 in the "COM Ports" section. The application I am using doesn't actually print. It's sole purpose is to prepare the printer for other applications.
The quote from Zebra make it sounds as pairing is actually not required at all. Are you printing from your app? If so just connect to the SPP service and send the text.
BluetoothAddress addr = ...
Guid serviceClass;
serviceClass = BluetoothService.SerialPort;
var ep = new BluetoothEndPoint(addr, serviceClass);
var cli = new BluetoothClient();
cli.Connect(ep);
Stream peerStream = cli.GetStream();
peerStream.Write ...
(From General Bluetooth Data Connections)
The Zebra Mobile Printer needed to be properly configured before pairing with this method will work. Here is what I did:
First, I ran the following commands on the printer:
.
! U1 setvar "bluetooth.authentication" "setpin"
! U1 getvar "bluetooth.authentication"
! U1 getvar "bluetooth.enable"
! U1 getvar "bluetooth.discoverable"
! U1 setvar "bluetooth.bluetooth_pin" "0000"
! U1 getvar "bluetooth.bluetooth_pin"
Then, the application with this code ran successfully.
.
int pair_req = 0;
try
{
if (BluetoothSecurity.SetPin(device, "0000")) {
while (status == false && pair_req < 3)
{
++pair_req;
status_box.Text = status_box.Text + '\n' + "Attempt " + pair_req.ToString();
status_box.Update();
if (BluetoothSecurity.PairRequest(device, "0000"))
{
status = true;
client.Refresh();
status_box.Text = "Paired Successfully.";
status_box.Update();
Thread.Sleep(5000);
}
else
{
status = false;
}
}
}
}
catch (ArgumentNullException e)
{
status_box.Text = "Pair failed.";
status_box.Update();
Thread.Sleep(5000);
}
status_box.Update();
Thread.Sleep(400);

Query printer status on my d-link print server

I have an d-link dp-311p print server which provides the printer status(offline, paper out, etc) on it's interface.
How can i get this oid status ?? i'm trying to find through axence nettools but there is A LOT of keys and the descriptions are not friendly...
Also, i'm trying to use this code(c#) to access the print server status but no success...
please, need a light, i'm completely lost!
Tks everyone
I did it! Here is how:
Search for mib browser because I didn't know the oid of the print server status. Found This one, then, I created a console app like this
OLEPRNLib.SNMP snmp = new OLEPRNLib.SNMP();
int Retries = 1;
int TimeoutInMS = 2000;
string CommunityString = "public";
string IPAddressOfPrinter = "192.168.1.12";
string ALLINEED;
// Open the SNMP connect to the print server
snmp.Open(IPAddressOfPrinter, CommunityString, Retries, TimeoutInMS);
ALLINEED = snmp.Get(".1.3.6.1.4.1.11.2.3.9.1.1.3.0");
snmp.Close();
Console.Write(ALLINEED);
On my machine I made a reference on the COM tab of the Add Reference dialog to “oleprn 1.0 Type Library“ which lived in “c:\Windows\System32\oleprn.dll“
Hope this can help someone.
Tks

Categories