我在项目中使用滑块。这些改变,我发送我的stm32侧和驱动马达。我的stm32侧面采用角度类型ascii,但是pyserial侧发送整数,我想在我的滑块值上发送54度并且pyserial发送90的ascii类型6我该怎么做?
def servoGripperFunc(self):
print "gripper buttonuna basildi"
def sliderMoveFunc(self):
print "Slider 1:"
print self.horizontalSlider.value()
ser = serial.Serial('/dev/ttyUSB0')
print(ser.name)
if ser.isOpen():
print(ser.name + ' is open')
size=(self.horizontalSlider.value())
dgr=ord(size)
ser.write(str(dgr))
time.sleep(1)
#print "Slider 2:"
#print self.horizontalSlider_2.value()
#print "Slider 3:"
#print self.horizontalSlider_3.value()
#print "Slider 4:"
#print self.horizontalSlider_4.value()
if __name__ == "__main__":
app = QtGui.QApplication([])
myWindow = MyWindowClass()
myWindow.setWindowTitle("PyServo for " +
platform.system() + " v." + software_version)
myWindow.setVisible(True)
myWindow.pushButton.clicked.connect(lambda: myWindow.servoGripperFunc())
myWindow.horizontalSlider.sliderMoved.connect(lambda: myWindow.sliderMoveFunc())
myWindow.horizontalSlider_2.sliderMoved.connect(lambda: myWindow.sliderMoveFunc())
myWindow.horizontalSlider_3.sliderMoved.connect(lambda: myWindow.sliderMoveFunc())
myWindow.horizontalSlider_4.sliderMoved.connect(lambda: myWindow.sliderMoveFunc())
# Start the window centered in screen
screenGeometry = app.desktop().screenGeometry()
x = (screenGeometry.width() - myWindow.width()) / 2
y = (screenGeometry.height() - myWindow.height()) / 2
myWindow.move(x, y)
app_exec_code = app.exec_()
app.quit()