Assign a Serial Port to a specific Serial Device


    Oct 15 2007 | 10:48 am
    Hello List!. I think that I have read threads about this issue in the past, but I don’t find them right now … I would like to know the best way to assign serial devices to serial ports via max in a dynamic way. In other words, I would like to know a system in OSX and Windows to control via max the assignation of serial Devices to Serial ports. In my case I want to use 4 Arduinos and assign them always to the same ports in any computer. I need this function to: 1. Never lose the assignation in a long term interactive installation. Example: if anyone disconnect - connect serial devices in different order … etc. 2. Always assign the devices correctly when you change from one computer to another. I hope I have made myself clear ,-) I understand the use of the message print to create menus of serial ports available, and the use of port message to select-open them. What I don’t find is an automatic (software controlled) way to assign a specific device to a specific port. I know how to do this by hand in the OS, but not from max. How do you manage this? Many thanks for your time and help. Cheers. Felix

    • Oct 15 2007 | 9:16 pm
      Felix,
      Sorry I can't give you a definitive answer, but I don't think it's possible to do what you describe. Until someone more knowledgable than myself says otherwise I think you should work on the assumption that the serial port is assigned on a pot luck basis.
      You seem to already be aware of the solution I am about to propose of using the print message and the "port a/b/c..." message. I can see why hardwiring the port assignment would be more reliable but I offer this solution as something I happen to have lying around.
      Below is a piece of code that I wrote to do the assigning automatically. Unfortunately, your arduino devices will need to show up with different names in the list produced by the print message. Maybe they already do show up differently, but if not you probably have to do some thing like hack their firmware to give them unique names.
      Another less than ideal solution for differentiating them would be to wire two spare sensor inputs on each arduino in such a way as to give them each their own binary number. ie 0-0 0-1 1-0 1-1
      Sorry if this doesn't answer your question!
      good luck Peter
    • Oct 15 2007 | 9:49 pm
      felix
      you can put in the name of the specific device instead of a letter a, b,c in the serial object. if you have bluetooth connections to you devices you can just do an AT command and set a specific name, and set the serial port to that name. or, set different headers before the array of bytes in your serial stream from your devices , and route them through the serial object, and assign the header to a port. hope its somewhat clear good luck -eva
      Peter Reid wrote: > Felix, > > Sorry I can't give you a definitive answer, but I don't think it's possible to do what you describe. Until someone more knowledgable than myself says otherwise I think you should work on the assumption that the serial port is assigned on a pot luck basis. > > You seem to already be aware of the solution I am about to propose of using the print message and the "port a/b/c..." message. I can see why hardwiring the port assignment would be more reliable but I offer this solution as something I happen to have lying around. > > Below is a piece of code that I wrote to do the assigning automatically. Unfortunately, your arduino devices will need to show up with different names in the list produced by the print message. Maybe they already do show up differently, but if not you probably have to do some thing like hack their firmware to give them unique names. > > Another less than ideal solution for differentiating them would be to wire two spare sensor inputs on each arduino in such a way as to give them each their own binary number. ie 0-0 0-1 1-0 1-1 > > Sorry if this doesn't answer your question! > > good luck > Peter > > > > > #P toggle 27 74 15 0; > #P window setfont "Sans Serif" 9.; > #P window linecount 1; > #P newex 27 96 57 196617 qmetro 10; > #P button 140 36 69 0; > #N vpatcher 618 411 1218 811; > #P window setfont "Sans Serif" 9.; > #P number 51 178 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; > #P newex 50 158 31 196617 + 97; > #P newex 50 137 27 196617 i; > #P message 195 91 33 196617 set 0; > #N counter; > #X flags 0 0; > #P newobj 184 115 66 196617 counter; > #P newex 50 93 30 196617 t s b; > #P newex 50 72 47 196617 zl iter 1; > #P newex 50 115 107 196617 sel YOURDEVICENAME; > #P newex 50 50 56 196617 route port; > #P inlet 195 71 15 0; > #P inlet 50 30 15 0; > #P outlet 51 198 15 0; > #P comment 92 158 339 196617 make this into the corresponding ascii letter for the relevant serial port; > #P window linecount 4; > #P comment 274 36 120 196617 find the desired device name in the list of devices and output the corresponding port letter; > #P connect 3 0 5 0; > #P connect 5 0 7 0; > #P connect 7 0 8 0; > #P connect 8 0 6 0; > #P connect 6 0 11 0; > #P connect 11 0 12 0; > #P connect 12 0 13 0; > #P connect 13 0 2 0; > #P fasten 9 0 11 1 189 134 72 134; > #P fasten 8 1 9 0 75 112 189 112; > #P fasten 10 0 9 0 200 111 189 111; > #P connect 4 0 10 0; > #P pop; > #P newobj 152 179 64 196617 p finddevice; > #P newex 45 122 80 196617 sprintf port %c; > #P newex 140 121 96 196617 t print b; > #P newex 45 159 77 196617 serial a 57600; > #B color 5; > #P connect 5 0 0 0; > #P connect 6 0 5 0; > #P connect 4 0 1 0; > #P fasten 1 0 0 0 145 153 50 153; > #P fasten 2 0 0 0 50 153 50 153; > #P fasten 3 0 2 0 157 202 128 202 128 119 50 119; > #P fasten 0 1 3 0 117 178 157 178; > #P connect 1 1 3 1; > #P window clipboard copycount 7; > > -- > http://www.peterreid.org/code/ > >
    • Oct 16 2007 | 1:35 pm
      Hi Peter and Eva. Thanks for sharing ,-) I think that Eva's second idea is interesting, but if i understand correctly there could still be a problem because the 4 serial max objects have to point always to the 4 arduinos (and not to other serial devices). If one of the 4 open ports in max(in 4 serial objects) points to other devices, then it doesn't work correctly.
      If the 4 ports point to the 4 arduinos, then it doesn't matter which port is which arduino, because i use headers to route each arduino's data.
      I'm getting it right?.
      In any case i would like to ask you both for a confirmation about how computers manage serial devices: when you connect a new device to a computer they assign automatically a new free port (ex:COM2), and then whenever you reconnect that device to the same computer, she will always assign the same serial port or name (thanks to the firmware serial number of the device). Is this correct? Thanks again. Felix