martinling / libserialport

Unofficial personal repository for libserialport - see git://sigrok.org/libserialport for official repo
http://sigrok.org/wiki/Libserialport
GNU Lesser General Public License v3.0
65 stars 34 forks source link

sp_wait issue under windows... #4

Closed Matrix-Zhang closed 9 years ago

Matrix-Zhang commented 9 years ago

Hi:

I'm useing your library with my serialport tool which the one of the goals is cross platform ...

there's an issue with sp_wait function and sp_nonblocking_read under windows os,

first, when the input buffer is nothing, the sp_wait will block until some data was recived in driver's buffer,

and then i use sp_nonblocking_read until it return 0 ( read all buffer)

the next loops for call sp_wait , it will not block anymore...

i check it out it because of the calling below in sp_nonblocking_read:

if(bytes_read > 0) { if (WaitCommEvent(port->hdl, &port->events, &port->wait_ovl) == 0) { if (GetLastError() != ERROR_IO_PENDING) { sp_close(port); RETURN_FAIL("WaitCommEvent() failed"); } } }

i modify the line :if(bytes_read > 0) to if(bytes_read == 0)

it works better now, but not perfect....

at last, thanks a lot for your job, and sorry for my bad english...

martinling commented 9 years ago

Hi,

I was actually just looking at this code today, it was causing other problems too.

Can you test with this branch please and let me know if it works correctly:

https://github.com/martinling/libserialport/commits/windows

Matrix-Zhang commented 9 years ago

i have tried it yet... it seems not correct.. when sp_wait return SP_OK then call sp_nonblocking_read, it just return -2 (SP_ERR_FAIL) now...

martinling commented 9 years ago

OK, it would be helpful if you could post a debug log.

If you set the environment variable LIBSERIALPORT_DEBUG = 1 and run your program from the command line, you should get a lot of debugging output.

Matrix-Zhang commented 9 years ago

sorry, i make a mistake before in my test program, now, it's ok

but there is a little issue:

sp: sp_get_port_by_name(COM4, 0028FE54) called. sp: Building structure for port COM4. sp: get_port_details returning SP_OK. sp: sp_get_port_by_name returning SP_OK. sp: sp_open(0050D148, 0x3) called. sp: Opening port COM4. sp: get_config(0050D148, 0028FDE0, 0028FDFC) called. sp: Getting configuration for port COM4. sp: get_config returning SP_OK. sp: set_config(0050D148, 0028FDE0, 0028FDFC) called. sp: Setting configuration for port COM4. sp: set_config returning SP_OK. sp: sp_open returning SP_OK. sp: sp_get_port_handle(0050D148, 0028FE58) called. sp: sp_get_port_handle returning SP_OK. sp: sp_set_baudrate(0050D148, 115200) called. sp: get_config(0050D148, 0028FD80, 0028FD9C) called. sp: Getting configuration for port COM4. sp: get_config returning SP_OK. sp: set_config(0050D148, 0028FD80, 0028FD9C) called. sp: Setting configuration for port COM4. sp: sp_new_event_set(023CFEE8) called. sp: sp_new_event_set returning SP_OK. sp: sp_add_port_events(020FAC88, 0050D148, 1) called. sp: add_handle(020FAC88, 812, 1) called. sp: add_handle returning SP_OK. sp: sp_add_port_events returning SP_OK. sp: sp_wait(020FAC88, 0) called. sp: set_config returning SP_OK. sp: sp_set_baudrate returning SP_OK. sp: sp_wait returning SP_OK. sp: sp_nonblocking_read(0050D148, 023CFAE8, 1024) called. sp: Reading up to 1024 bytes from port COM4. sp: sp_nonblocking_read returning 111. sp: sp_wait(020FAC88, 0) called. sp: sp_wait returning SP_OK. sp: sp_nonblocking_read(0050D148, 023CFAE8, 1024) called. sp: Reading up to 1024 bytes from port COM4. sp: sp_nonblocking_read returning 0. sp: sp_wait(020FAC88, 0) called.

the 1 sp_wait return ok, then i read all buffer, the 2 sp_wait should be block, actually not block, sp_nonblocking_read return 0 until the 3 sp_wait block

martinling commented 9 years ago

Can you try with this change:

https://github.com/martinling/libserialport/commit/01284d267cdbe0286761b1cc76947e6016466e8a

martinling commented 9 years ago

I think this issue should be fixed in the current master branch now. Please reopen if you still have problems.