Cannot Read Write NFC C# using library - c#

i have a coursework about nfc read and write, but i'm still new using C# and i found some libraries about nfc c#. one of them from h4kbas which I'm currenly using righ now.
the first thing i try is how to read UID, but it seem work fine
private void button1_Click(object sender, EventArgs e)
{
if (NFC.Connect())
{
textBox1.Text = NFC.GetCardUID();
}
}
and then i try making read and write :
Read
private void button2_Click(object sender, EventArgs e)
{
if (NFC.Connect())
{
NFC.WriteBlock(textBox2.Text, "5");
//Close();
}
}
Write
private void button3_Click(object sender, EventArgs e)
{
if (NFC.Connect())
{
NFC.ReadBlock("5");
//Close();
}
}
but after i try making a read and write function above, i don't found any error massage but if i try read or write some string data on running process, forced to close and give massage "The program '[10192] WFANFCReadWriteExecute.exe' has exited with code -1 (0xffffffff)." still..., i don't know the problem is on my code or i have to use "AuthBlock" first.

Related

Listview save to a txt file

I need that all data which I can see now in Find_ list View are online added to C:\Users\Public\WattLOG.txt file
Then I Will Access to this file with another program and read all events.
When there comes new line, I need to store it immediately in file.
private void Find_listView_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Search_listView_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}

Troubleshooting FileDialog trying to update textBox1

I'm looking for an "aha!" moment troubleshooting why the following works in one project, but in building a newer, more efficient version the same structure does not update the text in textBox1 with the result of openFileDialog1.
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
textBox1.Text = openFileDialog1.FileName;
}
I copied and pasted my code from Project 1 to Project 2, so I'm just not sure where the breakdown could be. The rest of the project does execute properly, so openFileDialog1 is completing successfully and allowing me to click button2 to encode a valid RSS xml file from the input given in openFileDialog1. The only thing not working is textBox1.Text displaying the FileName chosen in openFileDialog1. Any ideas as to where the breakdown is are appreciated!

Error while using sharpSSH in C# for multiple buttons

I have 2 buttons, Connect and Send Command. In the first button I am creating the connection to my server and in the second sending a command. The codes are as below:
public void button1_Click(object sender, EventArgs e)
{
SshExec shell = new SshExec("hostname", "username", "password");
shell.Connect();
}
public void button2_Click(object sender, EventArgs e)
{
shell.RunCommand("ls");
}
Now the error is in "shell.RunCommand("ls");" I am getting "The name 'shell' does not contains in the current context". I am new to C# (mere 2 days) and do not have much idea, so please if anyone can help.
What I am expecting is no error and the command to be sent properly to the terminal when the second button is pressed.
At the end sorry for bad formatting of the code, please inform me if any additional information is required.
Right now, you are declaring the variable shell inside the button1_Click method. That means only that method can "see" the variable and use it.
In order for both of the button methods to use the variable, it must be declared outside/above at the class level.
Try this:
private SshExec shell;
public void button1_Click(object sender, EventArgs e)
{
shell = new SshExec("hostname", "username", "password");
shell.Connect();
}
public void button2_Click(object sender, EventArgs e)
{
shell.RunCommand("ls");
}

Refresh DataGridView using BindingSource and TableAdapter

i actually work on a Customer-DataGrid but i stuck on the Sources because i dont use really often C#.
I have a DataGridView (dataGridView1), a internal Database (Database.mdf), a BindingSource (customerBindingSource) and customerTableAdapter
Now i trying to refresh the DataSource when i click a button.
Here is a simple snippet:
private void Kundenverwaltung_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'kundenAnsicht.customer' table. You can move, or remove it, as needed.
this.customerTableAdapter.Fill(this.kundenAnsicht.customer);
}
// I tried already some methods but i dont find a properly, functionally way
private void button2_Click(object sender, EventArgs e)
{
this.customerTableAdapter.Fill(this.kundenAnsicht.customer);
}
I hope you can understand my problem.
~ Dennis
You need to connect your DataGridView with "customerBindingSource":
`private void Kundenverwaltung_Load(object sender, EventArgs e)
{
this.dataGridView1.DataSource = this.customerBindingSource;
this.customerTableAdapter.Fill(this.kundenAnsicht.customer);
}
private void button2_Click(object sender, EventArgs e)
{
this.customerTableAdapter.Fill(this.kundenAnsicht.customer);
}`
It all.

How do I close an open file?

This button opens a text file which has error log information:
private void btnViewErrorLogFile_Click(object sender, EventArgs e)
{
Process.Start(AppVars.ErrorLogFilePath);
}
When the user goes to do any processing in the application, I want to check whether the file is open or not, if it is open, then I want to close it. How would I go about doing this?
This example is almost identical to what you're trying to do:
Process.Close Method
Process myProcess;
private void btnViewErrorLogFile_Click(object sender, EventArgs e)
{
myProcess.Start(AppVars.ErrorLogFilePath);
}
private void doSomething()
{
if (!myProcess.HasExited)
{
myProcess.CloseMainWindow();
myProcess.Close();
}
// Do whatever you need with the file
}
Shows how to check if it's running and how to close it.

Categories

Resources