|
Now I know that almost all USB barcode scanners type to whatever you have focused...
The problem I am facing is I want to scan something, then it querys a database based upon that barcode scanned. I had just focused a textbox for this, but when I got the scanner today I noticed something that I didn't think about... The scanner doesn't "paste" the data in the textbox. It literally types it out.
So I have a on text change to query the database with whats in the textbox. Is there another way I should be doing this? The length of characters for the barcode we will be scanning is not always the same. So I can't do it based on length of whats in the textbox.
I was wondering if there was a way to read it like you do a serial port scanner and have it not go into a textbox? I have googled and searched for this but have not found anything yet for doing this with a USB barcode scanner.
|
|
|
|
|
If there is not an event or flag sent when the barcode read is compleat then you could always implement something on the textchanged event. Set a flag and a timer when the first char is entered, reset the timer for each change, if the timer reaches 1 second then the last character has been entered. Write the data to the database!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Good idea.. I will give that a try.. although I do have to admit that seems to be kind of a "unreliable" way? I was thinking there would be another way.. but as long as there is no lag in inputing the information it should work great. I will try it out. Thanks
|
|
|
|
|
Most barcode readers provide a prefix and a postfix string, so you can specify text that gets added before and after the scanned data. Putting a unique character or string in the postfix string can be used to detect the end of the input, without waiting a fixed time. When not supported, a time delay seems the best tactic.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Anny decent scanner will let you setup pre- and post-fix character(s) it should add to the barcode when it's scanned. Handle the Form's Keydown event (remember to turn on the Form's KeyPreview!) and you can look for the pre-fix character(s) before any control on your form gets the keystrokes comming from the scanner. If you see the pre-fix character(s), start recording every keystroke until you get the post-fix character(s). Remember to set the e.Handled flag to True while you're seeing the characters you want, including pre-fix, data, and post-fix. When you see the post-fix character(s), you've got your barcode!
You may also want to put some kind of a timeout in this algorithm somewhere so you're not infinitely waiting for post-fix characters you may never see because of some failure of the scanner.
|
|
|
|
|
Dave Kreskowiak wrote: kind of a timeout in this algorithm
See, see my timer did get a look in after all
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I actually went with your timer theory and it seems to be working well. I haven't tried the others since I haven't learned out to append prefix and postfix strings. It was on the cheaper end around $100 scanner (HP LS2208-SR20361R)
|
|
|
|
|
hi
i came across the same sencerio as u, but its really easy
by using textbox KeyUp event, my scanner sends the
barcode data plus 'enter key'. so it got simple
private sub txt_barcode(byval sender as object, byval e as keyeventargs) handles txt_barcode.keyup
if e.keycode = key.enter then
dim barcode as string = txt_barcode.text.trim
.............
'lookup the database and pull the data
.....................
end if
end sub
|
|
|
|
|
I will have to try that! I think I was trying to look for that enter on a key down event before... Not a key up
|
|
|
|
|
Hi! I have made a Client and a Server applications. I want to send a file from the Server to the Client. This is how I do it:
<br />
ns is a NetworkStream which is connected.<br />
writer is a StreamWriter.<br />
<br />
The Srever:<br />
<br />
FileStream fs = File.OpenRead(path);<br />
long byteCount = fs.Length;<br />
writer.WriteLine(byteCount);
writer.Flush();<br />
int readBytes = 0;<br />
byte[] buffer = new byte[1024];<br />
while (readBytes < byteCount && ns.CanWrite)<br />
{<br />
int length = fs.Read(buffer, 0, buffer.Length);<br />
ns.Write(buffer, 0, length);<br />
ns.Flush();
readBytes = readBytes + length;<br />
}<br />
<br />
The Client:<br />
<br />
FileStream fs = File.Create(Application.StartupPath + "\\buffer.nkl");
long byteCount = long.Parse(reader.ReadLine());
int readBytes = 0;<br />
byte[] buffer = new byte[1024];<br />
while (readBytes < byteCount && ns.DataAvailable)<br />
{<br />
int length = ns.Read(buffer, 0, buffer.Length);<br />
fs.Write(buffer, 0, length);<br />
readBytes = readBytes + length;<br />
}
The problem is that the received file is trimmed - it isn't whole (sent file is 198 kb, received file is 23 kb). If I remove ns.DataAvailable it takes a long time and the file is almost complete (sent file is 198 kb, received file is 196 kb).
What am I doing wrong???
Still learning...
|
|
|
|
|
Hi,
you shouldn't give up once ns.DataAvailable is false, that could happen any time: maybe the server is temporarily busy (say waiting on disk I/O, serving other clients, ..) or the client has a more powerful machine, hence it would run ahead.
A better approach would be for the client to either just ignore ns.DataAvailable (now the client would hang if the server exits unexpectedly) or allow for a later retry (say when false, wait 100 msec and try again) which increases the odds, but exits gracefully when the communication really goes wrong.
If it goes wrong, add some logging statements to both server and client so you can see where it fails.
Example: Console.WriteLine("server: readBytes="+readBytes);
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
When the download is complete I can enter other commands to the server. If I have ns.DataAvailable, when I enter the command to my server to disconnect (the server should return "Disconnected") I receive a part of the transferred file (several words from it). As if there is still data in the stream.
But when the ns.DataAvailable is absent from the while loop, when I enter the command for download, the download begins but never ends. I have to close the client and then the buffer file is at 196 kb.
I am testing the application on my computer - both the client and the server (for an IP I am using localhost) so there shouldn't be a difference.
Still learning...
|
|
|
|
|
nike_arh wrote: I am testing the application on my computer - both the client and the server (for an IP I am using localhost) so there shouldn't be a difference.
Their relative priority (and hence the percentage of CPU cycles allotted to each of them) will depend on which process is in front!
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
In FirstWindow class:
* Has progress bar object named "progressBar1".
* Its value is updated in this class as the process runs.
In SecondWindow class:
* Has progress bar object named "pbSecond".
* This SecondWindow class invokes FirstWindow class but does not use (display) the
FirstWindow GUI.
* This SecondWindow sends the data to FirstWindow the data to be processed and save to the file.
Now, I had this kinda of crazy idea to try and was amazed it does work! I'm not certain on how this works... passing the pointer of the object?
FirstWindow class has this property:
public ProgressBar pBar
{
set { progressBar1 = value; }
}
public int DumpRFData(byte[] dat)
{
pBar.Maximum = dat.length;
for (int i = 0; i < dat.length; i++)
{
progressBar1.value = i;
... code sippet (for retriving dump data)
}
}
now in SecondWindow class:
public int DumpData()
{
byte[] data = new byte[1000];
FirstWindow fw = new FirstWindow();
fw.pBar = pbSecond;
fw.DumpRFData(data);
}
when the DumpRFData is invoked, the progress bar in SecondWindow is updated as the process in FirstWindow runs.
How could that be happening? Processed from the pointer or what?
|
|
|
|
|
It's not a pointer, it's a reference. This is pretty ugly, your dumpRFData method should be outside any UI class.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
right... I am in the middle of refactoring my source code to clean up the repeated functions and capsulate the classes with its appropriate methods.
|
|
|
|
|
Hi,
I need some urgent help on something.
I need to convert Expression<Func<T1, bool>> to Expression<Func<T2, bool>>.
I have a funtion that does T2 = Convert(T1)
In other words I need a function that does something like:
Expression<Func<T2, bool>> Convert(Expression<Func<T1, bool>> pSource) {
Expression<Func<T2, bool>> vResult;
...
...
...
T2 vOutpuParameter = Convert(vInputParameter);
...
...
...
return vResult;
}
Does anyone have any clues?
|
|
|
|
|
Hello
I'm trying to find some idea / method to draw railway pattern using Graphics gdi+
Google map gives a example to do some, I do not need to do exactly the same but something that can looks like a railway
The source information is an array of PointF
I'd a look on Pen.CompoundArray but I do not understand how it works from an atrray of PointF
Thanks for any help / suggestion
|
|
|
|
|
You mean a railway track ? I guess you draw two lines next to each other, then you draw small lines across it. I would think the best way to do that, would be to create a brush that defines a piece of track, then use that to draw your line.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
guess you draw two lines next to each other, then you draw small lines across it.
This is the obvious "brute force" way : needs a lot of calculation awikll fatten the code I really do not want to use that way
I would think the best way to do that, would be to create a brush that defines a piece of track, then use that to draw your line.
I also think that it will be a good way but I do not know how to define the brush ?
Do I have to create an external image ?
|
|
|
|
|
baranils wrote: I also think that it will be a good way but I do not know how to define the brush ?
You create a brush from a Bitmap, so you can load that from a file, or just draw it. In fact, I think the class you want is called BitmapBrush
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
You'll probably have to draw over the line twice. Read up on the compoundarray to get it to draw a double line (your railway lines). Then draw over that with a thick line and custom dash style to get sleepers.
|
|
|
|
|
Thank you
I will investigate that way !
|
|
|
|
|
Moving an array element to a variable.
When I started I didn't think just taking an element and copying to a variable was such a hassle.
OK, I have a string array defined as:
public static string[] Trux_Info = new string[20];
and I have a varaible define as
public static string port_in = "";
Now I thought that something like
port_in = Trux_Info[3]
would work. It didn't. I tried Trux_Info.GetValue(3). It didn't work right.
I know Trux_Info has info I can print to screen\file and the right info is there. I even passed the array across child, parent and back to a different child, the info is there.
I really need this element to go to this single variable, because after this happens then the processing can begin.
Any and all suggestion are appreciated.
Thanks
|
|
|
|
|
I tried it:
public static string[] Trux_Info = new string[20];
public static string port_in = "";
private void button1_Click(object sender, EventArgs e)
{
Trux_Info[0] = "Hello";
Trux_Info[1] = "There";
Trux_Info[2] = "This";
Trux_Info[3] = "Is";
Trux_Info[4] = "A";
Trux_Info[5] = "Test";
port_in = Trux_Info[3];
MessageBox.Show(port_in);
}
It show "Is" - which is what I would expect.
So, there is something you aren't telling us. Give us a cut-down-but-still-not-working sample of the code that isn't doing it's job, and tell us what it is doing instead.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|