|
code is
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using RfidApiLib;
using System.IO;
using System.Data.SqlClient;
using System.Threading;
namespace Service_Ambu_Exit
{
public partial class Form1 : Form
{
RfidApi api = new RfidApi();
public int TagCnt = 0;
string ip;
string portNo;
string p_type = "";
string p1 = "";
string arr1;
int intcount = 0;
public Form1()
{
InitializeComponent();
}
private int connectReader()
{
try
{
StreamReader sr1 = new StreamReader("ipandport.txt");
string[] str2;
string[] str3;
string arr3;
arr3 = sr1.ReadLine();
str2 = arr3.Split('=');
ip = str2[1].Trim();
StreamReader sr3 = new StreamReader("ipandport.txt");
string arr2;
arr2 = sr3.ReadLine();
arr2 = sr3.ReadLine();
str3 = arr2.Split('=');
portNo = str3[1].Trim();
int status;
int port;
string s = "";
try
{
port = int.Parse(portNo);
s = ip;
}
catch (Exception)
{
logfile("Please mention the valid ip address and port in settings file.");
return 0;
}
status = api.TcpConnectReader(ip, port);
if (status != 0)
{
logfile("Connect Reader Failed.");
return 0;
}
if (ip == "172.16.100.3".Trim() || ip == "172.16.100.4".Trim())
{
p1 = "STAFF".Trim();
}
else if (ip == "172.16.100.5".Trim() || ip == "172.16.100.7".Trim() || ip == "172.16.100.6".Trim())
{
p1 = "AMBULANCE".Trim();
}
else if (ip == "172.16.100.2".Trim() || ip == "172.16.100.1".Trim())
{
p1 = "BASEMENT".Trim();
}
StreamReader sr = new StreamReader("RFSettings.txt");
string[] str1;
string arr;
arr = sr.ReadLine();
str1 = arr.Split(':');
arr1 = str1[1].Trim();
}
catch (Exception e)
{
logfile(e.Message.ToString());
} return 1;
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
int i = 0;
while (i == 0)
{
i = connectReader();
// Thread.Sleep(2000);
}
logfile("Reader Connected.");
timer1.Start();
//timer2.Start();
}
catch (Exception e1)
{
logfile(e1.Message.ToString());
}
}
private void logfile(string str)
{
try
{
string month = string.Format("{0:MM}", DateTime.Now);
string year = string.Format("{0:yyyy}", DateTime.Now);
if (Directory.Exists("log/" + year + ""))
{
}
else
{
Directory.CreateDirectory("log/" + year + "");
}
if (Directory.Exists("log/" + year + "/" + month + ""))
{
}
else
{
Directory.CreateDirectory("log/" + year + "/" + month + "");
}
if (Directory.Exists("log/" + year + "/" + month + ""))
{
StreamWriter sw; //= new StreamWriter("log/" + year + "/" + month + "/RFlog.txt");
if (File.Exists("log/" + year + "/" + month + "/RFlog.txt"))
{
string str2 = DateTime.Now.ToString() + " " + str;
sw = File.AppendText("log/" + year + "/" + month + "/RFlog.txt");
sw.WriteLine(str2);
sw.Close();
}
else
{
sw = File.CreateText("log/" + year + "/" + month + "/RFlog.txt");
string str1 = DateTime.Now.ToString() + " " + str;
sw.WriteLine(str1);
sw.Close();
}
}
}
catch (Exception e)
{
}
}
private void check_status()
{
try
{
SqlConnection con = new SqlConnection(arr1);
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandText = "EXEC TAG_ZONE_STATUS_DEMO";
SqlDataAdapter da = new SqlDataAdapter(com);
DataTable dt = new DataTable();
da.Fill(dt);
SqlCommand com1 = new SqlCommand();
com1.Connection = con;
com1.CommandText = "select * from temp_tbl";
SqlDataAdapter da1 = new SqlDataAdapter(com1);
DataSet ds = new DataSet();
da1.Fill(ds);
if (ds.Tables[0].Rows[0][0].ToString() == "ALLOW")
{
if (p1 == p_type)
{
SqlCommand com2 = new SqlCommand();
com2.Connection = con;
com2.CommandText = "UPDATE tbl_tag_reader_master SET FLAG = 1 WHERE TAG_ID = '" + ds.Tables[0].Rows[0]["TAG_ID"] + "'";
con.Open();
com2.ExecuteNonQuery();
con.Close();
api.SetOutPort(0, 0);
Thread.Sleep(2000);
api.SetOutPort(0, 1);
}
}
}
catch (Exception ex)
{
logfile(ex.Message.ToString());
int i = 0;
while (i == 0)
{
i = connectReader();
// Thread.Sleep(2000);
}
logfile("Reader Connected.Out Cmd");
timer1.Start();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
intcount = intcount + 1;
api.ClearIdBuf();
int status;
byte tag_cnt = 0;
int i, j;
byte[,] isobuf = new byte[100, 12];
string s = "";
string s1 = "";
string[] s2 = null;
string s3;
byte tagflag = 0;
DateTime dt;
dt = DateTime.Now;
string dt1 = dt.ToString("yyyy-MM-dd HH:mm:ss");
status = api.EpcMultiTagIdentify(ref isobuf, ref tag_cnt, ref tagflag);
if (status != 0)
{
DllNotFoundException dl = new DllNotFoundException();
throw dl;
}
else if (tag_cnt > 0)
{
for (i = 0; i < tag_cnt; i++)
{
s1 = string.Format("NO.{0 }: ", TagCnt);
for (j = 0; j < 12; j++)
{
s = string.Format("{0:X2}", isobuf[i, j]);
s1 += s;
}
s2 = s1.Split(':');
s3 = DateTime.Now.ToString();
SqlConnection con1 = new SqlConnection(arr1);
SqlCommand com1 = new SqlCommand();
com1.Connection = con1;
com1.CommandText = "select count(*) from TBL_VEHICLE_OWNER_PERMISSION_MASTER where TAG_UID='" + s2[1].Trim() + "'";
SqlDataAdapter da23 = new SqlDataAdapter(com1);
DataTable dt23 = new DataTable();
da23.Fill(dt23);
int c23 = Int32.Parse(dt23.Rows[0][0].ToString());
if (c23 > 0)
{
SqlCommand com2 = new SqlCommand();
com2.Connection = con1;
com2.CommandText = "select PARKING_TYPE from TBL_VEHICLE_OWNER_PERMISSION_MASTER where TAG_UID='" + s2[1].Trim() + "'";
SqlDataAdapter da24 = new SqlDataAdapter(com2);
DataTable dt24 = new DataTable();
da24.Fill(dt24);
p_type = dt24.Rows[0][0].ToString();
}
else
{
p_type = "";
}
SqlCommand com;
com = new SqlCommand();
com.Connection = con1;
com.CommandText = "select * from tbl_tag_reader_master where tag_id='" + s2[1].Trim() + "' and datediff(second,timetag,'" + dt1 + "')<8";
DataTable dt12 = new DataTable();
SqlDataAdapter da12 = new SqlDataAdapter(com);
da12.Fill(dt12);
if (dt12.Rows.Count > 0)
{
}
else
{
com = new SqlCommand();
com.Connection = con1;
com.CommandText = "insert into tbl_tag_reader_master values('" + ip + "','" + s2[1].Trim() + "','" + System.DateTime.Now.ToString() + "','" + null + "','" + null + "','" + null + "','" + null + "','" + null + "','" + null + "')";
con1.Open();
com.ExecuteNonQuery();
con1.Close();
check_status();
TagCnt++;
}
}
}
if (intcount > 1800)
{
timercount2();
intcount = 0;
}
timer1.Start();
}
catch (DllNotFoundException d1)
{
logfile("Connection Broken. Reattempting Connection...");
int i = 0;
while (i == 0)
{
i = connectReader();
// Thread.Sleep(2000);
}
logfile("Reader Connected.Timer");
timer1.Start();
}
catch (Exception e1)
{
logfile(e1.Message.ToString());
int i = 0;
while (i == 0)
{
i = connectReader();
// Thread.Sleep(2000);
}
logfile("Reader Connected.Timer");
}
}
private void timer2_Tick(object sender, EventArgs e)
{
}
private void timercount2()
{
try
{
api.TcpCloseConnect();
int i = 0;
while (i == 0)
{
i = connectReader();
//Thread.Sleep(2000);
}
logfile("Reader Connected.Timer2");
}
catch (Exception e1)
{
logfile(e1.Message.ToString());
int i = 0;
while (i == 0)
{
i = connectReader();
//Thread.Sleep(2000);
}
logfile("Reader Connected.Timer2");
}
}
}
}
|
|
|
|
|
1. You should use <pre> or <code> tag to format code properly.
2. You should debug your application and try find the problem yourself. You just wrote some code, it doesn't work, so you think someone on the internet will fix it for you?
3. Connected to number 2 - you should tell us more specifically, what the problem is. "application hang" in the subject isn't telling us to much. You think we will run your code and check, where does it hang? We won't. Firstly you only gave us part of the code ("code-behind" of your form), and we don't know what controls you have on this form. Secondly, it's your job to locate the problem, and then we can tell you how to fix it. And if you can't locate the problem, than you should find at least a piece of code, that's causing it. Most of us here are willing to help, but you should show us, that you've done something to solve the problem yourself.
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
|
|
|
|
|
I tried to get the connected users by Win32_serverConnection/Win32_ServerSession
but I found out that WMI class is unable to get those users connected to my site
I only captured users connected to my computer by mstsc
Can anybody out there give me a clue?
any help would be greatly appreciated!
modified on Monday, May 9, 2011 4:33 AM
|
|
|
|
|
On your second point, if you got the code from an article, then there is a "new message" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
I tried to do it myself, but I found out
that method can't work on my own,
thus I found a smiliar tool over here.
but I found out that it still can't work as well,
so I don't really know what's wrong with it.
is there something related to my OS?
I'm using Windows XP SP3
|
|
|
|
|
As I said: if you got this from an article, then the author of the article is the best person to help you.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Thanks for your suggestions,
I can't find that ariticle anymore..
maybe the best thing I should do right now is to wait
somebody can help me with that.
|
|
|
|
|
|
I cannot help with your first problem: I don't currently have any computers connected to mine, and am not about to set up a connection just for a quick test! Someone else will be along soon, who can help more with that part of your question.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
another question,
by which way others access to my computer,
the info will be record?
like FTP, or access to the site?
|
|
|
|
|
Hello there.
I'm learning generics and linked list.
now i have managed to make a generic linked list, but I don't know how I can get the needed data out of it.
I can do it without generics, but with generics I don't know how, I can't find it.
So here I add people and show all the added people.
LinkedList<Persoon> LlPersoon = LinkedList<Persoon>.GetInstance();
LlPerson.Add(new Persoon(1, "First Person"));
LlPerson.Add(new Persoon(2, "Second Person"));
LlPerson.Add(new Persoon(3, "third person"));
Console.WriteLine(LlPerson);
Console.WriteLine(" Done. Adding Persons...");
but how can I just show the second person?
Without generics I did the following thing to get the name of person 2
public string getName(int iPersonNr)
{
Person Per = FirstPer;
bool bln = false;
string strName = "N/A";
while (Per != null && !bln)
{
if (iPersonNr == Per.getNumber())
{
strName = Per.getName();
bln=true;
}
Per = Per.getVolgende();
}
return strName;
}
I tried for days, but can't find it.
It must be something simple but I have no clue as I don't master generics enough.
any directions or help would be appreciated
thx
frofro
|
|
|
|
|
Are you asking about your own implementation of LinkedList? There is one available in .NET since 2.0
This would be an example of its use:
public class CPTest_LinkedList : CPTest {
public override void Test(int arg) {
LinkedList<Person> persons=new LinkedList<Person>();
foreach(string s in new string[]{"jef", "jan", "jos"}) persons.AddLast(new Person(s));
foreach(Person p in persons) log(p.Name);
foreach(Person p in persons) if (p.ID==1) log("person 1 = "+p.Name);
}
public class Person {
public string Name;
public int ID;
public static int count=0;
public Person(string name) { Name=name; ID=count++; }
}
}
which outputs:
18:57:36.439 CPTest.log-59 jef
18:57:36.453 CPTest.log-59 jan
18:57:36.467 CPTest.log-59 jos
18:57:36.479 CPTest.log-59 person 1 = jan
Its use is pretty easy as it implements ICollection . The one thing you can't do with such LinkedList is indexing, as in persons[1] which works fine in array-based collections such as List<T> itself. Indexing in LinkedList requires scanning the list one node at a time.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Saturday, May 7, 2011 2:46 PM
|
|
|
|
|
Lists are for putting things in, not getting things out.
|
|
|
|
|
Best implemented in WOM. See a datasheet here[^]
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
I recall seeing that data sheet when it originated, a very long time ago...
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I usually use a soft /dev/null for storing, but thinking about it, it might be better having it hardware accelerated. I will have to do some benchmarking...
|
|
|
|
|
Person secondPerson = LlPerson.First.Next.Value;
The above code assumes you are using the built-in linked list. LinkedList doesn't have a "GetInstance()" static method, as you seem to be using in your example. With the .Net LinkedList, you'd initialize it this way:
LinkedList<Person> llPerson = new LinkedList<Person>();
|
|
|
|
|
Hi,
I created setup and deployment to my project and would like to provide license agreement for the installation. Please guide me. Thanks in advance
|
|
|
|
|
|
|
thank you
|
|
|
|
|
|
|
hi! i have a simple AND gate circuit and i have to attach it with pc and control it through coding in c#. first of all i have to chk the serial port through which i have connected the circuit with pc. i dont knw how to control the working of AND gate with coding. means what should i do that if i clk the btn the LED attach on the circuit turn ON?
hope the question is clear
|
|
|
|
|
No, the details of the question aren't clear at all. This is what I can tell you:
- use SerialPort class to open up the right serial port;
- do not use the data lines (transmit, receive), use some of the control lines;
- available inputs are CD (CDHolding), CTS (CtsHolding), DSR (DsrHolding);
- available outputs are DTR (DtrEnable), RTS (RtsEnable);
- you can simply get or set their state by accessing the corresponding properties (mentioned above, within parentheses).
BTW1: for an LED you would need a series resistor, limiting the current to some 10 to 20 mA. Start with 330 or 470 ohm assuming the power supply voltage is 3.3 or 5V.
BTW2: assuming you're talking about some TTL or CMOS AND gate, you need an external voltage as well; however you probably don't really need a gate at all, and could take advantage of RS232C ports typically being able to sink and source 10mA (and more) on their control pins directly. As RS232C voltages may go up to 15V, you should start with a 1K ohm resistor here.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|