CNI vs PCI and Linux

Discussion in 'C-Bus Toolkit and C-Gate Software' started by more-solutions, Jul 22, 2011.

  1. more-solutions

    more-solutions

    Joined:
    Apr 23, 2006
    Messages:
    283
    Likes Received:
    4
    Location:
    Peterborough, UK
    Sorry, I seem to be starting a lot of threads recently.

    Sat on the train last night I was thinking about how to get C-Gate talking to a network via a serial port on Linux.

    As I understand it, a CNI is basically a serial to Ethernet converter bolted onto a PCI, but that's probably a horrible over-simplification. However, if that's true (or close to being true) then I could run a serial to ethernet gateway on my Linux box and tell C-Gate I have a CNI on localhost, thus bypassing all the headaches of serial port handling on Java.

    Before I try and set something up, is there a good reason why this couldn't work?
     
    more-solutions, Jul 22, 2011
    #1
  2. more-solutions

    tobex

    Joined:
    Nov 3, 2006
    Messages:
    728
    Likes Received:
    0
    Location:
    Sydney, Australia
    The solid state electronics tend to have a better lifespan than a hard disk.

    I bought a high-end din-rail serial converter on an auction website for very little.
     
    tobex, Jul 22, 2011
    #2
  3. more-solutions

    more-solutions

    Joined:
    Apr 23, 2006
    Messages:
    283
    Likes Received:
    4
    Location:
    Peterborough, UK
    Sorry, that's not what I was getting at.

    If I have a Windows PC with a serial port and a PCI, C-Gate is happy. If I swap Windows for Linux, C-Gate isn't happy, as the serial ports are no longer COM1/COM2 etc, and Java doesn't list the ports properly, and .... (there are other forum threads on the subject of PCIs and Linux not playing well).

    On the other hand, if I run a serial/ethernet "gateway" in software on the PC, providing access to the serial port at localhost:10001, then I'm hoping I can tell C-Gate to access this as a "CNI" to make it possible (and easy) to get access to the PCI via the existing serial port.
     
    more-solutions, Jul 22, 2011
    #3
  4. more-solutions

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    That is correct.

    This should work fine.
     
    Darren, Jul 23, 2011
    #4
  5. more-solutions

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,397
    Likes Received:
    26
    Location:
    Adelaide, South Australia
    There's some complications that may come up.

    For example, when doing this, you need to look at things like packet buffer sizes and timeouts. Most of these converters don't just get a Rx char and shove out an ethernet packet, they usually grab a few chars at a time (up to some timeout of accumulation) - also looking for an expiring inter-byte gap, and up to some limit of internal buffer size. Doing this is all ok, just complex.

    You may also run up against the lack of discovery support - entering a fixed IP address may suit. The CNI supports device discovery and over-the-LAN setting of properties, which your solution won't. This may or may not matter.
     
    ashleigh, Jul 23, 2011
    #5
  6. more-solutions

    more-solutions

    Joined:
    Apr 23, 2006
    Messages:
    283
    Likes Received:
    4
    Location:
    Peterborough, UK
    All good points, although I have some experience in passing binary serial protocols through IP (eg Modbus) where the same issues apply, albeit not recently, so fingers crossed I should be able to find a solution to this.

    I don't think this should matter unless C-Gate or Toolkit expects it to work that way. In fact the IP address will always be localhost since the software will run on the same server as C-Gate and the serial port, but I have no idea if Toolkit will be happy with a CNI on localhost or whether C-Gate would care either. If not that could be worked around, I'm sure, although there may still be other issues.

    What I wanted to check was that there wasn't a different protocol being used with the CNI (like for example ModNet vs Modbus), which would make everything a lot more messy.

    Hopefully I'll get chance to play a bit with this next week when I get back in the office.
     
    more-solutions, Jul 23, 2011
    #6
  7. more-solutions

    Andy@Mandoon

    Joined:
    Dec 13, 2004
    Messages:
    34
    Likes Received:
    0
    PCI connected via Network Socket

    I've been meaning to post that I have been running my PCI via a network port on my Linux box for 5 years now. It runs perfectly without any config hassles. CGate is running on the same box.

    CGate treats it like a network interface. The only caveat is that being so old, I can only vouch for the following instructions on Fedora 7. (The install is old!) So the below is valid on FC7, should be similar for most Linux builds.

    To configure CGate, you need to point it at the IP address of your machine and port 45001 (as configured in /etc/services).

    To customise for any installation, change the serial port used in the serial1 file.

    Install "xinetd" and "uucp" ( uucp supplies /usr/bin/cu)

    yum -y install xinetd uucp

    Create a file called /etc/xinet.d/serial1 containing:
    # default: off
    # description: Copy input/output between a port and the serial ttyS0 port
    #
    service serial1
    {
    flags = REUSE
    socket_type = stream
    wait = no
    user = uucp
    server = /usr/bin/cu
    server_args = -E+ -l /dev/ttyS1 -s 9600
    disable = no
    }

    Add to the bottom of /etc/services

    # Local services
    serial1 45001/tcp # Serial Port 1

    Restart xinetd using the command "/etc/init.d.xinetd restart"

    Ensure permissions are correct on /dev/ttyS1 ie. owner=root, group=uucp and group has "rw" permissions. If not, then NEED to setup a udev rule to fix. The udev rules are found in /etc/udev/rules.d

    Place this in a udev rule file with other "tty" rules in the directory /etc/udev/rules.d/ (eg. /etc/udev/rules.d/40-permissions.rules)

    KERNEL=="ttyS[0-9]*", GROUP="uucp"

    Of course, rebooting is needed to get this in place. Or do it manually
    using chown.
    [root@mandy etc]# chown root:uucp /dev/ttyS1
    [root@mandy etc]# chmod g+rw /dev/ttyS1

    Test by telneting to the port

    telnet mandy 45001
     
    Andy@Mandoon, Jul 25, 2011
    #7
  8. more-solutions

    more-solutions

    Joined:
    Apr 23, 2006
    Messages:
    283
    Likes Received:
    4
    Location:
    Peterborough, UK
    Thanks Andy, that looks like a great starting point!
     
    more-solutions, Jul 25, 2011
    #8
  9. more-solutions

    Andy@Mandoon

    Joined:
    Dec 13, 2004
    Messages:
    34
    Likes Received:
    0
    Let me know if you have problems getting the above to work.

    On my to do list (in the next 6 months!) is to move my automation server - including CGate - to the latest Ubuntu LTS server edition. If you want I can post the changes to the above steps.
     
    Andy@Mandoon, Aug 1, 2011
    #9
  10. more-solutions

    more-solutions

    Joined:
    Apr 23, 2006
    Messages:
    283
    Likes Received:
    4
    Location:
    Peterborough, UK
    When I get chance to try this I will definitely report back.

    However, I'm just coming to the end of a job where this would have been ideal but because we hadn't got it working we've installed a CNI, so the immediate need for this has gone. I want to get it working so it's in the toolbox for other applications but of-course I can't say when I'll find the time to "play", especially now that you've given me reason to think it will "just work"!

    Generally though I think there does seem to be a bit of community developing around C-Gate on Linux and I'm keen to do what I can to encourage and support that. A lot of the work I'm doing now lends itself to small embedded devices where the idea of running them on x86 Windows would be laughable, and WinCe/Mobile not much better.
     
    more-solutions, Aug 1, 2011
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.