Barcode scanners (Netum Scan) in python - python

I'm writing code which takes input from several barcode scanners, and I want a way to differentiate between each scanner. I'm on windows 10, and my python version is 3.11.1. And as the title suggests, I'm using scanners from a company called Netum.
I've tried using them as HID devices, but this seems incredibly slow and impractical. If the computer sees them each as keyboards, I have to validate each individual keystroke, rather than entire barcodes. So I've abandoned this approach under that assumption.
I discovered these scanners have what's called "USB COM Port Emulation," and that seems promising. It almost never works, but when it does, it just shoves an entire barcode into my code as a string. The problem is that, most of the time, when it's in this mode, it disconnects the USB dongle the instant I scan anything. But it makes a reference to "needing drivers" for this mode. I checked the device manager, which tells me all my drivers are totally up-to-date. This is really the crux of the problem, as my code works if this mode works reliably.
Also, I'm using PySerial to decode the inputs from the scanners. I dunno if that matters, but I figured I'd mention it. The following is the code I'm using to talk to these janky scanners, and it only works when the scanners don't disconnect from my PC for seemingly no reason.
import serial
scanner = serial.Serial(port='COM3', baudrate=9600, bytesize=8, timeout=1, stopbits=serial.STOPBITS_ONE)
string = scanner.read()
print(string.decode())
scanner.close()
If anyone has any advice, insights, or even just general directions to point me in, it would be appreciated. I'm at the point where I don't even know how to begin solving this.

Comment to answer
Have you installed any Virtual Com Port (VCP) drivers such as from FTDI? ftdichip.com/drivers/vcp-drivers They do a executable for easy install - this may help with your stability issues

Related

Is there a way to use python to automatically attach and detatch a usb connected device when conditions are met?

I am running my dad's busted old laptop (4gb ram) and controlling it remotely. I plan to leave it running to host a filezilla server and pihole, as well as anything else that could be useful.
It's running Linux mint XFCE, if that's helpful.
There's an issue - it gets hot. It's why the device was retired. The fan still runs though. I've improved it a lot by replacing the thermal paste, putting on a lighter OS (see above) and removing unnecessary things like the keyboard and screen, but it's still running hotter then I'd like.
I also have a usb connected laptop cooling pad. It turns on as soon as it is plugged in. The pad is enough to fix the issue.
This is where my question comes in. Would it be possible to write some code to automatically turn the cooling pad on when the laptop reaches a certain temperature and turn it off when it isn't needed?
My coding skills are basic. I can write things like if/then code in python but I cannot reliably create GUIs or access dictionaries.

Translating unix written python for windows to use in RoboDK

I have a script written in python that is used as a driver for a robot in RoboDK. The problem I was having initially was the driver was not recognising the COM port and therefore was not connecting. I’ve solved this by changing the if statement to
if connected is True:
The issue I’m having is, there’s a line of code that reads
data = sys.stdin.readLine()
which I’ve been informed won’t work on windows.
In RDK the program runs and sits at “waiting” but does not progress even when the simulation is run to control the movement of the real robot.
Please keep in mind, although I’ve some experience coding, I’ve never worked directly with a robot or anything of the likes like this, this is for a university project and it seems to be the biggest roadblock so far so any help would be very much appreciated as all web searches so far have been fruitless. Thank you for reading and thank you for any input you may be able to provide.

Pyserial - Embedded Systems

I am not expecting a code here, but rather to pick up on knowledge of the folks out there.
I have a python code - which uses pyserial for serial communication with an Micro Controller Unit(MCU). My MCU is 128byte RAM and has internal memory. I use ser.write command to write to the MCU and MCU responds with data - I read it using ser.read command.
The question here is - It is working excellently until last week. Since yesterday - I am able to do the serial communication only in the morning of the day. After a while, when I read the data the MCU responds with"NONE" message. I read the data next day, it works fine. Strange thing is - I have Hyperterminal installed and it properly communicates with the MCU and reads the data. So I was hoping if anyone have faced this problem before.
I am using threads in my python program - Just to check if running the program mulitple times with threads is causing the problem. To my knowledge, threads should only effect the Memory of my PC and not the MCU.
I rebooted my Computer and also the MCU and I still have this problem.
Note: Pycharm is giving me the answers I mentioned in the question. If I do the same thing in IDLE - it is giving me completely different answers
So, ultimately you're looking for advice on how to debug this sort of time dependent problem.
Somehow, state is getting created somewhere in your computer, your python process, or the microcontroller that affects things. (It's also theoretically possible that an external environmental factor is affecting things. As an example, if your microcontroller has a realtime clock, you could actually have a time-of-day dependent bug. That seems less likely than other possibilities).
First, try restarting your python program. If that fixes things, then you know some state is created inside python or your program that causes the problem.
Update your question with this information.
If that doesn't fix it, try rebooting your computer. If that fixes things, then you strongly suspect some state in your computer is affecting things.
If none of that works, try rebooting the micro controller. If rebooting both the PC and the micro controller doesn't fix things, include that in your question as it is very interesting data.
Examples of state that can get created:
flow control. The micro controller could be sending xoff, clearing clear-to-send or otherwise indicating it does not want data
Flow control in the other direction: your PC could be sending xoff, clearing request-to-send or otherwise indicating that it doesn't want data
Your program gets pyserial into a confused state--either because of a bug in your code or pyserial.
Serial port configuration--the serial port settings could be getting messed up.
Hyper terminal could do various things to clear flow control state or reconfigure the serial port.
If restarting python doesn't fix the problem, threading is very unlikely to be your issue. If restarting python fixes the problem threading may be an issue.

How to use FDTI chip in VCP mode?

I'm trying to get a SainSmart USB relay board based on the FT245RL chip working and having a terrible time. I was under the impression that I could control the relays from the command line with something like:
echo -e -n "\xFF\x1\x1" > /dev/ttyUSB1
While the device is mounted automatically and I think I've got the baud rate and permissions set up, nothing happens on my Debian squeeze or CentOS 5 machines. SainSmart's support is worthless.
I decided to try on windows, so I installed the drivers and wrote a small program in python:
import serial
ser = serial.Serial(2) #COM3
ser.write(chr(255) + chr(0) + chr(1))
ser.close
Still nothing. Perhaps it's a hardware problem so I install a provided windows program. It sees the device and works when I click on the relay buttons. Discouraged, I exit their program, look for bugs in mine (can't find any) but try it anyways, and it works! I write a much bigger program to do all sorts of cool things and cool things happen until I unplug the device. When I plug it back in, nothing works. I've got to run and exit the relay control program before my code will do anything.
I suspect that I've got to do something with d2xx drivers like FT_SetBitMode(). Is there any way to just use VCP mode? PyUSB won't install on my computer and isn't available for Linux.
All I want is a simple way to control a relay on Linux using python.
I had the same problem, I think you were right about FT_SetBitMode(). Eventually I got it to work by using ftd2xx (which you can get by pip). You will also need to install the D2XX drivers.
import ftd2xx
if ftd2xx.listDevices() < 1:
print "No relays found. Exiting..."
exit()
else: print "Initializing relays..."
relays = ftd2xx.open(0)
relays.setBitMode(255,1) # I think this uses FT_SetBitMode()
relays.write(b'\01\01') # relay one on
relays.write(b'\01\01') # relay two on
relays.write(b'\00\00') # all relays off
relays.close()
I would first suggest you to try out hyperterminal first.
From your code snippet it seems that you are missing the baudrate (assuming the rest are going to be the default values). And I don't really know if it matters but I always explicitly set the port as Serial('COM3'), one less possible point of failure this way :)
Probably you don't have a problem with Python, but with controlling the device as such.
You should try to find out if the the device has special requirements about the state of the control lines (DST, DTR etc.).
And, not to forget, the communication speed which Alex already mentions.
Using virtual com ports on Windows I found I had to use 115k baud

Make new software for Windows 95 on 486 machines, what to use?

I have a VB6 application running on a number of old 486 Windows 95 machines and sometimes the application is upgraded. The only way to accomplish this today is to use Hyperterminal and send the file over a null modem cable. Replacing the machines is not an option at this point.
I want to write an application that can take care of transferring the updating app over null modem without rewriting the VB6 app. This means I'm free to use anything I see fit. What alternatives are there?
These are the ones I can think of but I'd like to know if I'm wrong and any pros/cons. Also, I'd prefer to avoid C/C++ if at all possible.
Python with py2exe
Another VB6 app
C/C++
Edit: Some clarifications after reading the comments:
I want to make the process as easy as possible, today we have to remove and dismantle the computer, connect a keyboard and then fire up Hyperterminal to get going. That's why I want something more automatic. I'm open to suggestion of existing solutions but given the specific needs I didn't think there were any.
There is no ethernet on some of the computers either so the solution needs to be able to run RS232.
And again: Replacing the machines is not an option at this point. Just trust me on this.
If you must use a null modem, how about the built in serial line networking support?
Then you can just use normal network methods (psexec, file share, etc) methods to do the update.
Network Method
I would first get network cards installed in everything. If you want something that you can just plugin and go, look for any card compatible with NE2000. That card will work out of the box on Windows 3.11 and 95, no problem. In particular, you can find the 3Com EtherLink II or the 3C509B for very cheap online. It's an excellent card. (The Google Shopping results list several for under $20.)
From there, just enable the Windows File/Print Sharing service over TCP/IP, and you're good to go! After you've done this, you can remotely manage and upgrade these machines, saving you a lot of headache later on.
Serial-Port Method
Deanna's suggestion of using the serial port as a network device and transferring files normally will work as well. However, there is a bit of setup involved, and it can be a hassle if you've never done it. There are several other software options. I recommend LapLink. It's fairly painless.
You could even go all-out and pickup a multi-port serial interface for fairly cheap these days, and manage these computers centrally. RS232 is very robust and can go a long distance over the proper cabling.
Networking over Ethernet is the way to go though. If at all possible, choose that option.
We've got a few testing laboratories in a similar situation-the labs make money for the company so no touching the ancient computers that run the tests under pain of death. :-)
Anyway, pySerial seems like it'd work for this application, maybe take a look at their wxPython examples for some ideas on a GUI.
I guess the answer is pretty simple if you are happy using VB6 and the other app is already VB6, then use it.
That will do whatever serial comms you require quite adequately. Remember though you may want to update the application you write to do the updating in which case you are back to using hyperterminal!

Categories