@Override
public void open(
String portName, ConnectionListener connectionListener, Set<NodeListener> nodeListeners,
Set<MessageListener> messageListeners, Set<TransferListener> transferListeners, final Context context)
throws PortNotFoundException, PortNotOpenedException {
LOGGER.info("Open the serial simulation.");
setConnectionListener(connectionListener);
registerListeners(nodeListeners, messageListeners, transferListeners);
final BidibMessageProcessor messageReceiver = getSimulationMessageReceiver();
if (context != null) {
Boolean ignoreWrongMessageNumber =
context.get("ignoreWrongReceiveMessageNumber", Boolean.class, Boolean.FALSE);
messageReceiver.setIgnoreWrongMessageNumber(ignoreWrongMessageNumber);
}
startReceiverAndQueues(messageReceiver, context);
if (getConnectionListener() != null) {
LOGGER.info("Notify that the port was opened: {}", requestedPortName);
getConnectionListener().opened(requestedPortName);
}
LOGGER.info("The port was opened internally, get the magic.");
try {
int magic = sendResetAndMagic();
LOGGER.info("The root node returned the magic: {}", ByteUtils.magicToHex(magic));
}
catch (ProtocolException ex) {
LOGGER.error("Send reset and magic to root node failed.", ex);
}
}