Class Device encoding BUG #4
Unanswered
AdrianDi91
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Dear Python for the Lab Community,
I followed the steps of the book PFTL until the End of Chapter 3.5.1 (page 35-39) but my connection to the Arduino Due is not working.
Not only that I was copying/writting the code from the book also the GitHub Version is not working in my case. Moreover it causes the same problem independent if it is running in windows or linux. I tried to find the problem by print debugging and the code looks like this now:
import serial
from time import sleep
class Device:
DEFAULTS = {'write_termination': '\n',
'read_termination': '\n',
'encoding': 'Ascii',
'baudrate': 9600,
'read_timeout': 1,
'write_timeout': 1,
}
dev = Device('COM12') #<---- Remember to change the port
dev.initialize()
serial_number = dev.idn()
print(f'The device serial number is: {serial_number}')
volts = dev.get_analog_input(0) #Analog input and output must have the same number
print(volts)
dev.set_analog_output(0, 1000)
volts = dev.get_analog_input(0)
print(volts)
dev.finalize() #Close communication"""
As seen in the picture the line "ans = int(ans)" causes trouble because I cannot transform an empty variable into an integer. Somewhere before the problem was happening by the encoding or decoding I guess?
Thank you for the support.
Beta Was this translation helpful? Give feedback.
All reactions