# serial port not detected [solved]

## mystified

I have a ups connected via serial port using /dev/ttyS0.  My UPS can't detect anything.  

If I do cat /dev/ttyS0 I get no response.Last edited by mystified on Tue May 08, 2007 10:22 pm; edited 2 times in total

----------

## WhimpyPeon

Perhaps that serial port isn't set up right.

Try: 

dmesg | grep ttyS

to get some information on your serial device(s). Also make sure you aren't getting more than one serial device.

Then configure it using setserial.  Something like:

setserial /dev/ttyS0 irq 4 port 0x03f8 baud_base 115200 uart 16550A skip_test

Depending on your UPS and monitoring software you may have to adjust the baud rate to match your UPS.  If it is an APC UPS you should look into apcupsd.  I only use this with usb and can't comment on serial.

Not really an expert here, but I am still using serial to monitor some hardware decices.

----------

## mystified

I got the info from dmesg like you said and I entered it using setserial but I'm still not communicating with the UPS.  As far as baud rate I have no idea what that should be.  I googled for Belkin UPS and it didn't show a baud rate.

----------

## NeddySeagoon

mystified,

There was a problem with udev and the serial ports - it created circular symlinks instead of proper /dev entries.

Check your /dev entries are correct.

If you have the circular symlinks issue, delete the links and run udevstart. It will stay fixed.

----------

## mystified

Ok, it sounds like something to check but I'm not sure how to do it.

----------

## NeddySeagoon

mystified,

Do 

```
ls -l /dev/ttyS*
```

that will show you all your serial ports. These are normally symbolic links. The permissions will be lrwxrwxrwx. The first l means link.

The output will show 

```
-> [someplace] 
```

repeat the ls -l for each [someplace] until you get to a setof permissions that do not start with l (in which case you are probably ok) or you are back at /dev/ttyS, in which case you have the circular reference I described.

Non root users will need to be in the tty group (I think) to use the serial ports.

----------

## mystified

This was my output:

```
mystified@localhost /etc/udev/rules.d $ ls -l /dev/ttyS0

crwxrwxrwx 1 root uucp 4, 64 May  6 08:58 /dev/ttyS0

```

No l but a c to start.  Is that significant?

Also I did:

```
serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A

serial_cs: Unknown symbol cs_error

serial_cs: Unknown symbol pcmcia_disable_device

serial_cs: Unknown symbol pcmcia_unregister_driver

serial_cs: Unknown symbol pccard_get_first_tuple

serial_cs: Unknown symbol pcmcia_get_configuration_info

serial_cs: Unknown symbol pcmcia_request_io

serial_cs: Unknown symbol pcmcia_request_configuration

serial_cs: Unknown symbol pcmcia_access_configuration_register

serial_cs: Unknown symbol pccard_get_tuple_data

serial_cs: Unknown symbol pcmcia_register_driver

serial_cs: Unknown symbol pccard_parse_tuple

serial_cs: Unknown symbol pccard_get_next_tuple

serial_cs: Unknown symbol pcmcia_request_irq

```

I'm not sure I understand what that means.

----------

## NeddySeagoon

mystified,

the c at the start means its the real character device file. 

b means block d means directory, l is link and - means normal file.

Your unknown symbol errors mean your kernel is broken. It looks like pcmcia support is incomplete.

However, since you mention UPS, I guess you are not on a laptop. So you should probably not be trying to use pcmcia support at all.

Did you create /dev/ttyS0 yourself ?

Thats not how udev/Gentoo would do it.

----------

## mystified

No I didn't create it myself.  Any more ideas?

After googling some more I tried this and I think it's the problem.  But I have no idea how to fix it.

```
localhost rules.d # udevinfo -a -n /dev/ttyS0

Udevinfo starts with the device specified by the devpath and then

walks up the chain of parent devices. It prints for every device

found, all possible attributes in the udev rules key format.

A rule to match, can be composed by the attributes of the device

and the attributes from one single parent device.

  looking at device '/class/tty/ttyS0':

    KERNEL=="ttyS0"

    SUBSYSTEM=="tty"

    DRIVER==""

    ATTR{dev}=="4:64"

```

