0

I am currently developping a web application that needs to be able to read datamatrix codes that contain multiple values ( all seperated by pipes ). This code contains about 70-80 characters and I only need the first 10.

I am using a simple javascript regex that allows me to detect when those 10 characters are entered and I then trigger a postback.

So that is how it works: When I scan the code and see that I have the part I need, I trigger a postback, do some logic on the backend, and then, put back the focus on the input used for scanning so that the user can scan again.

The problem is: When I set the focus back to the input, the scanner continues to output the rest of the previous datamatrix code ! ( the scanner takes about 1-1.2 seconds to scan the complete code ), so if my backend logic is faster than that, it won't be finished, even after my postback. )

My question is: Is there something I can do about it ?

Here are two of the solutions that I have but that are not ideal at all:

  • Use some sort of a javascript timer that would allow me to detect whenever the scanner has finished ( the problem is that, I don't want to wait for the scanner to finish before scanning a new code )

  • Put another datamatrix that contains only this value ( This would be my last solution since it would impact a lot of things )

D.Gaulin
  • 108
  • 1
  • 8
  • Before reading an new code you need to flush the buffer. – jdweng Oct 24 '20 at 13:48
  • @jdweng , Didn't think that it was possible ! Do you have any idea of how I could achieve this ? – D.Gaulin Oct 24 '20 at 16:02
  • is the length of the scan always the same? I would let the text box receive the whole scan - once characters start to flow I would think the data coming is very fast. that way you don't have to flush the buffer. The other would be to use js and keydown - you would STILL grab all chars - but chop after 10 and THEN and ONLY then postback after all the chars been received/read/grabbed. In other words, I would not dare do a post-back until the whole text block is received. You going have a gazillion issues if you do a post back and chars are still incoming. – Albert D. Kallal Oct 24 '20 at 16:58
  • @AlbertD.Kallal I currently wait for the whole string then take the part I want. The thing is the scanner is quite slow ( few seconds ) and I don't want the user to wait.. – D.Gaulin Oct 24 '20 at 21:56
  • Ok, i got the part about scanner being slow. But you can't possbile tell me the scanner spits out 1 char, you wait, and then the next char appears. and then you wait, and then the next char and you wait? The stream of chars for one scan is going to occur as a whole pack of chars - and no doubt appears fast - very fast. If the next scan to come is slow - we dont' care. the only issue is each scan a known length? And the bottoms to bets the last char is some type of termination char. So you get/grab/take the WHOLE string in one shot. You don't stop your read at 10 chars. – Albert D. Kallal Oct 24 '20 at 22:22
  • @AlbertD.Kallal As I said in my post the scan can take up to 1 second ( there is a lot of data in that datamatrix ). – D.Gaulin Oct 24 '20 at 22:24
  • I would be beyind shocked if that ONCE chars start comming and appearing? You get the WHOLE scan string in a flash. So grab/get/take the whole string and THEN chop it. you in no possible way want to grab the first 10 and then the rest of the one scan chars are still coming in. So each scan can be slow, but the flow of chars for one scan happens in one "flash" of incoming string. So I would ALWAYS take that one string, and then chop the 10 chars off. If the strings (each scan) can flow bunched up, then you still must have a known length, or a termination char. – Albert D. Kallal Oct 24 '20 at 22:25
  • @AlbertD.Kallal Ok, the time it takes to scan a SINGLE datamatrix is about a second. It does not appear all at once. That is why I want to takes only the first 10 characters, flush the buffer then do this again and again. I don't want the user to wait for the whole code to be typed in. – D.Gaulin Oct 24 '20 at 22:27
  • Not suggesting you have to wait. So it takes say .4 of a second for the first 10 chars to appear, and then say another .5 for the next 10 chars to appear? So you can actually see each character appearing one by one? Seems strange. I would still use JavaScript to get the first 10, and it would continue to read chars, but just ignore or toss them out. So the loop code that fires on each char can continue, and when it reaches 10, then it can do something. You can't do a post back (perhaps in a update panel is ok). If posting back for each char, then it that code that slow - not the scanner. – Albert D. Kallal Oct 24 '20 at 22:39
  • The fact is that I need to manipulate the data on the backend. ( So I need a Postback ) and that if I can't flush the buffer I can't Postback because when it returns to the page it'll write the rest of the characters. – D.Gaulin Oct 24 '20 at 22:41
  • Are we trying to be silly here on purpose? Of course you need a post-back, but you sure as the heck don't need nor want one to occur until you have at least 10 chars - right? As I asked, if you take a blank form with a text box (zero zero zero code on this page). What is the time difference between the first 10 chars appearing and the next 10 chars in that form. Since this is so slow, you can use a stopwatch or at least hit stop when the 10th char appears, and then do the whole timing over again and hit stop watch at 20th char since they appear so slow. – Albert D. Kallal Oct 25 '20 at 02:03
  • I'm sorry but you don't understand my need. I scan a datamatrix and only want a part of it. If I Postabck too soon, the rest of the scan appears in the box. And I CANNOT wait until it's all done. The user needs to scan the first code, when I've got the part I want, I Postabck then the user should be able to scan again. I'm sorry I don't see how I could be clearer. – D.Gaulin Oct 25 '20 at 02:05
  • You not going to post back too soon. And we can post back and still have the client side software grabbing characters. So the grabbing of chars (say the first 10 and then the post back can occur - and the grabbing of chars can also still continue. However since we KNOW we need at least 10 chars, then no good reason to post back until we buffered up 10 chars. As we post back (with the 10 chars), the client code can continue grabbing chars that we presumably toss out. But until you give that timing information (first 10 vs say first 20), then all bets are off on this solution. – Albert D. Kallal Oct 25 '20 at 02:49
  • 1
    For example, whether the scanner you are using is hardware or software, if you have the ability to discard the data you are processing, you can call it. Without such a feature, you can't stop it and you have to wait until all the data is read. However, if you can manage the state of receiving unnecessary data, you may be able to perform other processing in parallel during that time. – kunif Oct 26 '20 at 10:29

1 Answers1

0

Although I would have liked to find an in-code solution, I found another solution.

I found out that I could change the scanner's speed using a configuration page. I put it at "fast" and now I receive the string almost all at once. ( Not event .2 seconds )

I just don't know why fast isn't the default option..

D.Gaulin
  • 108
  • 1
  • 8
  • 1
    Likely because when the scanner was originally developed that was its maximum speed - and over time software using that scanner came to depend on that speed - by making it faster they broke that software - so they have to default to the original slow behaviour to ensure their clients' old software continues to work! – Ian Kemp Oct 26 '20 at 11:48