Block with dropdown who's list is populated by Serial port list.

0 views
Skip to first unread message

Adam Bryant

unread,
4:41 AM (2 hours ago) 4:41 AM
to blo...@googlegroups.com
Sorry I am not sure how to word this.

I have a python function that list active serial ports and assigns them to the variable IFACE_1/IFACE_2/IFACE_n

How do I create a block that will create a dropdown menu populated but this list.

// {
// "type": "additional_interface_b_init",
// "message0": "Initialise aditional Interface B: %1",
// "args0": [
// { "type": "field_dropdown", "name": "NAME", "text": "IFACE_1" },
// { "type": "field_dropdown", "name": "NAME", "text": "IFACE_2" }
// ],
// "previousStatement": null,
// "nextStatement": null,
// "colour": 20,
// },

//py.forBlock['additional_interface_b_init'] = (block) => {
// const name = block.getFieldValue('NAME');
// const port = getInterfaceMapping()[name] || "/dev/ttyUSB0";
// return `import serial, time\nif 'ifaces' not in globals(): ifaces = {}\nif '${name}' not in ifaces:\n ifaces['${name}'] = {'ser': serial.Serial('${port}', 9600, timeout=0)}\n ifaces['${name}']['ser'].write(b'p\\0###Do you byte, when I knock?$$$')\n time.sleep(0.1)\n`;
//};

I have tried this but it means I have to populate the list first on the assumption that their could be these ports.

Can someone point me in the correct direction please?
Reply all
Reply to author
Forward
0 new messages