----------

## NeddySeagoon

mystified,

Are you on a laptop or not ?

Please post your lspci output and we'll take it from there.

----------

## mystified

No, not on a laptop.

```
localhost mystified # lspci

00:00.0 Host bridge: Intel Corporation 82865G/PE/P DRAM Controller/Host-Hub Interface (rev 02)

00:01.0 PCI bridge: Intel Corporation 82865G/PE/P PCI to AGP Controller (rev 02)

00:1d.0 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #1 (rev 02)

00:1d.1 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #2 (rev 02)

00:1d.2 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #3 (rev 02)

00:1d.3 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #4 (rev 02)

00:1d.7 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB2 EHCI Controller (rev 02)

00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev c2)

00:1f.0 ISA bridge: Intel Corporation 82801EB/ER (ICH5/ICH5R) LPC Interface Bridge (rev 02)

00:1f.1 IDE interface: Intel Corporation 82801EB/ER (ICH5/ICH5R) IDE Controller (rev 02)

00:1f.2 IDE interface: Intel Corporation 82801EB (ICH5) SATA Controller (rev 02)

00:1f.3 SMBus: Intel Corporation 82801EB/ER (ICH5/ICH5R) SMBus Controller (rev 02)

00:1f.5 Multimedia audio controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) AC'97 Audio Controller (rev 02)

01:00.0 VGA compatible controller: nVidia Corporation NV11 [GeForce2 MX/MX 400] (rev b2)

02:08.0 Ethernet controller: Intel Corporation 82562EZ 10/100 Ethernet Controller (rev 01)

```

----------

## NeddySeagoon

mystified,

I suspect you have the wrong support in your kernel or its modular and not loaded.

Do 

```
rm /dev/ttyS0
```

to delete that bogus device file.

```
modprobe 8250
```

to load the serial modue (if it exits)

Look at the end of dmesg for errors, if there are none, test the serial port again. udev will have made the /dev entry.

If there are errors - post them

----------

## mystified

```
localhost dev # modprobe 8250

WARNING: Error inserting serial_core (/lib/modules/2.6.20.7/kernel/drivers/serial/serial_core.ko): Invalid module format

FATAL: Error inserting 8250 (/lib/modules/2.6.20.7/kernel/drivers/serial/8250.ko): Unknown symbol in module, or unknown parameter (see dmesg)

```

From dmesg

```
250: disagrees about version of symbol uart_get_baud_rate

8250: Unknown symbol uart_get_baud_rate

8250: disagrees about version of symbol uart_resume_port

8250: Unknown symbol uart_resume_port

8250: disagrees about version of symbol uart_register_driver

8250: Unknown symbol uart_register_driver

8250: disagrees about version of symbol uart_suspend_port

8250: Unknown symbol uart_suspend_port

8250: disagrees about version of symbol uart_remove_one_port

8250: Unknown symbol uart_remove_one_port

8250: disagrees about version of symbol uart_update_timeout

8250: Unknown symbol uart_update_timeout

8250: disagrees about version of symbol uart_unregister_driver

8250: Unknown symbol uart_unregister_driver

8250: disagrees about version of symbol uart_get_divisor

8250: Unknown symbol uart_get_divisor

8250: disagrees about version of symbol uart_match_port

8250: Unknown symbol uart_match_port

8250: disagrees about version of symbol uart_add_one_port

8250: Unknown symbol uart_add_one_port

8250: disagrees about version of symbol uart_write_wakeup

8250: Unknown symbol uart_write_wakeup

```

And 

```
localhost dev # uname -r

2.6.20.7

```

vanilla-sources

----------

## mystified

Ok, I recompiled my kernel.  No error message so I did rm /dev/ttyS0 and them modprobe 8250 but I now have no ttyS0.  What do I need to do?

----------

## mystified

I checked my current log after I did modprobe and found the following:

