简体   繁体   English

python、arduino和无毛MIDI之间的串行通信

[英]Serial communication between python, arduino and hairless MIDI

I want to send a message from python via serial to arduino uno and then from arduino to hairless MIDI to control LMMS software.我想通过串行从 python 向 arduino uno 发送消息,然后从 arduino 向无毛 MIDI 发送消息以控制 LMMS 软件。 The problem is that the communication in both cases goes through port COM4.问题是这两种情况下的通信都通过端口 COM4。 Is it somehow possible to get data from python through a different port?是否有可能通过不同的端口从 python 获取数据?

Python code: Python代码:

import serial

ser = serial.Serial('COM4', baudrate = 9600, timeout = 1)

def getValues(input):
    if(input == 'y'):
        ser.write(b'g')
    else:
        ser.write(b'h')


while(1):
    userInput = input('Get data point?')
    getValues(userInput)

Arduino code: Arduino 代码:

char userInput;

void setup() {
  Serial.begin(9600);
}

void loop() {
  if(Serial.available()>0){
    userInput = Serial.read();
    if(userInput == 'g'){
      Serial.write(144);
    }
    else if(userInput == 'h'){
      Serial.write(0);
    }
  }
}

Python and Hairless MIDI cannot communitcate with Arduino over the same COM port simultaneously. Python 和 Hairless MIDI 无法通过同一个 COM 端口同时与 Arduino 通信。

You would have to open and close the connection in each software alternatingly.您必须交替打开和关闭每个软件中的连接。

I suggest you use a Python MIDI library that replaces the Hairless MIDI functionality.我建议您使用 Python MIDI 库来替代 Hairless MIDI 功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM