开云体育

How do I hook up a bar code reader to JMRI


 

I want to use a barcode reader to identify cars on my layout, but I can't find a way to read the code into JMRI. I've reviewed other bar code topics from this group in the past but none answered my question.
?
One way I've tried is to use a Reporter. I'm using an iMac running macOS Monterey. When I connect the bar code reader to the USB port, I can see it in the Mac system report and in JMRI>PanelPro>Debug> USB devices. However, when I try to create the Reporter using 'others' as the system manufacturer and (Direct Drive (Serial) not available), the USB port does not show in the serial port drop down. I can't get past this problem.
?
Another way I've tried is to use a Memory Variable. I can read the bar code into the value field if my cursor is in that field. But I don't known how to select that field without a cursor. I don't need to identify a port, as the bar code reader just acts like a keyboard, entering a 4-digit number and <enter>. I've never tried manipulating JMRI windows and am not sure how to activate a particular field in one.
?
I'm creating Jython script to accept the bar code using the waitChange command (for the Reporter) and then process it. But as I said I'm stuck trying to get the bar code inside JMRI. The Reporter track is preferred, I think, since I will be using two bar code readers eventually and I can have two reporters attached to two different connection ports. I don't know how I would do this using a Memory Variable.
?
Can someone help me out?
?
Thanks, Nick


 

I'm using PanelPro 5.11.2.
?
Nick


 

开云体育


My approach would be to look at two routes and decide the easier one:?

a)? use an existing serial device for reporter type, and make the bar-code reader's output fit the format expected from that device.? ??
b)? take the bar code reader's output, and feed that to an MQTT broker (eg. Mosquitto, which could run on your iMac).? ?Then use the MQTT connections inside JMRI to read the data from the MQTT broker.? ?If the data are not yet in "reporter form", there are methods within LogixNG which could help translate things.??


- Nigel


------ Original Message ------
From "Nick Brownsberger via groups.io" <nbrownsbe@...>
Date 05/05/2025 16:07:12
Subject [jmriusers] How do I hook up a bar code reader to JMRI

I want to use a barcode reader to identify cars on my layout, but I can't find a way to read the code into JMRI. I've reviewed other bar code topics from this group in the past but none answered my question.
?
One way I've tried is to use a Reporter. I'm using an iMac running macOS Monterey. When I connect the bar code reader to the USB port, I can see it in the Mac system report and in JMRI>PanelPro>Debug> USB devices. However, when I try to create the Reporter using 'others' as the system manufacturer and (Direct Drive (Serial) not available), the USB port does not show in the serial port drop down. I can't get past this problem.
?
Another way I've tried is to use a Memory Variable. I can read the bar code into the value field if my cursor is in that field. But I don't known how to select that field without a cursor. I don't need to identify a port, as the bar code reader just acts like a keyboard, entering a 4-digit number and <enter>. I've never tried manipulating JMRI windows and am not sure how to activate a particular field in one.
?
I'm creating Jython script to accept the bar code using the waitChange command (for the Reporter) and then process it. But as I said I'm stuck trying to get the bar code inside JMRI. The Reporter track is preferred, I think, since I will be using two bar code readers eventually and I can have two reporters attached to two different connection ports. I don't know how I would do this using a Memory Variable.
?
Can someone help me out?
?
Thanks, Nick


 

NIck,

What reader hardware are you using?

Dave Sand



----- Original message -----
From: "Nick Brownsberger via groups.io" <nbrownsbe=[email protected]>
Subject: [jmriusers] How do I hook up a bar code reader to JMRI
Date: Monday, May 05, 2025 10:07 AM