```
May 06 11:05:03 [kernel] 8250: Unknown symbol uart_resume_port

May 06 11:05:03 [kernel] 8250: disagrees about version of symbol uart_register_driver

May 06 11:05:03 [kernel] 8250: Unknown symbol uart_register_driver

May 06 11:05:03 [kernel] 8250: disagrees about version of symbol uart_suspend_port

May 06 11:05:03 [kernel] 8250: Unknown symbol uart_suspend_port

May 06 11:05:03 [kernel] 8250: disagrees about version of symbol uart_remove_one_port

May 06 11:05:03 [kernel] 8250: Unknown symbol uart_remove_one_port

May 06 11:05:03 [kernel] 8250: disagrees about version of symbol uart_update_timeout

May 06 11:05:03 [kernel] 8250: Unknown symbol uart_update_timeout

May 06 11:05:03 [kernel] 8250: disagrees about version of symbol uart_unregiste

May 06 11:05:03 [kernel] 8250: Unknown symbol uart_unregister_driver

May 06 11:05:03 [kernel] 8250: disagrees about version of symbol uart_get_divisisor

May 06 11:05:03 [kernel] 8250: Unknown symbol uart_get_divisor

May 06 11:05:03 [kernel] 8250: disagrees about version of symbol uart_match_port

May 06 11:05:03 [kernel] 8250: Unknown symbol uart_match_port

May 06 11:05:03 [kernel] 8250: disagrees about version of symbol uart_add_one_port

May 06 11:05:03 [kernel] 8250: Unknown symbol uart_add_one_port

May 06 11:05:03 [kernel] 8250: disagrees about version of symbol uart_write_wak$

May 06 11:05:03 [kernel] 8250: Unknown symbol uart_write_wakeup
```

----------

## mystified

Recompiled with a new .config and used gentoo-sources this time.  I made sure everything compiled in for my serial port.  This time I compiled it in as a driver and not as a module and it still shows it has no driver.

----------

## NeddySeagoon

mystified,

Rebuilding your kernel is correct but you need to start with 

```
make clean
```

so make cannot use old binaries.

If your /dev/ttyS0 is missing, either that bit of the kernel is broken, modules help with the diagnosis.

If you think the kernel is ok, do 

```
udevstart
```

----------

## mystified

I did you udev start and the serial port still doesn't work.  I'll recompile my kernel again and see what happens.  Oh, and the port is there after the compile,

----------

## mystified

Ok, I did make clean, compiled serial in as a module. Did modprobe 8250, checked dmesg and got the following:

```
localhost log # dmesg | grep 8250

Serial: 8250/16550 driver $Revision: 1.90 $ 4 ports, IRQ sharing disabled

serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
```

Checked kernel .config

```
# CONFIG_MOUSE_SERIAL is not set

# CONFIG_SERIAL_NONSTANDARD is not set

CONFIG_SERIAL_8250=m

CONFIG_SERIAL_8250_PCI=m

CONFIG_SERIAL_8250_PNP=m

CONFIG_SERIAL_8250_NR_UARTS=4

CONFIG_SERIAL_8250_RUNTIME_UARTS=4

# CONFIG_SERIAL_8250_EXTENDED is not set

CONFIG_SERIAL_CORE=m

# CONFIG_SERIAL_JSM is not set

# CONFIG_SND_SERIAL_U16550 is not set

# CONFIG_USB_SERIAL is not set

```

still no response from the port and when I do:

```
localhost log # udevinfo -a -n /dev/ttyS0

Udevinfo starts with the device specified by the devpath and then

walks up the chain of parent devices. It prints for every device

found, all possible attributes in the udev rules key format.

A rule to match, can be composed by the attributes of the device

and the attributes from one single parent device.

  looking at device '/class/tty/ttyS0':

    KERNEL=="ttyS0"

    SUBSYSTEM=="tty"

    DRIVER==""

    ATTR{dev}=="4:64"

  looking at parent device '/devices/pnp0/00:08':

    KERNELS=="00:08"

    SUBSYSTEMS=="pnp"

    DRIVERS=="serial"

    ATTRS{id}=="PNP0501"

  looking at parent device '/devices/pnp0':

    KERNELS=="pnp0"

    SUBSYSTEMS==""

    DRIVERS==""

```

It still shows no driver for /dev/ttyS0

Any idea what I could be doing wrong?

I just tried this

