Read/Write with a custom hardware via USB serial

Hi,

I’ve made a hardware watch dog card that connects to a PC via USB port (it uses a general USB to Serial converter) and thru the virtual serial, I need to send some bytes telling the hardware that the PC is alive.

Now I have a client that uses RouterOS on a PC and he asked me if my card is compatible with it.

Because of that I’m making this topic.

Is it possible to run a custom C application on RouterOS? The application was made by me and I have the C source code (only POSIX C).

It it’s not an option, it is possible to send direct commands to the serial via script. It needs a INIT command to be sent when the system starts and a KEEP ALIVE command to be sent each XX minutes.

But I need a way to list the serial ports availables on system.

Thanks.

Nobody never tried to talk with a custom serial device with RouterOs?

you probably need to setup a PPP async adapter (just like a modem dialup client) and in the INIT string enter the text you want it to send. Then setup a script that enable and disables this interface for however often you need it to send it. It’s a hack, but it should work for what you need. You won’t be able to read anything from the port, but you can surely send.

Exactly. I have written an example for that in the wiki a long time ago. Should work with current versions, too, though.
You cand find the example here: http://wiki.mikrotik.com/wiki/Sending_text_out_over_a_serial_port

Hope that helps a bit.

Ah yes, and there is a (although ver counter-intuitive) way to read data from the serial port on the RouterOS device itself. But you cannot read arbitrary data, you have to have control over the device connected to the serial port to talk a special protocol. Something like “HTTP-over-RS232”. I did create this setup for a special application.
But as I said - you need to run custom software on the serial device to be able to use this workaround…

Having commands to read/write from/to a serial port natively in RouterOS would surely be a tremendous help. Hint hint @ MikroTik :wink:

I have used the ppp hack and it injects an invalid route into my routing table everytime it runs. That is no good, it was causing massive packet loss. Any ideas on a workaround for this?

I was thinking maybe bridge the terminal session to telnet and then accessing it via telnet, but I have no idea how to go about doing this. I am just trying to get an internal mt script to write data to the serial port. ideas?

maybe you had dial-on-demand turned on for the ppp interface and it was injecting a route?

you can use /port remote-access to bridge a serial port to a telnet port, works excellent. Use RAW mode so you can just use telnet or netcat in linux.

Sam

Well I need to write to the serial port/telnet session from mikrotik, any idea how I could write a script to telnet into something from mikrotik?

Thanks!

in the current 3.x there isnt a way to script an outbound connection other than http/ftp/ping, etc. Maybe LUA has some enhanced methods for serial access in 4.x, havent looked into that yet.

ah, hummm…

Well is there any way to keep ppp from making routes. My code is just:

#write to display
/interface ppp-client add name="scripttemp" port=serial1 modem-init="$display" null-modem=yes disabled=no
:delay 1
/interface ppp-client remove [/interface ppp-client find name="scripttemp"]

add ‘add-default-route=no’ and ‘null-modem=yes’ maybe…

Sam

I already had null-modem=yes

Add default route fixes the route problem, but now it doesn’t write to the LCD. I was thinking it may be because it doesn’t write to the lcd until packets are sent its way?

I’m also looking to add external temp sensor/watch dog/alarm board and stumbled upon this thread.

Here’s my idea: assuming that telnet session can be scripted…:

Create metarouter.
configure the “main” ROS as an rs232 - TCP bridge (/port remote-access )
Telnet from metarouter to the “main” ROS for bi-directional communication with the device connected to rs232.

would this work -I wonder… :smiley:

btw, the board I’m looking at is:
http://www.relaypros.com/mm5/merchant.mvc?Screen=CTGY&Store_Code=NCD&Category_Code=2-Relay_Controllers_RS-232

edit: there’s another board that only monitors rs232 activity if anyone is interested
http://www.industrologic.com/uwdtdesc.htm