Why is it possible to open serial ports (COM) on Windows using file functions?

Asked

Viewed 92 times

4

How does this happen? There are other ways to open or just this Digo, in languages like C, PHP, Python, etc.

1 answer

4


Because they are files. Or at least a form of. It’s not just in Windows. It makes it much easier for the operating system to treat certain devices as if they were files. After all what you will do in a file is the same as what you would do in the device, read and write data.

Files, from the user’s point of view, are streams data, where they are physically does not matter, except for the lower layers of the operating system.

This is the form available in the operating system.

  • how would be the path of that file in windows? I try . COM but it can only open and write and can’t tell if it exists, read...

  • In general it exists. As the ideal is not to verify the existence of something but to try to use and see if it gives some error, thus avoiding a race condition, does not need to have a way to check. What can be done is to list all existing devices to know if it will be used. The "file" COM exists.

  • Yes, but how will I read? because I have to pass the file path, however it n identifies or says that the operation is not allowed, which would be the path of the "file"

  • Then you have to ask another question, say what language you are using, etc. But the way is "COM1", "COM2", etc.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.