How to detect if /dev/ttyGS0 is connected or not - c++

I am writing a c++ program on my linux device where I can connect the device's micro usb to my computers (host) USB port. I want my program to detect if /dev/ttyGS0 has a device connected to it or not and if it does, I want my device to connect to it right away without having to send any data from my computer. And if it disconnects, I want it to also detect that and close the port. I do not want to use libusb for this. I want to use a different library.
As of now, I am using the fcntl.h library. I'm open to any other libraries and suggestions.

Related

Serial communication over RS232 and USB

I plan to write serial driver to send data from target to host. The target is a renasas RX62N. And the host is windows 8.1. The target has RS232 port and the host has a USB port. I plan to use a converter cable with DB9(not sure) and USB connectors. 1) would like to know if I can send and receive from target and host? 2) would like to know if there is a way of getting around writing USB driver to send and receive from host is there software(Program) that could monitor usb port and send and receive dats over USB port? Ive seen software that let you send data and see the data receive by a port.
(1) RS-232 is bidirectional. You can send and receive at the same time.
(2) You do not have to write a USB driver for the host. Windows has this built in. Use the standard Windows serial I/O calls. They work the same way for serial ports and for USB to serial converters.
The USB<->RS-232 converter cable will appear to the PC host as a legacy serial port, support for the CDC/ACM USB profile that implements this port emulation is built into Windows, Linux and OSX. In windows however you will normally have to install "driver" which in most cases will simply be a INF file that maps the cable's USB vendor/product ID to the usbser.sys devive driver. Some USB/Serial devices may have custom drivers.
Common USB CDC/ACM devices from FTDI and Prolific will install drivers automatically via Windows Update (though historically Prolific drivers have been problematic - though recently they have improved).
At the target end, you communicate via the UART that is wired to the RS-232 line driver as you would normally.
For basic testing and keyboard/screen console access to your target, you van use any terminal emulator software such as TeraTerm, HyperTerminal, or Putty.

Windows form application for USB port

Previously I have work with Windows Form application to establish some RS232 connection. I used the already provided serial port component (SerialPort), and I was able to establish RS232 communication relatively easy.
Now, I was wondering if there will be something similar in Winodows Form application to establish a USB communication ?
It seems there is this WinUSB API that provides a very low level interfacing with the device.
However, I am not sure how easy will that be? Also, not sure how easy will it be to integrate into Windows Form application ?!
Will there be a simpler version of such USB interface API?
I don't have to stick to Visual Studio. Is there other c++ USB API, besides WinUSB, that is more standard that people use? I would like to develop a GUI API that does some communication over USB. If need be, I can use Python or some other tools if it facilitates the process?
Thanks in advance.
Although USB is a serial protocol, you can't treat USB like a serial port:
It's dependant on what the actual device is. For example a mobile phone, may provide several "endpoints" for USB, one being a serial port to use the phone as a modem, one as a storage device allowing you to transfer photos and music files to/from the phones storage, and as a camera device that you can take photos with. All of these have different behaviour and need a USB driver-plugin to make it behave correctly - these are typically shipped with Windows, and your phone will appear as COM5:, the E: or "Samsung Galaxy S3 Mini" drives and as a camera under the "cameras and scanners".
Of course, you can programmatically open all these devices, but it is done as the device-type that they present as on the inside of windows (so you use serial port functions or file functions or camera functions).
You CAN also write a device driver for a device, if you have sufficient details of how it works.
But there's no real way to "open the port". The USB API is a driver API, not a user-mode API. Here's a page to start from to understand USB drivers:
http://msdn.microsoft.com/en-gb/library/windows/hardware/ff540215%28v=vs.85%29.aspx
There is a WinUSB driver, which allows a single application to access a single device, assuming you know how to operate that device.

What usb device is connected to a usb port

I'll try to keep this simple.
I have a hub connected to my PC. This hub has several USB interfaces. I'm listening to WM_DEVICECHANGE event and I get the USB interface path. How can I know what port it was connected to? Looking for a non-WMI solution in c++ or c# for a windows environment.
I tried using IOCTL_USB_GET_NODE_CONNECTION_NAME with USB_NODE_CONNECTION_NAME (where USB_NODE_CONNECTION_NAME.NodeName will hold the path to the device) but this only works if the device connected to the port is a hub as well.
Any help will be much appreciated.
The primary issue in C++ is that there is no standard functions for detecting USB ports.
USB Port identification and implementation is a platform specific issue. For example, Linux handles USB ports quite differently than Windows and many embedded systems don't have USB ports.
So you'll have to look for a 3rd party library or find some OS API to use for your platform.

iPhone/iPad wifi tcpip connection to other computers on a wifi

I have multiple computers on a Wifi router. For the iPhone/iPad In objective-c how can I determine what computer is on what tcpip socket address so I can choose and connect to that computer? (each computer is a socket server written in c++ and I need to be able to easily check the status that is out putted)
If your computers are all Macs, it is pretty easy. Simply use the NSNetservice class to advertise the service and the socket port that you already have.
Then, on the iOS devices, simply use a NSNetServiceBrowser object to look for your particular service by name, and connect to one or all of them as required.
If your computers are not Macs, you can look into Bonjour for Windows, or any Zeroconf implementation such as Avahi on Linux.
TCP programming

best method to find the COM port to which my embeded device got connected in my vc++ program

I want to find the COM port my device got connected in my vc++ program.
upto now i used to scan all the ports from 0 to 15 and send some command if the reply is suitable to me i can confirm that it is the port i am finding.
But this is Taking a lot of time.
anyother solution???
The serial API does not provide for any of the sort of identification that you seem to desire so the only choice that you have is to poll he various ports. If the device is a USB device, you may be able to garnish clues from the friendly name associated with that device (see How do I get the friendly name of a COM port in Windows?).