tofergregg / IBM-Wheelwriter-Hack

Turning an IBM Wheelwriter into a unique printer
MIT License
100 stars 11 forks source link

unicode strings not supported on MacOS #14

Open ffd8 opened 4 years ago

ffd8 commented 4 years ago

Perhaps I'm making an amateur mistake... have the Nano + hardware all setup onan IBM 6747-2, but running into trouble while trying to test with your python scripts on MacOS 10.13.6, getting the following error (i'm using a nano clone, but that shouldn't be the issue, since code uploaded without problem):

➜  python_scripts python actualTypewriterNano.py
Please choose a port:
    1) /dev/tty.Bluetooth-Incoming-Port
    2) /dev/tty.wchusbserial1430
2
Traceback (most recent call last):
  File "actualTypewriterNano.py", line 104, in <module>
    ser.write(chr(event))  # send one byte
  File "/usr/local/lib/python3.7/site-packages/serial/serialposix.py", line 532, in write
    d = to_bytes(data)
  File "/usr/local/lib/python3.7/site-packages/serial/serialutil.py", line 63, in to_bytes
    raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))
TypeError: unicode strings are not supported, please encode to bytes: 'h'

Is it because I'm using python 3? (i'm not so familiar with python...) – also tried just your testSend.py, but get the following similar error:

python_scripts python testSend.py
Traceback (most recent call last):
  File "testSend.py", line 13, in <module>
    ser.write(a)
  File "/usr/local/lib/python3.7/site-packages/serial/serialposix.py", line 532, in write
    d = to_bytes(data)
  File "/usr/local/lib/python3.7/site-packages/serial/serialutil.py", line 63, in to_bytes
    raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))
TypeError: unicode strings are not supported, please encode to bytes: '\x1e\x00abcdefghijklmnopqrstuvwxyz\nabc'

Do you know a solution? Have you considered making a basic demo for talking to the Nano controller via Processing?? That's more my strength.. have done serial for plotters + thermal printers.. so I'll explore that next, but curious if you already had any tests laying around to get started?

ffd8 commented 4 years ago

Ahha.. found two problems!

Tried changing some of the python scripts to use .encode() on strings for unicode.. but then the actualTypewriter.py script could only write one char before quitting with an error of: TypeError: a bytes-like object is required, not 'str'

Starting to play in Processing and successfully have really basic typewriter(!) without any bells/whistles using:

import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;        // Data received from the serial port

void setup() 
{
  size(200, 200);
  myPort = new Serial(this, "/dev/cu.wchusbserial1430", 115200);
}

void keyPressed() {
  if(keyCode != 16){
    myPort.write(key+"");
  }
}

void draw() {
  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
    println(val);
  }
}