1. Nguyen Xuan Huy
  2. PowerBuilder
  3. Thursday, 15 July 2021 08:13 AM UTC

 

I am trying to make a function to read data from a device (barcode scanner).

By design a barcode scanner works like a keyboard to input data (key by key). It is not convenient for a store.

I want to read data direct from the device as a whole text. is there any way to do that?

 

Thank you

Huy

Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 15 July 2021 18:03 PM UTC
  2. PowerBuilder
  3. # 1

Hi  Nguyen;

   Does the BarCode vendor supply a DLL that you could use to interface to that device?

Regards ... Chris

Comment
  1. Nguyen Xuan Huy
  2. Friday, 16 July 2021 01:49 AM UTC
Hi Chris



No, only some brand name scanner supply with DLL, almost not.



Regards

Huy
  1. Helpful
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Thursday, 15 July 2021 18:15 PM UTC
  2. PowerBuilder
  3. # 2

Chris is correct:  you absolutely need a way to interface with the device. Most barcode scanners will have this already set up and documented, so you will know how to call the functions required to interact with the device.

If the device reads a stream of test to the COM port, you can access the READ that way, as well.

From a previous post by Chris:

Hi <username>;

  A serial port or USB  device can be read or written to using the FileOpen ( ) method. For example ...

integer li_FileNum

li_FileNum = FileOpen ( "COM1:", LineMode!, Write!, LockWrite!, Replace!)

FileRead / FileWrite ...

Just replace COM1: with the device name / port you need to access

HTH

Regards ... Chris

Comment
  1. Nguyen Xuan Huy
  2. Friday, 16 July 2021 01:47 AM UTC
Hi Olan Knight



I have tried the below:

int li_rtn

li_rtn = FileOpen("\Device\0000003e", LineMode!, Read!, LockRead!, Replace!)

Or

li_rtn = FileOpen("\\.\GLOBALROOT\Device\0000003e", LineMode!, Read!, LockRead!, Replace!)

Both case return -1

"\Device\0000003e" is Physical device object name ( in windows device manager)



I don't know how to fix.



Best regards

Huy
  1. Helpful
  1. Olan Knight
  2. Friday, 16 July 2021 11:48 AM UTC
Try using the example above:

integer li_FileNum

li_FileNum = FileOpen ( "COM1:", LineMode!, Write!, LockWrite!, Replace!)



Remember that the COM1 port is on your device, and is a reserved word so the sysytem should identifyand route that FileOpen correctly.
  1. Helpful
  1. Miguel Leeuwe
  2. Friday, 16 July 2021 11:57 AM UTC
If you only want to read, why try to apply a write and a lock? I'd say, first try to get Read access without locking. If that works, try to lock.
  1. Helpful
There are no comments made yet.
Christopher Altvater Accepted Answer Pending Moderation
  1. Friday, 16 July 2021 13:07 PM UTC
  2. PowerBuilder
  3. # 3

Hi Nguyen,

I am using generic USB barcode scanners and when the user has specific window opened, the window key event captures the data to an instance variable. As each character comes from the scanner, the key event fires and the KeyDown function checks the characters. I am using barcode 39 and the data should only be upper case alpha and numeric characters. As the characters are appended to the instance variable, the code in the event looks for the enter key from the scanner to indicate the end of the scan and then it will valid the data in the instance variable.

This is not the most common way to use barcode scanners with PB, but it works for me. If you are interested, I can provide the key event code.

Another method would be to use some type of data wedge software, but this is an extra expense.

Chris

Comment
  1. mike S
  2. Friday, 16 July 2021 13:22 PM UTC
many barcode scanners allow you to add in prepend characters - so that could be checked for to see if a scan started, then continue on until the postpend character (also usually settable) is sent.
  1. Helpful
  1. Christopher Altvater
  2. Friday, 16 July 2021 14:01 PM UTC
I use the letter "A" for a prefix to identify the data. The following number can either be 7 or 11 digits. So when the enter key fires the event, the data is validated and resets the variable.



I am not counting the characters as the key event fires, but this could be added for better validation.



Many USB scanners can be configurated with a different prefix and postfix. Some scanners can strip the prefix from the data, but I use the prefix in the event code and it is stripped off there.
  1. Helpful
  1. Nguyen Xuan Huy
  2. Sunday, 18 July 2021 09:10 AM UTC
@Christopher Altvater

Thank you , I have tried, but the key event of window object does not fire when users focus on a data window control.

- scanner allows to configurate with a different prefix and postfix, I think it ok to check, but only brand name scanner have these features.



Regards

Huy
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.