```
localhost linux # setserial /dev/ttyS0 irq 4 skip_test autoconfig

Cannot autoconfigure port: Device or resource busy

```

----------

## NeddySeagoon

mystified,

Emerge minicom

Check the port settings and talk to the UPS from the console

----------

## keyson

Hi,

Observe that the /dev/ttyS0 have group uucp or tty depending

on your udev version.

Check by ls -l /dev/ttyS0

You need to add nut to the uucp or tty group to get the driver to talk to the ups.

Or you may start the driver in debug as root.

/lib/nut/belinunv -DD -a name -u root

Name is the tag name in ups.conf.

Don't know what the type of belkin you have. But check the

http://eu1.networkupstools.org/compat/stable.html

for the right driver.

Regards

Kjell

----------

## mystified

Ok, I added user nut to uucp and still no response from the UPS.

And I haven't figured out how get minicom working correctly.

----------

## keyson

OK.

You start it up as

```
minicom -s
```

Then you can do your settings and save it as default.

When you start it like

```
minicom
```

later it should use this settings. To alter the settings press 'ctrl-a z' it means hold down ctrl and press a then release both

and press z. Now you have a screen where you may alter settings. 

The belkin driver is a ascii based command driver

so by sending

```
~00P003STA
```

it should return status. The speed should be 2400baud DTR low and RTS high (hardware handshake).

The belkinunv is a multi protocol driver, look at http://eu1.networkupstools.org/protocols/belkin-universal/

So i think minicom would not help you out.

So I think we start from the beginning to get it right.

What is the name of the ups (brand (belkin?) type number ?) ?

Give me your ups.conf.

How many com-ports do you have on the computer. (To make sure you use the right port)

Regards

Kjell

----------

## mystified

I have a Belkin F6C900.

This is from my ups.conf

```
 [belkin]

        driver = belkinunv

        port = /dev/ttyS0

#       cable = 940-0024c

#       desc = "Something descriptive"

```

I have only one comm port.

----------

## keyson

OK.

Then we know the problem. This is a new belkin ups and is not using the

belkin or belkinunv protocol.

This ups is using the megatec protocol, BUT it is violating this protocol and

was fixed for about one month ago by Carlos Rodrigues.

You have two options:

1. get the svn trunk and compile.

Draback is that you need all configure flags to install it like Gentoo.

2. Get the svn trunk and the tgz for 2.0.5. Now unpack the tgz

replace the megatec.c and megatec.h in the drivers directory.

Make a tgz cd to the directory below nut-2.0.5, then

```

tar -czf nut-2.0.5.tar.gz nut.2.0.5

```

then copy it to the /usr/portage/distfiles

Now make an overlay copy the sys-power/nut/ to the overlay and make a

ebuild /usr/local/portage/sys-power/nut-2.0.5-r1.ebuild digest

If you need assistant we help you out.

In this way you have it the Gentoo way. (Vould be nice with a svn ebuild by the way  :Smile:  )

From the nut list:

 *Quote:*   

> 
> 
> Re: [Nut-upsdev] Belkin F6C900-UNV and the megatec driver
> 
> Carlos Rodrigues wrote:
> ...

 

Regards

Kjell

----------

## mystified

I can't find just an svn trunk in a tar.gz.  There are all kinds of svn trunks.  I don't know which one I need.

----------

## keyson

OK.

You need subversion installed to get the svn trunk from

svn://svn.debian.org/nut/trunk

So emerge subversion and the do

```

svn co svn://svn.debian.org/nut/trunk

```

Now you have a trunk directory with all code in it.

cd to trunk/drivers there you find the megatec.c and megatec.h

Now copy the nut-2.0.5.tar.gz to your home directory from /usr/portage/distfiles and extract it

```
tar xvzf nut-2.0.5.tar.gz
```

Now copy the megatec files from trunk/drivers to nut-2.0.5/drivers and do as i described to make a new nut-2.0.5.tar.gz

tar czf nut-2.0.5.tar.gz nut.2.0.5 standing in your home directory.

B.T.W If you don't want to install subversion i can send you the files.

