matt-dale / rf-explorer-python-api

OUTDATED PACAKGE: USE THIS
https://github.com/RFExplorer/RFExplorer-for-Python/wiki
13 stars 6 forks source link

Serial open needs Linux testing #1

Open rbw42 opened 10 years ago

rbw42 commented 10 years ago

Hi, I've just been trying this on a linux and mac laptop. The design of the constructor for the RFExplorer class unfortunately won't work on linux or mac. The serial device created by the driver is called something like '/dev/ttyUSB0' on linux and '/dev/cu.SLAB_USBtoUART' on a mac (osx 10.8). The code to open the serial device ser = serial.Serial(int(port-1)) appears to be internally translated to something like '/dev/ttySx' on linux and '/dev/cuadx' on a mac (where 'x' is port-1). So the integer-based way of specifying the serial device just doesn't work.

What does seem to work is opening the serial device with the correct name of the filesystem object, like ser = serial.Serial('/dev/ttyUSB0') on linux. If you want to keep the integer device specification, how about (for linux/mac) using it as an index into the list returned by list_serial_ports() and instead of doing ser = serial.Serial(int(port-1)) do devs = list_serial_ports() ser = serial.Serial(devs[port]) or something like that? It seems that the RFExplorer serial device always appears last in that list, so you could even have the port ID default to -1 so it picks the last item in the array by default if it is not specified.

Hope this is useful.

Cheers, Randall.

matt-dale commented 10 years ago

Thanks for the testing and the input. Good catch! I only ever tested on Windows and OS10.6.8.

I created a new branch to test the new method of instantiating the class. Please see the RFExplorer-Linux-and-Mac-init- branch with new methods getRFExplorerPort() using Randall's suggestion and an updated exampleScript.py.

The RFExplorer class needs the port name as a string, or the port number as an int.

I have no way of testing this today, but let me know if you can.

Thanks again, -Matt

rbw42 commented 10 years ago

Hi Matt, I just tested this on my mac laptop and it seems to work fine. I also had to change the serial baudrate to 500000 rather than the 2400 that is currently in the code. (My unit has this rate set as default and the RFExplorer manual seems to suggest that one doesn't change it to 2400 unless you have a good reason. Maybe this has changed over time.) Either way, since only those two settings are explicitly supported, you could potentially try one in initialize_RFE_connection() and try the other if it fails. Cheers, Randall.

matt-dale commented 10 years ago

Hi Randall,

Thanks again. In my production code, I am using 500 kbps, so I must have used the 2400 for testing. I've merged the changes into the master branch, and updated the readme to reflect the 500 kbps setting.
I have to wait for another RFExplorer to come in (I work for a rental company) until I test some more. Please offer any other suggestions or changes since I wrote this a long time ago for a single purpose. Thanks again,