Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SR30C and move away from pyudev #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

yuzawa-san
Copy link

Great tool here. Not a lot of open source Uniden scanner programming stuff out there. I was looking for something minimalist since I did not feel like paying for that butel.nl tool that most people online seem to recommend.

The main objective was adding the SR30C device. There are a few quirks:

  • It uses the same BC125AT protocol, but the unset channel looks like CIN,1,,00000000,,,0,1,0 Even when a channel is set, if the modulation and tone columns are default (when writing CIN,1,,01230000,AUTO,0,0,1,0 it is read back CIN,1,,01230000,,,0,1,0), then the value is not explicitly stated in the CIN data. I updated the regex and parse logic to handle this case.
  • The SR30C uses a different chipset for its USB controller (the CP2104 from Silicon Laboratories). I modified the vendor detection. Also this chipset insists on using a 57600 baud rate. This is not documented anywhere on the internet, but that was the only baud rate that worked in my testing.

Other Issue: Udev appears to be linux only pyudev/pyudev#185 so my Mac did not work with this. I did find that the pyserial library has a way of iterating thru serial ports. I attempted to do a similar scanner discovery process as you have currently. Open question: you check for tty, but my Mac is fine using the cu device instead of the tty device. Is linux more picky about have a tty in particular. I can research this more if we need parity for that. There is no pyserial minimum version in the setup.py but maybe one should be provided since the search functionality seems to be added in a later version (3.0+) https://pyserial.readthedocs.io/en/latest/tools.html Changed in version 3.0: returning ListPortInfo objects instead of a tuple

I have tested this on Mac with a SR30C. I don't have easy access to any other OS's or scanners.

@fdev
Copy link
Owner

fdev commented Jun 26, 2020

Thanks for the pull request! I definitely want to look into removing the pyudev dependency if pyserial now has all the functionality I need, and by the looks of it that's the case.

If the baudrate is automatically detected as well that's even better, especially for supporting different devices.

I'm pressed for time on other projects so I can't fully review and test the code (using my actual scanner) now, but I'll definitely get back to it as soon as possible!

@fdev
Copy link
Owner

fdev commented Aug 9, 2020

My UBC125XLT has died on me a couple of weeks ago. I'm still looking into getting it repaired somehow, so for now I can't test this PR with an actual device.

@gjmvervoort
Copy link
Contributor

Did try the changes on Linux (Fedora 33), seems to work. I was able to import to and export from my UBC125XLT.

@JelmerT
Copy link

JelmerT commented Apr 5, 2021

Would love to test this, but I'm not getting a serial endpoint when plugging in the scanner. Is there a trick to make macOS recognize the vid and pid as a serial device? Or is there a driver I'm not finding? (I'm on 11.2 Big Sur with a BC125AT)

@yuzawa-san
Copy link
Author

I'll have to check again. I recall I was using a KEXT from the scanners usb-controller's chipset manufacturer (dont recall off of the top of my head). I recall that when I upgraded to big sur, the one I was using for the SR30C was flagged as incompatible and removed for a reason I do not remember. I'll have to retest. Or at least maybe clean up the documentation.

@JelmerT
Copy link

JelmerT commented Apr 9, 2021

Looks like the BC125AT (which I have) doesn't have a dedicated usb serial chip, so no standard driver that macOS can use. I wonder if anyone ever got the BC125AT working on macOS.

Copy link
Owner

@fdev fdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took a while but I finally have a working UBC125XLT again, and the time available to take a look at your proposed changes.

There were a bunch more files that needed to be updated, so I created a new branch improvement/pyserial to incorporate the changes from your PR. While reviewing your code there were three sections that raised questions for me.

@yuzawa-san Could you take a look at the comments and verify if the code in my new branch works with your SR30C?

Thanks again for your PR and your patience 🙂

Comment on lines +224 to +225
if not model in SUPPORTED_MODELS:
sys.exit("Got unsupported model: ", model)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check necessary? Only specific combinations of vendor and product id even get here. If the ids match, and we can get a model name, I'm fine with assuming it's a supported model.

Comment on lines +209 to +212
# Fall back to zeroing out the channel
result = self.send("CIN,%d,,00000000,,,0,1,0" % index)
if not result or result != "CIN,OK":
raise ScannerException("Could not delete channel %d." % index)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on why this fallback should be added? The PR description does not mention this addition.

"baudrate": 9600
}
# Silicon Laboratories Vendor (SR30C uses this chipset for its USB controller):
if port.vid == 4292 and port.pid == 60000:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use port.product here as well? port.product == "SR30C" would be more readable in my opinion. Since I don't have an SR30C I can't check the value of port.product for this case.

@jpreiss
Copy link

jpreiss commented Jul 9, 2021

I also had problems with the BC125AT on MacOS Mojave because it doesn't appear as a tty. I hacked together an alternative to class Scanner that talks to the scanner directly over USB using https://github.com/pyusb/pyusb. It can import and export channels on my hardware.

My branch: https://github.com/jpreiss/bc125csv/tree/pyusb. The code is just a proof of concept, it is far from ready for a PR!

@yuzawa-san
Copy link
Author

I've been busy recently, but since my last response, I found that the drivers for the Sr30c and the general support for serial in big sur is quite different than from prior OSX versions. I do think it is a good idea in general to divorce the SR30C logic from the serial upgrades.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants