veeso / termiwin Goto Github PK
View Code? Open in Web Editor NEWtermiWin: a termios porting for Windows
License: GNU General Public License v3.0
termiWin: a termios porting for Windows
License: GNU General Public License v3.0
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.
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?
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
... 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?
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!
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:
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?
I currently try to get libmbus to compile on windows and use your termiWin.
I miss:
Do you have any idea how to add them?
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("\\.\"));
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.