Now copy back the nut-2.0.5.tar.gz to /usr/portage/distfiles and follow the overlay info I gave you.

Then you would run emerge sys-power/nut and it would use the overlay and the new source.

Regards

Kjell

EDIT: Don't forget to setup the PORTDIR_OVERLAY in the /etc/make.conf

EDIT2: B.T.W Have to sleep, be back in the morning.

----------

## mystified

I'm lost on how to make the overlapy copy.

Ok, once I'm done with this what do I put as driver in my ups.conf?

----------

## keyson

OK.

If you set PORTDIR_OVERLAY ="/usr/local/portage" in make.conf, then copy

/usr/portage/sys-power/nut/* to /usr/local/portage/sys-power/nut/

You have to create the /usr/local/portage and sys-power directory.

Now you have an overlay not updated by the 'emerge --sync'

And the ups.conf.

The driver should be megatec.

[myups]

driver = megatec

port = /dev/ttyS0

----------

## mystified

OK I followed your instructions but got this error:

```
localhost mystified # /etc/init.d/upsd start

 * Starting UPS drivers ...

Network UPS Tools - UPS driver controller 2.0.5

Network UPS Tools - Megatec protocol driver 1.5 (2.0.5)

Carlos Rodrigues (c) 2003-2006

Megatec protocol UPS not detected.

Driver failed to start (exit status=1)

 * Failed to start UPS drivers!                                           [ !! ]

 * ERROR:  cannot start upsd as upsdrv could not start
```

----------

## keyson

OK.

if your ups.conf looks like this

[myups]

driver = megatec

port = /dev/ttyS0

run this command

```
/lib/nut/megatec -DD -a myups
```

The myups is what you have inside the [] in the ups.conf.

And tell me what it say.

----------

## mystified

Ok, I get this

```
localhost mystified # /lib/nut/megatec -DD -a belkin

Network UPS Tools - Megatec protocol driver 1.5 (2.0.5)

Carlos Rodrigues (c) 2003-2006

debug level is '2'

Starting UPS detection process...

Attempting to detect the UPS...

Sending "Q1" command...

Wrong answer to "Q1" command.

Attempting to detect the UPS...

Sending "Q1" command...

Wrong answer to "Q1" command.

Attempting to detect the UPS...

Sending "Q1" command...

Wrong answer to "Q1" command.

Attempting to detect the UPS...

Sending "Q1" command...

Wrong answer to "Q1" command.

Attempting to detect the UPS...

Sending "Q1" command...

Wrong answer to "Q1" command.

5 out of 5 detection attempts failed (minimum failures: 2).

Megatec protocol UPS not detected.
```

----------

## keyson

Hmmm.

That does not look to good.

But this http://lists.alioth.debian.org/pipermail/nut-upsdev/2007-March/001874.html tell me

that it use the megatec driver.

I know that some ups'es seems to disable the comport when connected to usb.

Have you tryed to shut it off and disconnect it from the wall outlet. Then start it up again

and try this last command. It may need a reset. 

B.T.W Don't let it feed your computer during this test. Connect a lightbulb or something instead.

And i se that the driver version is reporting 1.5 it should be 1.5.3 if you manage to change the

megatec.c and megatec.h. Maybe you only copy the megatec.c file then it is reporting 1.5.

You may use minicom, and set the portsettings to 2400-8-n-1 (2400baud, 8bit, no parity, 1 stop bit)

And send

Q1<cr>

<cr> is enter.

----------

## mystified

Now I'm getting this

```
Network UPS Tools - Megatec protocol driver 1.5 (2.0.5)

Carlos Rodrigues (c) 2003-2006

debug level is '2'

Starting UPS detection process...

Attempting to detect the UPS...

Sending "Q1" command...

Wrong answer to "Q1" command.

Attempting to detect the UPS...

Sending "Q1" command...

"Q1" command successful.

Attempting to detect the UPS...

Sending "Q1" command...

"Q1" command successful.

Attempting to detect the UPS...

Sending "Q1" command...

"Q1" command successful.

Attempting to detect the UPS...

Sending "Q1" command...

"Q1" command successful.

1 out of 5 detection attempts failed (minimum failures: 2).

Asking for UPS information ("I" command)...

UPS doesn't return any information about itself.

Megatec protocol UPS detected.

Asking for UPS power ratings ("F" command)...

Asking for UPS status ("Q1" command)...

24.0V battery, interval [19.4V, 27.4V].

Done setting up the UPS.

Asking for UPS status ("Q1" command)...

dstate_init: sock /var/lib/nut/belkin open on fd 5

Asking for UPS status ("Q1" command)..
```

I think I'll try switching to USB and see if that works.  Nothing to lose.

----------

## keyson

OK.

Now it detect it right.

You could try 

/etc/init.d/upsdrv start

And see if it runs before you try usb.

To run it on usb:

I think you have libusb > 0.11 so the device used should be

/dev/bus/usb/00x/00x

To set the right permissions on that you need a udev rule.

I don't think that Gentoo install this as default when you emerge nut.

You find a template file in nut-2.0.5/scripts/hotplug-ng named nut-usbups.rules.in.

So you need to fix this. But we can start with a test.

change the driver to newhidups and port to auto in the ups.conf.

Then run

/lib/nut/newhidups -DD -u root -a belkin

By using the -u root it does not need the /dev to be set to user nut.

If it works i can help you with the udev rule.

----------

## mystified

Good news.  I got:

```
Megatec protocol UPS detected.                                            [ ok ]

localhost mystified # /etc/init.d/upsd start

 * Starting upsd ...

Network UPS Tools upsd 2.0.5

Connected to UPS [belkin]: belkin  
```

Now I have to figure out how to use it!

----------

## keyson

OK

Do

/etc/init.d/upsd start

If it starts, do

```

upsc belkin@localhost

```

EDIT:

Good help is http://gentoo-wiki.com/HOWTO_NUT

EDIT1:

Sorry i did not see that the upsd was started. So only do the upsc thing

----------

## mystified

Ok, that worked.  Thanks so much for all your help.  I never would have gotten this working without your support!   :Very Happy: 

----------

## keyson

No problems.

Read the howto and finish the setup then start the monitor /etc/init.d/upsmon start.

I'm a little confused about it saying version 1.5 on the driver.

Check that you did it right and realy using the new megatec driver.

Because it would not work 100% if you don't.

Regards

Kjell

----------

## mystified

Ok, I have a configuration error somewhere that I can't figure out.

```
ay  8 11:33:35 localhost upsmon[5668]: Poll UPS [mystified@localhost] failed - [mystified] does not exist on server localhost

May  8 11:33:35 localhost upsmon[5668]: Poll UPS [server@localhost] failed - [server] does not exist on server localhost

May  8 11:33:35 localhost upsmon[5668]: Poll UPS [belkins@localhost] failed - [belkins] does not exist on server localhost
```

----------

## keyson

Check the line in upsmon.conf

You should only have one line if you have one ups.

MONITOR belkin@localhost 1 user pass master

user and pass is the user and pass you set in upsd.users

[user]

password = pass

allowfrom = localhost

instcmds = ALL

upsmon master

I looked at the HOWTO NUT page and it misses a lot of info for the setup.

But you have good docs on http://www.networkupstools.org/doc/

EDIT: last line say belkins@localhost should be belkin@localhost one s to much.

----------

## mystified

That's what I don't understand.  I have only one user: mystified.

Now I'm get this:

```
May  8 12:11:17 localhost upsmon[6189]: Poll UPS [mystified@localhost] failed - [mystified] does not exist on server localhost

May  8 12:11:17 localhost upsmon[6168]: Poll UPS [mystified@localhost] failed - [mystified] does not exist on server localhost

May  8 12:11:18 localhost upsmon[5668]: Poll UPS [mystified@localhost] failed - [mystified] does not exist on server localhost

```

----------

## keyson

The line in the upsmon.conf is the ups you want to monitor.

So you have a belkin set in ups.conf so if you monitor this it should say

MONITOR belkin@localhost 1 user pass master 

in upsmon.conf

I sent you a pm.

----------

## mystified

Thanks to keyson I'm marking this problem as solved.  His help was invaluable.

----------

