Sending text out over a serial port: Difference between revisions

From MikroTik Wiki
Jump to navigation Jump to search
(dial on demand = no is required for interface to initialize when it is created/enabled)
mNo edit summary
 
Line 2: Line 2:
As RouterOS doesn't (yet?) provide a native command to do that, you can work around with the following little script:
As RouterOS doesn't (yet?) provide a native command to do that, you can work around with the following little script:


  /interface ppp-client add name="scripttemp" dial-on-demand=no port=serial0 modem-init="I am the string" null-modem=yes disabled=no
  /interface ppp-client add name="scripttemp" dial-on-demand=no port=serial0 \
modem-init="I am the string" null-modem=yes disabled=no
  :delay 1
  :delay 1
  /interface ppp-client remove [/interface ppp-client find name="scripttemp"]
  /interface ppp-client remove [/interface ppp-client find name="scripttemp"]

Latest revision as of 09:42, 13 March 2013

Sometimes there's a need to send out some (short) text over a serial port to control other devices.
As RouterOS doesn't (yet?) provide a native command to do that, you can work around with the following little script:

/interface ppp-client add name="scripttemp" dial-on-demand=no port=serial0 \
modem-init="I am the string" null-modem=yes disabled=no
:delay 1
/interface ppp-client remove [/interface ppp-client find name="scripttemp"]

The following assumptions were made:

  • We want to use serial port "serial0"
  • We have configured the serial port to match the other devices' setup (baud-rate etc.)
  • serial0 (or whatever port you use) is not used by RouterOS serial-console

The script sends the text configured as modem-init string out over the serial port when run.
So in the example above, it would send "I am the string" (without the quotes).