Why Join
Become a member
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
C# Corner Home
Technologies
MonthlyLeaders
ASK A QUESTION
Forumguidelines
george albert
0
8
0
having a problem with ZK SDK download -cannot get the whole log file
Oct 16 2020 11:40 AM
Dear Sir,
I am writing a windows service to get attendance log from attendance machine , I am using Visual Studio 2015
and I am working on windows 10 64 bit , the reference file name is ZKEUEmKeeperNet.dll version 1.0.0.0
runtime version v2.0.50727 actually I am facing 2 problems :
1- I am getting partial log : I mean not all punch transactions appear (I am taking this data to DB Oracle )!!!!
I tried I do not know why but I have removed the DB connection code and trying to write the data directly to harddisk using writetofile function
2- I am not getting the log file on harddisk this is not an SDK problem as I think this problem happened recently I do not know why!!
any suggestions for this problem or is the database connection with oracle caused a problem or the Onstart service time caused a problem I am running the service every 10 seconds and if I increased the time problems happen like if I make it every 100 seconds, please I need support it is taking too much time, thanks in advance
below is my code:
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Diagnostics;
using
System.Linq;
using
System.ServiceProcess;
using
System.Text;
using
System.Timers;
using
System.IO;
using
System.Threading.Tasks;
using
Oracle.ManagedDataAccess.Client;
using
Oracle.ManagedDataAccess;
namespace
Att_Service2
{
public
partial
class
Service1 : ServiceBase
{
ZkSoftwareEU.CZKEUEMNetClass axCZKEM1 =
new
ZkSoftwareEU.CZKEUEMNetClass();
private
bool
bIsConnected =
false
;
//the boolean value identifies whether the device is connected
private
int
iMachineNumber = 1;
//the serial number of the device.After connecting the device ,this value will be changed.
Timer timer =
new
Timer();
// name space(using System.Timers;)
string
sdwEnrollNumber =
""
;
int
idwTMachineNumber = 0;
int
idwEMachineNumber = 0;
int
idwVerifyMode = 0;
int
idwInOutMode = 0;
int
idwYear = 0;
int
idwMonth = 0;
int
idwDay = 0;
int
idwHour = 0;
int
idwMinute = 0;
int
idwSecond = 0;
int
idwWorkcode = 0;
int
idwErrorCode = 0;
int
iGLCount = 0;
int
iIndex = 0;
public
Service1()
{
InitializeComponent();
}
protected
override
void
OnStart(
string
[] args)
{
// WriteToFile("Service is started at " + DateTime.Now);
timer.Elapsed +=
new
ElapsedEventHandler(OnElapsedTime);
timer.Interval = 10000;
//10 seconds
timer.Enabled =
true
;
}
protected
override
void
OnStop()
{
// WriteToFile("Service is stopped at " + DateTime.Now);
}
public
void
WriteToFile(
string
Message)
{
string
path =
"D:\\Logs"
;
if
(!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//AppDomain.CurrentDomain.BaseDirectory +
string
filepath =
"D:\\Logs\\ServiceLog_"
+ DateTime.Now.Date.ToShortDateString().Replace(
'/'
,
'_'
) +
".txt"
;
if
(!File.Exists(filepath))
{
// Create a file to write to.
using
(StreamWriter sw = File.CreateText(filepath))
{
sw.WriteLine(Message);
}
}
else
{
using
(StreamWriter sw = File.AppendText(filepath))
{
sw.WriteLine(Message);
}
}
}
private
void
OnElapsedTime(
object
source, ElapsedEventArgs e)
{
ZkSoftwareEU.CZKEUEMNetClass axCZKEM1 =
new
ZkSoftwareEU.CZKEUEMNetClass();
string
TNS;
string
IP;
//data in file should be like
//DATA SOURCE = 192.168.2.240:1521 / ORCL; USER ID = XXXXX; Password = YYYYY-192.168.2.74-
string
totalData = File.ReadAllText(@
"c:\Data\Att1.txt"
);
//read information for attendance Machine1
try
{
int
index = totalData.IndexOf(
"-"
);
int
lastindex = totalData.LastIndexOf(
"-"
);
int
IPlength = lastindex - index - 1;
TNS = totalData.Substring(0, index).ToString().Trim();
IP = totalData.Substring(index + 1, IPlength).ToString().Trim();
}
catch
(Exception ex) { WriteToFile(
"No file exist or revise the format to be like DATA SOURCE = 192.168.2.240:1521 / ORCL; USER ID = ASCON; Password = ASCON-192.168.2.74- the file path is c:\\data\\Att1.txt"
);
return
;}
/////////////////////////////////////////////////////////////////////////////////////
string
sdwEnrollNumber =
""
;
int
idwTMachineNumber = 0;
int
idwEMachineNumber = 0;
int
idwVerifyMode = 0;
int
idwInOutMode = 0;
int
idwYear = 0;
int
idwMonth = 0;
int
idwDay = 0;
int
idwHour = 0;
int
idwMinute = 0;
int
idwSecond = 0;
int
idwWorkcode = 0;
int
idwErrorCode = 0;
int
iGLCount = 0;
int
iIndex = 0;
int
Port = 4370;
bool
bIsConnected;
int
iMachineNumber = 1;
string
insertSQL;
//3- Get Data From Attandance Machine
try
{
while
(axCZKEM1.Connect_Net(IP, Port) !=
true
) ;
//****New check connection TCP
WriteToFile(
"Connected to attendance "
+DateTime.Now.ToString());
axCZKEM1.EnableDevice(iMachineNumber,
false
);
//disable the device today
WriteToFile(
"Device Disabled "
+ DateTime.Now.ToString());
while
(axCZKEM1.ReadGeneralLogData(iMachineNumber) !=
true
) ;
//**New i added a loop instead of if
WriteToFile(
"Begin Loop "
+ DateTime.Now.ToString());
while
(axCZKEM1.SSR_GetGeneralLogData(iMachineNumber,
ref
sdwEnrollNumber,
ref
idwVerifyMode,
ref
idwInOutMode,
ref
idwYear,
ref
idwMonth,
ref
idwDay,
ref
idwHour,
ref
idwMinute,
ref
idwSecond,
ref
idwWorkcode))
//get records from the memory
{
// //insert into Oracle DB
DateTime Date = Convert.ToDateTime(idwYear.ToString() +
"-"
+ idwMonth.ToString() +
"-"
+ idwDay.ToString() +
" "
+ idwHour.ToString() +
":"
+ idwMinute.ToString() +
":"
+ idwSecond.ToString());
// WriteToFile(Date);
//MessageBox.Show(iMachineNumber + "-" + sdwEnrollNumber + "-" + Date);
/*Commented on 18-7-2020
WriteToFile(iMachineNumber+
"-"
+ sdwEnrollNumber+
"-"
+ idwInOutMode+
"-"
+ Date);
*/
// MessageBox.Show("inserted Successfully");
}
//end while
}
//end try
catch
(Exception ex)
{
WriteToFile(
"error "
+ ex.ToString()+
" at "
+DateTime.Now.ToString() );
}
//today
}
//end function
}
//end class
}
//end namespace
Reply
Answers (
0
)
How do you change registry settings to enable devices attached to USB
Powershell, help with incrementing inside foreach and scriptblock