I try to access the SerialPort “xy” from the “write” component I am trying to write. I know it works already fine in FireFly, but for learning purposes I’d like to code it myself. Seeing that Firefly unowriteelement is just requiring the port and start boolean, I am not sure how to access the opened port without creaating a new one that ends up messing with the xy port.
However, if I try and make the SerialPort public, I am not sure how to access it from the other element.
thanks in advance
I believe you simply feed the port number into the open port component so that you have a separate one for each port you want to connect.
Thanks for your reply Christopher!
I may have not been very clear when describing my problem, as I am not looking for opening several ports:
the available port element just provides a list of available ports as string. (in this case only COM5 is available)
the open port element constructs a serialPort and opens the port by name:
SerialPort xy = new SerialPort(“COM5”);
now the write element: should look like this: xy.writeLine(“someString”)
but I cant acccess xy and if I try and construct a new SerialPort in the write element, it would conflict with xy already opened SerialPort.
is this question more clear?
thanks in advance
I think I’m starting to understand.
You are building your own tx component.
You want to send the port information to the tx, or for the tx to automatically know what port is connected?
Since I don’t know what the inputs to your tx component are:
In the openPort component, you create a public variable called xy for the serial port.
In the tx component, you search the canvas for the open port component and read that xy serial port.
You create a serialPortGoo = gh_goo
You then create a SerialPortParam = GH_param
You then output SerialPortParam from your openport component and input it into your tx component.
I’ll try to post an example in 10 hours or so as I’m about to head to work.
yes, exactly. I tried to copy the functions from firefly, where the unowrite component corresponds to my tx component. I added some params to mine to make some trials, but ended up like you kindly described in option 1 to create a public serialPort xy.
Guess I could give it a try, should have all necessary snippets lying aroung, but its late here, I’ll try tomorrow. I thought of this already but was used a generic parameter and option 1 I was a bit tired of trying without having even a hint where I’m going. only step thats missing is option1step2.
Thank you very much for pointing the right direction, it saves me sooo much time and nerves:smiley:
And thank you for having taken the time to understand my question.
Good start into your day
From one of my older scripts, the Guid should be the openPort one. Note that this means you can only have one openport component per script.