Re: [Tutor] Converting a string to a byte array

2017-09-25 Thread Phil
On 26/09/17 07:02, Cameron Simpson wrote: Just to this. If your serial file handle is a normal buffered one, you may also need to call .flush(). When you run from the command line as "python3 mycode.py" is done automatically at programme exit. In the IDE, the programme has not exited, so your

Re: [Tutor] Converting a string to a byte array

2017-09-25 Thread Cameron Simpson
On 25Sep2017 09:29, Phil wrote: [...] Just for interest I amended my code to use what you provided and tried it under IDLE. There aren't any errors but but my Arduino is not responding. However, if I enter python3 mycode.py then it works perfectly. I'm sure there's an explanation for this. Ju

Re: [Tutor] Converting a string to a byte array

2017-09-24 Thread Cameron Simpson
On 25Sep2017 09:29, Phil wrote: On 25/09/17 07:26, Cameron Simpson wrote: I don't understand why this works from the pyqt IDE but not when run from the console. I suppose the IDE is adding the correct encoding. I'm guessing the IDE is python 2 and not doing any encoding at all. In python 2 s

Re: [Tutor] Converting a string to a byte array

2017-09-24 Thread Phil
On 25/09/17 07:26, Cameron Simpson wrote: Thank you Cameron and Peter for your replies. I don't understand why this works from the pyqt IDE but not when run from the console. I suppose the IDE is adding the correct encoding. I'm guessing the IDE is python 2 and not doing any encoding at all. I

Re: [Tutor] Converting a string to a byte array

2017-09-24 Thread Cameron Simpson
On 24Sep2017 20:24, Phil wrote: I'm trying to do the same under pyqt but I'm having trouble converting a string to a byte array. This works correctly from the pyqt IDE but not from the console. python3 mycode.py generates "typeError: string argument without an encoding" Is it possible your p

Re: [Tutor] Converting a string to a byte array

2017-09-24 Thread Peter Otten
Phil wrote: > Thank you for reading this. > > The following code sends "Fred" to my serial connected device without > any problems. > > import serial > > ser = serial.Serial('/dev/ttyACM0',9600) > ser.write(b'Fred\n') > > > I'm trying to do the same under pyqt but I'm having trouble convertin

[Tutor] Converting a string to a byte array

2017-09-24 Thread Phil
Thank you for reading this. The following code sends "Fred" to my serial connected device without any problems. import serial ser = serial.Serial('/dev/ttyACM0',9600) ser.write(b'Fred\n') I'm trying to do the same under pyqt but I'm having trouble converting a string to a byte array. This