Recent

Author Topic: ttyUSB0 only opens/connects the first time  (Read 14370 times)

adrien

  • New Member
  • *
  • Posts: 10
ttyUSB0 only opens/connects the first time
« on: July 19, 2013, 08:54:04 pm »
Hi,

Has anyone seen this too?
I'm using Synaser with Lazarus 1.0.8 on Lubuntu 13.04, and lsusb shows a HL-340 USB-Serial adapter.
When I connect /dev/ttyUSB0 the first time, everything works fine.
But after disconnecting (ser.free) I get error 5 (EIO) when I try to connect (ser.Connect('/dev/ttyUSB0') - after a new TBlockSerial.Create of course)
Looking into synaser.pas, the problem happens when calling fpOpen, as it returns -1 (and errno 5).
As it works the first time I suppose the port is not released properly.
I've tried with LinuxLock := false, purge, CloseSocket (those two are called by synaser anyway), I also added 300ms sleep between synaser function calls.
Synaser uses FileClose (fpClose repeated), I replaced it with fpClose to check for error, but no error there.
After disconnecting and reconnecting the USB-Serial cable it works again. Once.
This does not happen in WinXP.

Well, my wheels are spinning in the mud. Anyone's got a winch?

Thanks,
Adrien.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: ttyUSB0 only opens/connects the first time
« Reply #1 on: July 20, 2013, 12:27:58 am »
hello adrien,

i have tried a  Prolific PL2303 USB to serial adaptor on Ubuntu 12.04  using Lazarus 1.1 svn fpc 2.7.1 and sertest project from my component tlazserial (use synaser library)
port settings detects serial port -->  /dev/ttyusb0
i can open and close this port many times with no problem ( i don't free the serial component when close it)
1 - why do you destroy your TBlockSerial and not close it and re open it ?

Friendly, J.P

Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

adrien

  • New Member
  • *
  • Posts: 10
Re: ttyUSB0 only opens/connects the first time
« Reply #2 on: July 20, 2013, 12:39:10 am »
Hello JP,

Thanks for the input.
It's just for trying to find the source of the problem..
The problem is when I quit the program (and destroy the TBlockSerial) and restart it, then I can't connect any longer.

It might be a driver / chip problem though.

Adrian

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: ttyUSB0 only opens/connects the first time
« Reply #3 on: July 20, 2013, 01:01:36 am »
ok,
to see if it is a O.S - driver problem, try to use another kind of serial port app ( ex minicom gtkterm) .
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

adrien

  • New Member
  • *
  • Posts: 10
Re: ttyUSB0 only opens/connects the first time
« Reply #4 on: July 20, 2013, 01:04:10 am »
I'll try.

Btw,it looks like this:

procedure TForm1.Button3Click(Sender: TObject);
var
  SerBuf : Array[0..511] of byte;
  TmpBuf : Array[0..63] of byte;
  blen : integer;
begin
  ser:=TBlockSerial.Create;
  Sleep(300);
  ser.LinuxLock := false;
  ser.Connect('/dev/ttyUSB0');
  Sleep(300);
  ser.config(9600,8,'N',SB1,false,false);
  blen := MakeBuf(@SerBuf[0]);
  Sleep(300);
  ser.SendBuffer(@SerBuf[0],blen);
  Sleep(300);
  ser.RecvBufferEx(@TmpBuf[0], 1, 500);
  Sleep(300);
  ser.free;
end;

Adrien.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: ttyUSB0 only opens/connects the first time
« Reply #5 on: July 20, 2013, 01:16:29 am »
and what is your synaser version ?
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

adrien

  • New Member
  • *
  • Posts: 10
Re: ttyUSB0 only opens/connects the first time
« Reply #6 on: July 20, 2013, 01:23:07 am »
40

adrien

  • New Member
  • *
  • Posts: 10
Re: ttyUSB0 only opens/connects the first time
« Reply #7 on: July 20, 2013, 01:24:48 am »
Sorry, Synapse 40, Synaser 7.5.0

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: ttyUSB0 only opens/connects the first time
« Reply #8 on: July 20, 2013, 01:29:38 am »
ok my component Tlazserial use 007.005.002 synaser library ( with some changes).
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

adrien

  • New Member
  • *
  • Posts: 10
Re: ttyUSB0 only opens/connects the first time
« Reply #9 on: July 20, 2013, 01:42:47 am »
I seem to have a dpkg problem, can't install anything. (Maybe thats my problem..)
Anyway I'll fix it tomorrow and check with another serial port app.

Thanks for the help J.P

Adrien.

adrien

  • New Member
  • *
  • Posts: 10
Re: ttyUSB0 only opens/connects the first time
« Reply #10 on: July 20, 2013, 06:10:41 pm »
Hi again,

I tried with gtkterm on Lubuntu 13.04:
Works for the first connection, then I get "Cannot open /dev/ttyUSB0: Input/output error"
If I unplug/replug then it works again, once.

I also tried with minicom on SliTaz 4.0(Linux 2.6): same problem (though I get: "mincom: cannot open /dev/ttyUSB0: Connection timed out")

Tried again on WinXP (virtual port COM3): works fine. I can connect/deconnect/reconnect without problem.

All this is on the same hardware, with VirtualBox.

So it seems to be a driver problem (usbserial and ch341)
Or maybe the Windows virtual Com driver stays connected all the time, thus avoiding a chip problem that a more "direct" Linux driver can't avoid.
Just speculations..

Any ideas?

Adrien.





Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: ttyUSB0 only opens/connects the first time
« Reply #11 on: July 22, 2013, 02:11:56 am »
i tried with virtualbox 4.2 , Ubuntu 10.04 lucid 32 bits ,  Prolific PL2303 USB to serial adaptor

with the program sertest, i can connect/deconnect/reconnect without problem (connect usb prolific device mapped to /dev/ttyS2 by the system)

Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

adrien

  • New Member
  • *
  • Posts: 10
Re: ttyUSB0 only opens/connects the first time
« Reply #12 on: July 22, 2013, 04:09:08 pm »
I found this when I went looking for the driver code history
(at https://github.com/torvalds/linux/commits/master/drivers/usb/serial/ch341.c)

4 month ago,  "USB: ch341: fix use-after-free in TIOCMIWAIT"

This might be it.

I'll have to find out how to update the driver though (I'm rather new to Linux)
I'll come back when I figure it out.

Adrien.

adrien

  • New Member
  • *
  • Posts: 10
Re: ttyUSB0 only opens/connects the first time
« Reply #13 on: July 22, 2013, 08:16:51 pm »
Hi JP,

The updated version of ch341.c requires an updated linux header (serial.h), so I suppose other drivers/modules... must be recompiled too.
Anyway I think I'll just wait for Lubuntu 13.10 as these updates are likely to be in there.
I'll come back when I've tried 13.10

Many thanks for your input,

Adrien.

adrien

  • New Member
  • *
  • Posts: 10
Re: ttyUSB0 only opens/connects the first time
« Reply #14 on: July 23, 2013, 12:47:30 am »
I updated the kernel to 3.10.2 and it works fine now.
So it was a driver problem that normally is fixed in the next Ubuntu/Lubuntu.. release.

To update the kernel:
http://www.liberiangeek.net/2013/07/upgrade-to-linux-kernel-3-10-latest-to-resolve-some-issues-in-ubuntu/

Cheers,
Adrien.

 

TinyPortal © 2005-2018