ProXR python - relay on - problem

I am using proxr and i want to enable the relay using python 3.
I added the library from
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)

and I got this error:

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

~\ 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))
23 def turn_off_relay_by_index(self, relay):

~\ 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
114 else:

~\AppData\Local\Continuum\anaconda3\lib\site-packages\serial\ 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\ 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,

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!