Giter Site home page Giter Site logo

veeso / termiwin Goto Github PK

View Code? Open in Web Editor NEW
60.0 6.0 23.0 169 KB

termiWin: a termios porting for Windows

License: GNU General Public License v3.0

C 94.51% CMake 5.49%
termios windows serial-ports termios-structure struct-termios termios-compatibilty serial-communication serial-port termios-for-windows windows-termios

termiwin's Issues

Any way to use with a Python packages?

I'm attempting to run a Python package called asciinema (records terminal sessions) but every attempts throws up errors due to missing module "termios". So my question is whether or not (and if so, how) this can be integrated into a Python package, and/or how (if possible) it can be used in place of the missing module.

Returned handle cannot be used with "isatty"

The libmbus code uses "isatty" with the handle returned from "connect" to check if the connection is correct and to a serial device.

Because the handle you return is not really a handle, but the real handle is somewhere in your struct only this method returns an error.

Any idea how to fix this? Also overwrite isatty?

hard defines for read/write/select/open/close also affects other files

Hey,

I currently try to get libmbus to compile on windows and sofound your great termiWin as replacement for termios.h ...
Bute when I use this the redefines for "read/write/select/open/close" in termiWin.h also affects other methods called "open/close" in a complete different file (definition of a struct in libmbus) ends up in weired error messages.

Here is the struct from libmbus:
https://github.com/Apollon77/libmbus/blob/build-windows/mbus/mbus-protocol-aux.h#L92

and this generates error ;

..\libmbus\mbus\mbus-protocol-aux.c(1529): error C2039: 'openSerial': is not a member of '_mbus_handle'

as soon as the code wants to assign to "open" property:
https://github.com/Apollon77/libmbus/blob/build-windows/mbus/mbus-protocol-aux.c#L1529

Is there any way to solve this?!

Ingo

tcdrain is always blocking ...

... can it be because of the fact that the CreateFile is done in "non overlapping" mode ?!

When I understood it correctly "non overlapping" means that the WriteFile call returns after everything is written. So when you call a drain after the Write you will wait for an Event that never comes (because already was there?)

Could this be possible?

I also tried to set mode to overlapping, but then I got no successfull connect (or I forgot something).

For now I removed the drain, but if my above "idea" is true then the tcdrain should always return directly, or ?! Or you need to move to overlapping mode.

What fo you think?

Control/Charset option handling is not working

I struggled around a very long time now, and finally noted that the "getCharSet" and "getControlOptions" methods are not working and return crap (or better: only 0").

Because of this wrong options are set.

My cflag is sset as follows:

memset(term, 0, sizeof(*term));
    term->c_cflag |= (CS8/*|CREAD|CLOCAL*/);
    term->c_cflag |= PARENB;

resulting in

c_cflag = 4c00

This struct is then used to call

 tcsetattr(handle->fd, TCSANOW, term);

Now after nothing worked I added debug and I found out that the"getByte" calls (at least) in getCharSet and getControlOptions return 0 in this case, leading to wrong results.

Could you please check that?!
I will also try to get in the bianry comare stuff, but ... maybe your are faster :-)

Thank you for all your support!

Serial port name init seems wrong/strange

Hi again :-)

I found one last thing which adding testing for my library.

Your code in "OpenSerial" to init ihe port name is:

com.port = calloc(1,sizeof(char)*(strlen("\\\\.\\")+4));
strncat(com.port, portname, 4);

So you only accept the first 4 characters of the portname that is given to the function, but reserve then 4 bytes more without writing them somewhere.

From specs:

  • You can use COM1..9 directly
  • for others (like COM10 or other names) you need to use \.\COM10 as example.

So I think you initially wanted to limit to 4 character ports (but with this you do not allow COM10 or such) and wanted to always add "\." in front ... but you did not done that :-)

I would propose a change to:

	com.port = calloc(1,sizeof(char)*(strlen(portname)+1));
	strncat(com.port, portname, strlen(portname));

so simply copy the portname as it was as it came in (plus 1 for the \0 as string terminator) and have people send correct portnames ?!
Alternative would be to use portname as is (to also allow longer portnmes then 4 characters) and always prepend "\.". What do you think?

Missing defines CREAD, CLOCAL and B600

I currently try to get libmbus to compile on windows and use your termiWin.

I miss:

  • B600 ... ok this one was easy to add :-)
  • CREAD
  • CLOCAL

Do you have any idea how to add them?

Tons of Errors

A:\Projects\cProjects>gcc -c termiWin.c
termiWin.h:39:14: error: conflicting types for 'openSerial'
#define open openSerial
^~~~~~~~~~
termiWin.h:180:5: note: previous declaration of 'openSerial' was here
int openSerial(char* portname, int opt);
^~~~~~~~~~
termiWin.h:36:14: error: conflicting types for 'readFromSerial'
#define read readFromSerial
^~~~~~~~~~~~~~
termiWin.h:178:5: note: previous declaration of 'readFromSerial' was here
int readFromSerial(int fd, char* buffer, int count);
^~~~~~~~~~~~~~
termiWin.h:37:15: error: conflicting types for 'writeToSerial'
#define write writeToSerial
^~~~~~~~~~~~~
termiWin.h:179:5: note: previous declaration of 'writeToSerial' was here
int writeToSerial(int fd, char* buffer, int count);
^~~~~~~~~~~~~
termiWin.c: In function 'readFromSerial':
termiWin.c:454:44: warning: passing argument 4 of 'ReadFile' from incompatible pointer type [-Wincompatible-pointer-types]
ret = ReadFile(com.hComm, buffer, count, &rc, NULL);
^~~
In file included from C:/Mingw-w64/mingw64/x86_64-w64-mingw32/include/winbase.h:18,
from C:/Mingw-w64/mingw64/x86_64-w64-mingw32/include/windows.h:70,
from termiWin.h:29:
C:/Mingw-w64/mingw64/x86_64-w64-mingw32/include/fileapi.h:167:106: note: expected 'LPDWORD' {aka 'long unsigned int *'} but argument is of type 'int *'
WINBASEAPI WINBOOL WINAPI ReadFile (HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped);
~~~~~~~~^~~~~~~~~~~~~~~~~~~
termiWin.c: In function 'writeToSerial':
termiWin.c:468:45: warning: passing argument 4 of 'WriteFile' from incompatible pointer type [-Wincompatible-pointer-types]
ret = WriteFile(com.hComm, buffer, count, &rc, NULL);
^~~
In file included from C:/Mingw-w64/mingw64/x86_64-w64-mingw32/include/winbase.h:18,
from C:/Mingw-w64/mingw64/x86_64-w64-mingw32/include/windows.h:70,
from termiWin.h:29:
C:/Mingw-w64/mingw64/x86_64-w64-mingw32/include/fileapi.h:175:109: note: expected 'LPDWORD' {aka 'long unsigned int *'} but argument is of type 'int *'
WINBASEAPI WINBOOL WINAPI WriteFile (HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
termiWin.c: In function 'openSerial':
termiWin.c:483:5: warning: 'strncat' specified bound 4 equals source length [-Wstringop-overflow=]
strncat(com.port, "\\.\", strlen("\\.\"));

Function openSerial() changes the portname parameter

The function openSerial() changes the portname parameter at the end were fd is established:

if (com.hComm == INVALID_HANDLE_VALUE) return -1;
strncpy(portname, portname + 3, 1);
com.fd = atoi(portname); //COMx
SerialParams.DCBlength = sizeof(SerialParams);
return com.fd;

This can easily be fixed as follows:

if (com.hComm == INVALID_HANDLE_VALUE) return -1;
com.fd = atoi(portname + 3);							// COMx and COMxx
SerialParams.DCBlength = sizeof(SerialParams);
return com.fd;

There is a type at the beginning as well:

//COMx
else {
	com.port = calloc(1, sizeof(char) * 5));
}

There is one bracket to many on right side. It should be:

//COMx
else {
	com.port = calloc(1, sizeof(char) * 5);

Sending appears to be working correctly, but I have trouble receiving data.
Is there something where i can define a receive buffer size?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.