serial port trouble on Win10

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

serial port trouble on Win10

Ulrich Schmidt
Hi all

My windows10 app try to comunicate with some external hardware via a
serial port

I use Lua5.3(gcc_64)+iup(precompiled-mingw6_64)[1] to build my Windows10
App. So far so good.
I can open the serial port via io.open() but this approach works in
buffered mode and my short messages get stuck in the transmit buffer.
2.try: I used winapi.open_serial() but this function silently craches my
app in case the filename is correct.

Now my questions:
Anyone tried winapi.open_serial()[2] on Win10? (mingw6_64)
Can anyone suggest a solution/lua-module, that works out of the box?

Thank you all.
Ulrich.


[1]: sourceforge.net ... iup-3.30_Win64_dllw6_lib.zip
[1]: sourceforge.net ... iup-3.30-Lua53_Win64_dllw6_lib.zip
[2]: https://luarocks.org/modules/steved/winapi/1.4.2-1
Reply | Threaded
Open this post in threaded view
|

Re: serial port trouble on Win10

Sean Conner
It was thus said that the Great Ulrich Schmidt once stated:
> I can open the serial port via io.open() but this approach works in
> buffered mode and my short messages get stuck in the transmit buffer.

  Two possible solutions:

1. use file:flush() after writing data to ensure the buffer is written.
2. use file:setvbuf('no') immediately after opening the serial port to avoid
   all buffering of data.

  -spc (And that's all the ideas I have)
Reply | Threaded
Open this post in threaded view
|

Re: serial port trouble on Win10

Ulrich Schmidt
Am 10.10.2020 um 08:51 schrieb Sean Conner:

> It was thus said that the Great Ulrich Schmidt once stated:
>> I can open the serial port via io.open() but this approach works in
>> buffered mode and my short messages get stuck in the transmit buffer.
>
>    Two possible solutions:
>
> 1. use file:flush() after writing data to ensure the buffer is written.
> 2. use file:setvbuf('no') immediately after opening the serial port to avoid
>     all buffering of data.
>
>    -spc (And that's all the ideas I have)
>
Solution 2. worked so far as i can send short commands to my hardware.
Thank You. For doing so, i had to open the file in write mode.
Unfortunately i cant read this port. To read, i need to open the file in
read mode but cant send anymore.
Thats probably the reason Steve Donovan did a lot of magic behind the
scene in his winapi module.
Reply | Threaded
Open this post in threaded view
|

Re: serial port trouble on Win10

Sean Conner
It was thus said that the Great Ulrich Schmidt once stated:

> Am 10.10.2020 um 08:51 schrieb Sean Conner:
> >It was thus said that the Great Ulrich Schmidt once stated:
> >>I can open the serial port via io.open() but this approach works in
> >>buffered mode and my short messages get stuck in the transmit buffer.
> >
> >   Two possible solutions:
> >
> >1. use file:flush() after writing data to ensure the buffer is written.
> >2. use file:setvbuf('no') immediately after opening the serial port to
> >avoid
> >    all buffering of data.
> >
> >   -spc (And that's all the ideas I have)
> >
> Solution 2. worked so far as i can send short commands to my hardware.
> Thank You. For doing so, i had to open the file in write mode.
> Unfortunately i cant read this port. To read, i need to open the file in
> read mode but cant send anymore.

  You can open a file for reading and writing by using "r+" for the mode
when opening the file.  The wording for "r+" in the Lua manual labels this
mode as "update mode" (and in my opinion might not be clear about opening
the file in read/write mode).

> Thats probably the reason Steve Donovan did a lot of magic behind the
> scene in his winapi module.

  That, and to (probably) allow one to configure the serial port (speed,
bits,  etc.).

  -spc
Reply | Threaded
Open this post in threaded view
|

Re: serial port trouble on Win10

Ulrich Schmidt
Am 10.10.2020 um 21:56 schrieb Sean Conner:
>    You can open a file for reading and writing by using "r+" for the mode
> when opening the file.  The wording for "r+" in the Lua manual labels this
> mode as "update mode" (and in my opinion might not be clear about opening
> the file in read/write mode).
THIS was the golden tip! You saved my day. :)
Thank You.

Ulrich.