I have a plugged usb-serial device plugged to my windows and serial mapped it using virtualbox e.g COM1 -> /dev/ttyS0..
Now how will i know which serial port my device is using.. I know right now im using /dev/ttyS0. but what if i don't know?.. Linux Debian is creating this permanent serial port devices on boot time /dev/ttyS0-S3.
How can i make a test that /dev/ttyS0 is the real port im using in c.
Here's my way of testing if it's the right port or not.
devfd=open("/dev/ttyS0",O_WRONLY | O_NOCTTY | O_NDELAY);
if(s_fd<0) exit(1);
printf("open\n"); //It will always return true printing open because this device is created on boot time and is always available. so i made another check and that is to write to the port(Assuming i have set the permission to have full access to the serial port). if i can write to the port then it means it is really the port im using.
test=write(devfd,"ATZ",4);
if(test<0) printf("Can't write to port: Maybe not the serial port ur using\n");
printf("Device is avaialable\n"); // returns true because we can write to the port
Can you show me other samples in c of how can Check serial port if there's a device plugged to that serial port?
Or a test in c to the following serial port /dev/ttyS0 - /dev/ttyS3 if the following have devices plugged on them.
Thanks.
/proc/tty/driver/serial
file. – sawdust