Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.3.4 | Serial port cannot open #13

Open
MLaudren opened this issue Oct 18, 2024 · 7 comments
Open

V0.3.4 | Serial port cannot open #13

MLaudren opened this issue Oct 18, 2024 · 7 comments

Comments

@MLaudren
Copy link

When using either server or client, with version 0.3.4,
I have an error: 'Device 1': Failed to open serial port. Error code: 2
image

Tried with different adapter and port, and also running as admin, but could not get it to work

If I do the same with version 0.1.5, all is working great.
Likely the new Modbus library have issue ?, as explain here: #10 (comment)

@serhmarch
Copy link
Owner

serhmarch commented Oct 18, 2024

Hello. Error code: 2 is the value returned by the standard WinAPI function GetLastError() and means ERROR_FILE_NOT_FOUND according to the Windows documentation.

As I see in Project window you're using RTU:COM34. COM34 doesn't look like a valid serial port number. I just repeated your settings in server v0.3.4 app on Windows and I got completely the same output that you have. And this is understandable because I really do not have serial port with the name COM34 in my list of serial ports.

Maybe you selected COM3 and then accidentally pressed 4 and thus got COM34?

@MLaudren
Copy link
Author

Hi Serhii,

I am using a lots of serial cables/adapter, and as Windows assign them individually, this one got the com port number 34,
See in screenshot from Device manager.

image

Same adapter, using Com34 is working fine with older version as I said.

If you think of tests I can do to narrow the area/cause, let me know, and I'll do.

@MLaudren MLaudren reopened this Oct 21, 2024
@serhmarch
Copy link
Owner

Its hard to say what is cause of the problem. This error can occur only as result of CreateFile standard WinAPI function execution:

            ...
            d->serialPort = CreateFileA(
                d->settings.portName.c_str(), // Port name
                GENERIC_READ | GENERIC_WRITE, // Read and write access
                0,                            // No sharing
                NULL,                         // No security attributes
                OPEN_EXISTING,                // Opens existing port
                0,                            // Disables overlapped I/O
                NULL                          // No template file
                );

            if (d->serialPortIsInvalid())
            {
                return d->setError(Status_BadSerialOpen, StringLiteral("Failed to open serial port. Error code: ") + toModbusString(GetLastError()));
            }
            ...

https://github.com/serhmarch/ModbusLib/blob/63b40ec78d7bc81d4fa02a45b27020ddf3585154/src/win/ModbusSerialPort_win.cpp#L77

It might have something to do with the input parameters of the function.
First, I need to expand the error message in the next release, and then you can take new screenshots to see what values are passed to the function.

@serhmarch
Copy link
Owner

Hello. Please try new v0.3.5 version. Lets see what it would be.

@MLaudren
Copy link
Author

MLaudren commented Nov 7, 2024

Hi @serhmarch ,
I've done some tests, but still not working.

Server still cannot open the port
image

Client same as server
image

I'll try to test more later.
I didn't saw any logs I can share.

@serhmarch
Copy link
Owner

serhmarch commented Nov 7, 2024

Hello. This behavior is also possible if the string COM34 somehow contains non-ASCII characters (for example, in Cyrillic there are all three characters COM looks like the same as in Latin, but they have a different byte code). + in version 0.1.5 it was not possible to enter the port name manually, only to select from the drop-down list, in this and previous versions it is possible.

I realize that in this case it is unlikely, I just left it here as an option.

Then please specify the version of the operating system and hardware. When I'll have time, I will try to run it on different machines, maybe I can get the same result.

@MLaudren
Copy link
Author

MLaudren commented Nov 12, 2024

Hi @serhmarch ,

I'm running the application on Win 11 Pro (23H2)
As for the hardware, I have some FTDI base USB/RS485 adapter, B&B Electronics USOPTL4, and other 3rd party cables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants