|
Am trying to read/write to card using RFID reader, but the RFID reader is appearing under Human Interface Device, so far I have been able to get all Human Interface Devices into a DropDownlist using HidLibrary here is my code
HidDevice[] mahdDevices;
private void Form1_Load(object sender, EventArgs e)
{
mahdDevices = HidDevices.Enumerate().ToArray();
for (int i = 0; i < mahdDevices.Length; i++)
{
cmbDevices.Items.Add(mahdDevices[i].Description);
}
}
But now am not sure of how to send and receive data from the HID selected on the drop downlist, I also checked Hardware IDs of RFID device in properties, No idea on what to do with the IDs or how to communicate with HID devices to scan card, this is how i usually communicate with devices using serial port:
_port = new SerialPort();
_port.PortName = comboBox2.Text;
_port.BaudRate = 9600;
_port.Parity = Parity.None;
_port.DataBits = 8;
_port.StopBits = StopBits.One;
if (_port.IsOpen)
{
textBox1.Clear();
}
else
{
_port.Close();
}
_port.DataReceived += new SerialDataReceivedEventHandler(RFID_DataReceiver);
Please I need help communicating with HIDs.
|
|
|
|
|
RFID Readers do not allow you to write to the chip. As the name implies, it READS, not writes. All it does is read ID tags that are programmed into the chips.
RFID Readers usually expose themselves as either a serial device (think COM ports of the old days), or as keyboards, where they "type" whatever code they read off the card. For this to work, you'd have to handle key input using your Forms KeyPreview event.
How the device exposes itself would be covered in the documentation for whatever reader you're using.
|
|
|
|
|
Am completely new to working with RFID, I just need some help reading the content of an RFID Card, I did something and i found a HidLibrary to get input from HID devices but I still finding it hard to use. Here is what i have done so far:
private void button4_Click(object sender, EventArgs e)
{
var devives = HidDevices.Enumerate(0x9915, 0x1116);
_device = devives.First();
_device.OpenDevice();
_device.Inserted += DeviceAttachedHandler;
_device.Removed += DeviceRemovedHandler;
_device.MonitorDeviceEvents = true;
_device.Write(new byte[] { 0, 81, 80 });
_device.ReadReport(OnReport);
_device.CloseDevice();
}
When it hits _device.write, I hear a couple of beep sounds I don't really know what that means..
private void DeviceAttachedHandler()
{
_device.ReadReport(OnReport);
}
private static void DeviceRemovedHandler()
{
Console.WriteLine("Device Removed");
}
private void OnReport(HidReport report)
{
if (!_device.IsConnected) { return; }
var cardData = report.Data;
str = Encoding.ASCII.GetString(cardData);
if (str == null)
{
_device.ReadReport(OnReport);
}
else
{
MessageBox.Show("String");
}
}
OnReport data returns 0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 I don't know what this means too any help please
|
|
|
|
|
I couldn't tell you. I know nothing about your device at all.
Frankly, going through a HID driver is doing it the hard way.
Like I said, it's going to be covered in the documentation of the device. If you don't have any documentation, nor vendor developer support, you bought the wrong device.
|
|
|
|
|
Okay the card reader is working fine in another software I want to implement that same functionality in my software, that's what this whole struggle about, and I don't have any documentation to look at.
|
|
|
|
|
If you've got no docs, you bought the wrong device. Anything you do is just guessing.
You try to figure out how the device exposes itself by doing some testing. If it's a "keyboard wedge", all you have to do is open Notepad, make sure it has the focus, the scan a card. If text shows up in Notepad, it's acting like a keyboard.
If that doesn't do anything, you can go into Device Manager and see if it exposes itself as a COM port device.
I worked with RFID hardware back about 15 years ago, but the devices I had were all Ethernet-based and I had all the documentation on them.
|
|
|
|
|
I have checked the device manager, it is seen in Human Interface Device, I got the hardware IDs hoping I could do something with the IDs but nothing yet
|
|
|
|
|
If it's showing us as a HID, you can see if it's working like a keyboard.
I already told you how to do that.
|
|
|
|
|
Dave is right: without information you are just whistling in the dark - you need to talk to the manufacturers of the reader, and see what manuals / data / sample code they can provide.
Just trying to work it out by assuming it's a HID and guessing is a very slow and clumsy way compared with reading the manual!
If it's a HID, then it's probably configured to act as a keyboard rather than to provide a "direct datastream" - but you can only confirm that by finding the maker.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hello everyone! I need help with generating random decimal numbers from 5 to 6 (For example 5.1, 5.2 etc.) It often throws out various errors to me so I decided to contact the team on the forum. Any advice and suggestions will be helpful to me. I am a beginner in all this..
|
|
|
|
|
There is no direct support for random decimal numbers in .NET, but it's pretty easy to do:
private Random rand = new Random();
private decimal GetRandom(decimal min, decimal max)
{
return ((decimal)rand.Next((int)(min * 100.0M), (int)(max * 100.0M))) / 100.0M;
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Or, if you need more resolution:
private Random rand = new Random();
public decimal GetRandom(decimal min, decimal max, int steps=10000) {
if (steps<=0) throw new ApplicationException("steps must be >= 1");
int r = rand.Next(0, steps);
return ((steps-r)*min+r*max)/steps;
}
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
|
|
|
|
|
Yours a homework question, so my answer not going to be acceptable, but for your amusement, read on.
Sajo Nezic wrote: I need help with generating random decimal numbers from 5 to 6 (For example 5.1, 5.2 etc.) That's a question from a user. As a developer, you supposed to see that "5" is a constant and not relevant to the question. You generate a float and put a "5." string in front of it. Gives you instantly one more digit to play.
So the next thing the user wants is "random data". There's this thing called a "youtube" giving you very large blobs of random data. Not "random" enough for homework, but random enough for encryption using one-time-pads. The amount of data available is overwhelming.
Back to your position; you get multiple errors, and we cannot guess what wrong on "multiple", as the answer is "multiple". Show us your code, let us argue for a day and then come back. Your code cannot be more wrong than my first code, so just share and learn.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Sajo Nezic wrote: It often throws out various errors to me
You need to show the code and explain what are the errors, otherwise we can't help you to fix your code.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
There is a lengthy discussion (with code examples) of generating random decimal numbers in C# here: [^].
imho, very few apps need greater random number "integrity" than that provided by the Framework (see OriginalGriff's solution, here), or, by using the other native crypto facilities: [^]
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
BillWoodruff wrote: There is a lengthy discussion (with code examples) of generating random decimal numbers in C# here: [^].
and a much simpler one at xkcd: Random Number[^] (read the tooltip text)
|
|
|
|
|
Hello
I have a problem statement for which looking for a solution.
Requirement:
1. I have around 1000 files and all are in different folders e.g
2020-08-11->
Folder 1 -> file 1
folder 2 -> file 2
2. Wanted to write a program which will extract lines from these files and create one output file
3. Input Lines to read came from Database table e.g
one column in table which stores the input for the program.
Any suggestion or reference is appreciated. Not a good at C# programming
|
|
|
|
|
|
And?
What have you tried?
Where are you stuck?
What help do you need?
All we have so far is a "wish list"!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
lalgourav wrote: Any suggestion or reference is appreciated. Not a good at C# programming This is a C# programming forum. You can ask for help, but not solutions.
lalgourav wrote: I have around 1000 files and all are in different folders If this asked during an interview I just leave without a word; 10, 1000, or 20000 items is the same loop.
lalgourav wrote: Any suggestion or reference is appreciated. Hire someone. You have 32 teeth, 16 bottom, 16 top. I know the numbers, the locations, the theory, but still you wouldn't want me as a dentist. Not even after a two-month course.
You need a programmer? Hire one.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi everyone!
Does anyone have a sniblet to be able to detect if the device is enabled or disabled in device manager. I've done a bit a searching and couldn't find anything of use when attempting to get a status of a device.
What I have so far, it appears the value I am obtaining by marshaling my Data stays the same regardless of its status so my API call is incorrect or the way I am marshaling out and I was hoping one of you may have a sniblet that actually works.
Below are two failed attempts at getting the device status :\
Thank you!!
public static bool GetDeviceState(Func<string, bool> filter)
{
var dpk = new DEVPROPKEY();
dpk.fmtid = new Guid("60b193cb-5276-4d0f-96fc-f173abad3ec6");
dpk.pid = 2;
var displayDevClass = new Guid("{ca3e7ab9-b4c3-4ae6-8251-579ef933890f}".ToString());
var hDevInfo = SetupDiGetClassDevs(ref displayDevClass, null, IntPtr.Zero, DiGetClassFlags.DIGCF_PRESENT | DiGetClassFlags.DIGCF_DEVICEINTERFACE);
if (hDevInfo != INVALID_HANDLE_VALUE)
{
uint i = 0;
while (true)
{
var did = new SP_DEVINFO_DATA();
did.cbSize = (uint)Marshal.SizeOf(did);
if (!SetupDiEnumDeviceInfo(hDevInfo, i, out did)) break;
uint required = 0;
DEVPROPTYPE dpt = 0;
var temp = new byte[0];
SetupDiGetDeviceProperty(hDevInfo, ref did, ref dpk, ref dpt, temp, 0, ref required);
if (required > 0)
{
var data = new byte[required];
if (SetupDiGetDeviceProperty(hDevInfo, ref did, ref dpk, ref dpt, data, required, ref required))
{
Debug.WriteLine(BitConverter.ToString(data));
}
}
}
}
IntPtr info = IntPtr.Zero;
Guid NullGuid = Guid.Empty;
try
{
info = SetupDiGetClassDevsW(ref NullGuid, null, IntPtr.Zero, DIGCF_ALLCLASSES);
CheckError("SetupDiGetClassDevs");
SP_DEVINFO_DATA devdata = new SP_DEVINFO_DATA();
devdata.cbSize = (UInt32)Marshal.SizeOf(devdata);
for (uint i = 0; ; i++)
{
SetupDiEnumDeviceInfo(info, i, out devdata);
if (Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS)
CheckError("No device found matching filter.", 0xcffff);
CheckError("SetupDiEnumDeviceInfo");
string devicepath = GetStringPropertyForDevice(info, devdata, 1);
uint CM_DEVCAP_HARDWAREDISABLED = 0x100;
uint proptype, outsize;
IntPtr buffer = IntPtr.Zero;
SetupDiGetDeviceRegistryPropertyW(info, ref devdata, (uint)SetupDiGetDeviceRegistryPropertyEnum.SPDRP_CAPABILITIES, out proptype, IntPtr.Zero, 0, out outsize);
uint buflen = outsize;
buffer = Marshal.AllocHGlobal((int)buflen);
outsize = 0;
SetupDiGetDeviceRegistryPropertyW(info, ref devdata, (uint)SetupDiGetDeviceRegistryPropertyEnum.SPDRP_CAPABILITIES, out proptype, buffer, buflen, out outsize);
byte[] lbuffer = new byte[outsize];
Marshal.Copy(buffer, lbuffer, 0, (int)outsize);
int errcode = Marshal.GetLastWin32Error();
if (errcode == ERROR_INVALID_DATA) return false;
CheckError("SetupDiGetDeviceProperty", errcode);
uint capabilities = BitConverter.ToUInt32(lbuffer, 0);
capabilities = getDWORDProp(info, devdata, SetupDiGetDeviceRegistryPropertyEnum.SPDRP_CAPABILITIES);
uint bitwise = capabilities & CM_DEVCAP_HARDWAREDISABLED;
bool isHardwareDisabled = bitwise > 0;
Debug.WriteLine(devicepath);
Debug.WriteLine(" - HARDWAREDISABLED: " + isHardwareDisabled.ToString().Trim() + " Compat: " + capabilities.ToString());
if (devicepath != null && filter(devicepath)) break;
}
}
finally
{
if (info != IntPtr.Zero)
SetupDiDestroyDeviceInfoList(info);
}
return true;
}
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool SetupDiGetDeviceRegistryProperty(IntPtr deviceInfoSet, ref SP_DEVINFO_DATA deviceInfoData, uint property, out UInt32 propertyRegDataType, byte[] propertyBuffer, uint propertyBufferSize, out UInt32 requiredSize);
public enum RegType : uint
{
REG_BINARY = 3,
REG_DWORD = 4,
REG_EXPAND_SZ = 2,
REG_MULTI_SZ = 7,
REG_SZ = 1
}
const int BUFFER_SIZE = 1024;
static string getStringProp(IntPtr h, SP_DEVINFO_DATA da, SetupDiGetDeviceRegistryPropertyEnum prop)
{
UInt32 requiredSize;
UInt32 regType;
byte[] ptrBuf = new byte[BUFFER_SIZE];
if (!SetupDiGetDeviceRegistryProperty(h, ref da, (uint)prop, out regType, ptrBuf, BUFFER_SIZE, out requiredSize))
throw new InvalidOperationException("Error getting string property");
if (regType != (uint)RegType.REG_SZ || (requiredSize & 1) != 0)
throw new InvalidOperationException("Property is not a REG_SZ");
if (requiredSize == 0)
return "";
return Encoding.Unicode.GetString(ptrBuf, 0, (int)requiredSize - 2);
}
static uint getDWORDProp(IntPtr h, SP_DEVINFO_DATA da, SetupDiGetDeviceRegistryPropertyEnum prop)
{
UInt32 requiredSize;
UInt32 regType;
byte[] ptrBuf = new byte[4];
if (!SetupDiGetDeviceRegistryProperty(h, ref da, (uint)prop, out regType, ptrBuf, 4, out requiredSize))
throw new InvalidOperationException("Error getting DWORD property");
if (regType != (uint)RegType.REG_DWORD || requiredSize != 4)
throw new InvalidOperationException("Property is not a REG_DWORD");
return BitConverter.ToUInt32(ptrBuf, 0);
}
|
|
|
|
|
Hi, I'm not familiar with most of the functions you're using, but maybe this helps:
I once was interested in the enable/disable status of my Ethernet connection, as set in the Control Panel Network Connections (which might be different from the choice offered in Device Manager).
I used WMI (class Win32_NetworkAdapter), and checked property NetConnectionStatus which was zero for disabled and non-zero (7 IIRC) for enabled.
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
|
|
|
|
|
Here is fresh code that works for me:
using System;
using System.Management;
namespace LP_Core {
public class LP_Ethernet {
public static string GetState() {
string query = "SELECT NetConnectionStatus FROM Win32_NetworkAdapter "+
"WHERE NetConnectionID='Ethernet'";
ManagementObjectSearcher ethernets = new ManagementObjectSearcher(query);
foreach (ManagementObject ethernet in ethernets.Get()) {
switch (Convert.ToInt32(ethernet["NetConnectionStatus"])) {
case 0:
return "disabled";
case 7:
return "enabled but disconnected";
case 2:
return "enabled and connected";
default:
return "unknown";
}
}
return "absent";
}
}
}
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
modified 10-Aug-20 21:38pm.
|
|
|
|
|
Luc is being modest. If he says he got a better idea, you better follow it.
Not every device is complete in terms of device-drivers. I have a mountain of webcams that don't work under Linux to prove so.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Bonjour,
Je voulais déployer mon web service en IIS.
Ce web service crée en C# permettant de connecter à une base oracle 11g.
J'ai utilisé comme connecteur Oracle Data Access.
Le web service fonctionne localement mais après déploiement j'ai le message suivant :
Oracle.DataAccess.Client.OracleConnection --> Oracle.DataAccess.Client.OracleException: The provider is not compatible with the version of Oracle client à Oracle.DataAccess.Client.OracleInit.Initialize()
Le connecteur Oracle Data Access est en 32 bits alors j'ai activé les applications 32bits en IIS mais le même problème.
Merci.
Google translate: Hello,
I wanted to deploy my web service in IIS.
This web service created in C # allowing to connect to an Oracle 11g database.
I used as Oracle Data Access connector.
The web service works locally but after deployment I have the following message:
Oracle.DataAccess.Client.OracleConnection -> Oracle.DataAccess.Client.OracleException: The provider is not compatible with the version of Oracle client à Oracle.DataAccess.Client.OracleInit.Initialize ()
The Oracle Data Access connector is 32-bit so I enabled 32-bit applications in IIS but the same problem.
Thank you.
|
|
|
|
|