# Creating new objects in a module

**URL:** <https://forum.inductiveautomation.com/t/creating-new-objects-in-a-module/32146>\
**Category:** Module Development\
**Created:** [February 11, 2020, 8:47pm UTC](https://forum.inductiveautomation.com/t/creating-new-objects-in-a-module/32146 "2020-02-11T20:47:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bebel](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bebel](https://forum.inductiveautomation.com/u/bebel)\
**Post date:** [February 11, 2020, 8:47pm UTC](https://forum.inductiveautomation.com/t/creating-new-objects-in-a-module/32146/1 "2020-02-11T20:47:41Z")

</div>

I have created a serial comm module and so far I can read and write data but only for one port. The issue is that in the module class I have a static port as follows:  
private static SerialPort myPort;  
Once I configure that port it is associated with one of the ports on the client computer.  
public int configurePort(  
@ScriptArg(“PortName”) String Name,  
@ScriptArg(“BaudRate”) int BaudRate,  
@ScriptArg(“DataBits”) int DataBits,  
@ScriptArg(“StopBits”) int StopBits,  
@ScriptArg(“Parity”) int Parity) {  
int result = -1;  
try {  
myPort = SerialPort.getCommPort(Name);  
myPort.setComPortParameters(BaudRate, DataBits, StopBits, Parity);  
result = 1;  
} catch (Exception e) { e.printStackTrace(); }  
return result;  
}  
Is there a way to dynamically create new objects (ports) in the module instead so that I can use more than one serial port at a time or is there a more proper way to be doing this in the first place? In my past C# experience I would create a serial port object in the program but I don’t think this is possible with Ignition.  
The only thing I can think of myself is to create an array of a static class with a name and serial port, then fill in the name with the system name of each serial port of the client so that I can select which one to interact with in each method.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 11, 2020, 8:51pm UTC](https://forum.inductiveautomation.com/t/creating-new-objects-in-a-module/32146/2 "2020-02-11T20:51:18Z")

</div>

Keep a `Map<String, SerialPort>`. Create and put new serial ports into it when one doesn’t exist, otherwise get the existing one. Make sure to remove them on shutdown.