I want to use a barcode reader to identify cars on my layout, but I can't find a way to read the code into JMRI. I've reviewed other bar code topics from this group in the past but none answered my question.
?
One way I've tried is to use a Reporter. I'm using an iMac running macOS Monterey. When I connect the bar code reader to the USB port, I can see it in the Mac system report and in JMRI>PanelPro>Debug> USB devices. However, when I try to create the Reporter using 'others' as the system manufacturer and (Direct Drive (Serial) not available), the USB port does not show in the serial port drop down. I can't get past this problem.
?
Another way I've tried is to use a Memory Variable. I can read the bar code into the value field if my cursor is in that field. But I don't known how to select that field without a cursor. I don't need to identify a port, as the bar code reader just acts like a keyboard, entering a 4-digit number and <enter>. I've never tried manipulating JMRI windows and am not sure how to activate a particular field in one.
?
I'm creating Jython script to accept the bar code using the waitChange command (for the Reporter) and then process it. But as I said I'm stuck trying to get the bar code inside JMRI. The Reporter track is preferred, I think, since I will be using two bar code readers eventually and I can have two reporters attached to two different connection ports. I don't know how I would do this using a Memory Variable.
?
Can someone help me out?
?
Thanks, Nick


 

Its a Symcode reader. Not very expensive. Nick


 

Nigel,
?
The reader I have is not programmable. It simply reads into whatever app I have selected as if it were a keyboard.
?
Haven't worked with MQTT before. I'll have to look into it.
?
Nick


 

开云体育


So, in principle...? ?you could write something in Python (or similar) which takes the readings, and then "publishes" a message to MQTT.? ? If that message were to a path such as "../mylayout/reporters/reporter01" and contained the text value "123AB123" (or whatever your barcode said),? then you're just about home and done as JMRI can subscribe to those messages and will treat them as reporter messages.

Question is how much of a learning curve are the two key steps:? (a) installing a MQTT broker, and (b) code-writing to get the above to work.??
?

- Nigel


------ Original Message ------
From "Nick Brownsberger via groups.io" <nbrownsbe@...>
Date 05/05/2025 18:19:05
Subject Re: [jmriusers] How do I hook up a bar code reader to JMRI

Nigel,
?
The reader I have is not programmable. It simply reads into whatever app I have selected as if it were a keyboard.
?
Haven't worked with MQTT before. I'll have to look into it.
?
Nick


 

Nigel,
?
I tried reading directly into a Jython program using the input command. (I didn't exactly use that command, but the safer command the name of which I can't remember right now.) But I couldn't get that to work either. I think what you suggested earlier regarding MQTT might be a better approach. I'll look into that tonight.
?
Any ideas why I can't see the USB connection when adding a Reporter.
?
Or, could I use the RFID input connection to read from a bar code reader to an IDtag?
?
Nick


 

开云体育

Nick,

?

My rough thought is that you write a script that opens the device. Look at the FileLogging.py for an example of opening a file/device. The script would then handle the input stream and make reporters or whatever you want done with it.

?

?

-Ken Cameron, Member JMRI Dev Team

?

?


 

开云体育

Nick,

?

JMRI only looks for certain types of names for the devices that it shows you. On some systems you can add what amounts to a search key for finding other devices to offer. But even if the device name is offered, the system connection will limit what it does with it. Unless the device you had sends a matching message format to something the system connection knows, it won’t go anywhere.

?

-Ken Cameron, Member JMRI Dev Team

?

?


 

Nigel, Ken,
?
My device only connects to a USB port on my Mac. When it reads a bar code it sends a 4-digit code, i.e. 0123, followed by <enter>. If I have a spreadsheet open, when the code is read it fills the active cell with the 4-digit code and moves down to the next cell (in my Excel spreadsheets, using the enter keys moves to the next cell down). I can read as many bar codes as I want, moving down the spreadsheet each time.
?
I just haven't found a way for it to read into something in PanelPro that I can take action on.
?
Also, for the reason just mentioned, I don't think MQTT will work since its not a wireless device. And it sounds like I need to buy a piece of hardware to implement MQTT.
?
Thanks for continuing to help.
?
Nick


 

开云体育

That’s why I said a script that opens the port for reading. JMRI proper doesn’t even know about it. You just have to code to open the device name. For Windows, that’s a COM something. For Mac or Linux, that’s going to be a /dev/ something. That script will figure out what to do with that four digit code. But since that code is running inside of JMRI, it knows all the tables of things in JMRI.

