ProXR python - relay on - problem

Hello.
I am using proxr and i want to enable the relay using python 3.
I added the library from https://github.com/ncd-io/Industrial-Relay-Control
and I also install the pyserial.
then I wrote the code in python:
#import the pyserial module
import serial
import socket
import ncd_industrial_relay as ncd
#set up your serial port with the desire COM port and baudrate.
serial_port = serial.Serial(‘COM159’, baudrate=115200, bytesize=8, stopbits=1, timeout=.5)
#instantiate the board object and pass it the serial port
board1 = ncd.Relay_Controller(serial_port)
board1.turn_on_relay_by_index(1)

and I got this error:

TypeError Traceback (most recent call last)
in ()
----> 1 board1.turn_on_relay_by_index(1)

~\ncd_industrial_relay.py in turn_on_relay_by_index(self, relay)
19 msb = relay >> 8
20 command = self.wrap_in_api([254,48,lsb,msb])
—> 21 return self.process_control_command_return(self.send_command(command, 4))
22
23 def turn_off_relay_by_index(self, relay):

~\ncd_industrial_relay.py in send_command(self, command, bytes_back)
110 command = self.convert_data(command)
111 if self.combus_type == ‘serial’:
–> 112 self.combus.write(command)
113 return self.combus.read(bytes_back)
114 else:

~\AppData\Local\Continuum\anaconda3\lib\site-packages\serial\serialwin32.py in write(self, data)
306 #~ raise TypeError(‘expected %s or bytearray, got %s’ % (bytes, type(data)))
307 # convert data (needed in case of memoryview instance: Py 3.1 io lib), ctypes doesn’t like memoryview
–> 308 data = to_bytes(data)
309 if data:
310 #~ win32event.ResetEvent(self._overlapped_write.hEvent)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\serial\serialutil.py in to_bytes(seq)
61 return seq.tobytes()
62 elif isinstance(seq, unicode):
—> 63 raise TypeError(‘unicode strings are not supported, please encode to bytes: {!r}’.format(seq))
64 else:
65 # handle list of integers and bytes (one or more items) for Python 2 and 3

Any idea why?

Thank you,
Yoni.

Looks like Windows and Mac/Linux handle byte encoding differently. I only tested on Mac/Linux.

I’ll grab a Windows machine and see if I can’t test it later today.

It will hopefully be something simple like statically setting the variables to a bytearray.

So in the library under send_command comment out the line that says self.convert_data(command)

That should solve the issue. I’ll do some additional testing to make sure its cross python2/3 and windows/mac compatible and update the repository.

Thank you very much!