?

-Ken Cameron, Member JMRI Dev Team

?

?


 

开云体育

Nick

like most things inside JMRI there are at least half a dozen ways of getting to the end.? Ken's suggested scripts method is one.? ?
I prefer to do processing either in LogixNG or outside of JMRI (hence suggesting python) as I find it quicker/easier to change things "on the fly", rather than staring at a JMRI script wondering "why did that not work".? ?

Sticking with stuff that might work straight out of JMRI.? There's some USB stuff (labelled as deprecated because the library underlying it isn't supported, so caution over it as it may stop working with an update, and doesn't work on new processor Macs already) which shows reading serial input to a Memory Variable.? If you've got that far, then LogixNG could monitor the memory variable for change, and write a new Reporter message with the report value taken from the memory variable.??



MQTT doesn't need wireless, nor do you need to spend any money.? ?MQTT is purely a data transfer mechanism, and will work on a single machine (with a sort of network connection internally in the machine from the machine to itself).? Or, will work over a wired, or wireless network.? ? If heading that way, you'll need:?
a)? MQTT Broker (server) software, typically that's "Mosquitto" because it's well documented and free.?
b) Something to take your current serial input and publish it on the broker on a path that will be collected by JMRI.? That's a python script (or any other language you're comfortable with running on your existing computer .?
c)? JMRI connection to the MQTT broker (in preferences).? Its fine to have multiple connections in preferences.?
And that's it.? ??

Yes, MQTT is often used for devices connected via WiFi, but that's just one thing that can be done with it.??




- Nigel


------ Original Message ------
From "Nick Brownsberger via groups.io" <nbrownsbe@...>
Date 05/05/2025 21:42:23
Subject Re: [jmriusers] How do I hook up a bar code reader to JMRI

Nigel, Ken,
?
My device only connects to a USB port on my Mac. When it reads a bar code it sends a 4-digit code, i.e. 0123, followed by <enter>. If I have a spreadsheet open, when the code is read it fills the active cell with the 4-digit code and moves down to the next cell (in my Excel spreadsheets, using the enter keys moves to the next cell down). I can read as many bar codes as I want, moving down the spreadsheet each time.
?
I just haven't found a way for it to read into something in PanelPro that I can take action on.
?
Also, for the reason just mentioned, I don't think MQTT will work since its not a wireless device. And it sounds like I need to buy a piece of hardware to implement MQTT.
?
Thanks for continuing to help.
?
Nick


 

On May 5, 2025, at 4:07?PM, Nick Brownsberger via groups.io <nbrownsbe@...> wrote:

Any ideas why I can't see the USB connection when adding a Reporter.
It sounds like your device is more like a USB keyboard than a USB serial port.

USB supports several different types of devices. Serial ports and Human Interface Devices (HIDs, like keyboards, mice and gamepads) use completely differnt sets of commands on the USB cable. Code that expects one can’t communicate with the other, and vice versa.

Since you’re device is acting like a keyboard, there’s no point in trying to treat it as a serial device. That’s why trying to open it as a COM port isn’t going to work: It’s not a serial device, and WIndows is not going to see it as one, so there’s no corresponding COM port to connect to (and simillar for macOS or Linux)

I think you’re going to permanently have to have a data entry field open for it to put it’s keyboard input into. And that’s going to be very inconvenient.

Bob

Bob Jacobsen
rgj1927@...


 

Thanks everyone,
?
The bar code reader does act like a keyboard, so, Bob, that clears up several of my questions and a lot of confusion. It sounds like I need to handle the input of the from the reader outside of JMRI first. I'll take another look at MQTT and Mosquitto. I suspect I'll have more questioned.
?
Thanks to everyone for helping!!
?
Nick


 

开云体育

Nick,

?

Check in device manager when you plug it in. Some devices make multiple entries so they might be used multiple ways. If it creates a COM device (windows) then you have lots of options for how to deal with it. If not, then you have a bit more work with what library or driver you might need to make the connection.

?

-Ken Cameron, Member JMRI Dev Team

?

?