Activate and deactivate usb device in c? - c

We have a laser scanner which is connected all the time to a certain usb port.
The usb device should be deactivated normally.
Only at certain times I have to activate this usb device at the usb port with a litte c program.
So how can I activate a deactivated usb device in c?
Thanks for your information.
Update:
I forgot to mention to operating system: Windows XP, Windows Vista, Windows 7, ...
The laser scanner is a Honeywell Voyager MS 9540 product.
In the documentation I read that if the usb scanner is connected to a serial port, you can send enable and disable commands over the serial port in order to enable or disable scanning. But I thought it would be easier to simply enable or disable a usb port/device.

I bit more information would be useful ...
For usb connection you can use libusb (see also: libusb-win32). Since it's used by CUPS (a printing software) too, i guess its ideal for you.

Related

Force connection on specific USB port/symlink

I am planning to use Dump1090 and I want to have 2 RTLSDR dongles on the same computer, always plugged into the same USB port. I am planning to assign a symlink "adsb" to the port for the RTL dongle that has an ADS-B antenna connected to it. Is there a way to force the connection on this specific USB port?
By default, the code takes the first device available.
Thank you
https://github.com/antirez/dump1090/blob/master/dump1090.c

Linux Serial Device Server over USB?

I have an embedded Linux solution and want to create a command service over serial USB. The idea being that when a computer connects to my embedded via USB, they see a serial device and send serial commands to me through that port and I send responses back.
I need some help in the direction to proceed. Do I need to emulate a serial device so they see me as a COM port? Is there build in Linux solutions to broadcast my details as a serial device? Are there code examples? I can see block devices connect with my embedded solution like a USB storage device. When I plug into another computer, I would like it to see me as a serial COM port.
I just need help in the direction of which path I should go down to solve this.
Thanks in advance.
What you are looking for is the Linux USB serial gadget. The Linux USB gadgets framework allows devices to behave as a variety of standard USB devices, including serial devices, Ethernet adapters, and mass storage devices.
Note that USB gadgets will only work on targets with a USB controller that can be set to operate as a USB device. Not all USB controllers and target devices are compatible with this configuration. For instance, most PCs have a host-only USB controller, and the Raspberry Pi Model B is not compatible with gadgets because it contains an embedded USB hub upstream of the USB ports. (However, the Pi Zero is fully compatible with gadgets.)

How to dump/burn program into LPC2148

I have LPC2148 daughter board but I am not able to dump/burn code into it, and it doesn't have any usb connector to dump code.
I read on internet by using FT232RL I can able dump code into LPC2148 but I am not able to do so.
please give me solution
thank you..!
The chip supports In-System Programming (ISP) via an on-chip boot loader ROM.
From the User Manual UM10139:
Programming of the Flash memory may be accomplished in several ways:
over the serial built-in JTAG interface, using In System Programming
(ISP) and UART0, or by means of In Application Programming (IAP)
capabilities.
The function of the FT232RL you mentioned is to act as a USB/UART bridge and is necessary primarily because modern PCs lack legacy RS-232 serial ports. You can in fact purchase a USB-Serial cable or adapter which will contain a bridge chip such as the FT232RL. Most of these use RS-232 line level signals, so you would still need an RS-232 line driver/receiver to connect then to your board (if your board has a serial port, it probably already has a line transceiver and you can connect directly to that). It is possible from specialist suppliers including FTDI themselves to get a USB cable with integrated FT232 and bare TTL level connections to connect directly to LPC2148 UART0 Rx/Tx lines.
If your board does not already expose a UART0 serial port and the necessart control to start the boot loader, a Serial Port Bootloader Interface board is available. For that you may then also need a USB/Serial adapter or a PC with a legacy serial ports.
Once you have a suitable serial connection, you will need the LPC2000 Flash Utility software to run on the PC.
The JTAG option is however faster, and more powerful since the JTAG is both a programming and debugging port. With a suitable toolchain and JTAG adapter it is possible to program and execute code with source-level PC hosted debugging including break pointing, data watching and single stepping of the code.

Stm32 Virtual COM Port - Can not connect

This is a code, part of my project;
//----------------------------------------------------------------------------
// USB: Virtual COM ----------------------------------------------------------
//----------------------------------------------------------------------------
USB_Interrupts_Config();
Set_USBClock();
USB_Init();
while (bDeviceState != CONFIGURED)
;
//----------------------------------------------------------------------------
// Main Loop -----------------------------------------------------------------
//----------------------------------------------------------------------------
while(1)
{
USB_printf("Main Function");
GPIO_SetBits(GPIOC, GPIO_Pin_10);
Wait(200);
GPIO_ResetBits(GPIOC, GPIO_Pin_10);
Wait(200);
}
After plugging my usb to the Circuit, Virtual COM Port Driver installation finishes correctly and LED blinking is also OK.
But when I try to connect COM port via Hyper Terminal or 3th party tools, I can not
achieve it.
Is there any opinion?
Thanks..
I had similar issue with a slightly different wording - it is possible to connect to the device until it's reset. My custom board would enumerate VCP correctly but would not connect after device reset. Turns out, that USB host keeps the enumerated address for the device, while device looses its address after reset/reprogramming. To avoid such issues, software reset should also perform USB physical layer reset (disconnecting pullup on D+/D- pin, depending on the speed used). In such a case it should be possible to connect to the device after disabling and then re-enabling it in the device manager or re-plugging
Not Necessarilly the answer but may be worth checking.
If your periodically send information out of the COM port and it appears your program does ( never used STM32 ), Windows (hyperterm so I assume windows XP) can detect that as a serial mouse and enumerates it as a mouse thus opening the port and preventing any other application from using it.
We have had many issues with this with our devices (CP2103's from SiLabs), and also is a common problem with GPS recievers.
This answer GPS Detected as serial mouse as a good description of the issue and possible workarrounds.

Detecting a RS-232 com port in Linux

I have an ECR(Electronic Cash Register) device,it has a RS-232 com port cable for the connection to PC but I have not been given any drivers for it. I am trying to connect the device to PC but PC is not able to detect the cable. How to detect this device attached on this RS-232? I am working under Linux. Any help on how to find the device is appreciated?
Following is the code snippet I found in C to connect to device based on Baudrate and Com Port number.
int OpenComport(int comport_number, int baudrate)
int SendByte(int comport_number, unsigned char byte)
int SendBuf(int comport_number, unsigned char *buf, int size)
Please see my answer to a related question which shows how to open and configure the serial port.
On Linux, serial ports are almost always /dev/ttyS[0123] (that is /dev/ttyS0, /dev/ttyS1, etc.) for the hardwired ports, and /dev/ttyUSB* for USB ports. The hardwired "devices" may appear only when the hardware is present on some distributions. On others, they always appear whether there is hardware or not. (Try cat /dev/ttyS2 and see if you get the error "no such device".) This is a kernel configuration option which is frequently set to create the device entries whether the hardware is there or not.
The USB ports are present only when there is hardware plugged in, but if there are multiple USB serial ports, it can be difficult identifying which is which.
There is a mechanism within /etc/udev/rules.d/* which can be configured if some aspects of the devices are consistent. See man 7 udev for details.
For applications I have written, I determine which device is which by writing to the device and identifying its response. For devices which don't respond, this is either a worthy programming challenge or a mundane configuration solution.
I think you need to do a little reading about RS-232, and well, C programming also. There are no drivers for RS-232. It is a very "dumb" protocol - you basically just shove data out the port.
The PC cannot detect the cable? That's because it's not USB. Believe it or not, Plug-and-play didn't always exist; you tell the software what port the device is supposedly connected to, and it tries to talk to it.
Furthermore, those aren't "code snippets", those are just function prototypes. There isn't any actual code there.
1>since there's no operating system on your ECR so I guess u don't need any drivers ,instead a firmware will be there in the ECR , which tries to communicate with your Linux UART driver
2> Rs-232 is basically a serial protocol , I mean it has 9 wires , and hence a connecter with 9 pins are used DB-9 connectors ,all the communications inside a processor is in parallel format so a chip called UART is used to convert all the parallel data into serial data , and since yu want to pass the data in Rs-232 format , it needs to be packaged in that format .
3> Linux kernel already has a uart driver , which is implemented for RS-232 . so need to worry about drivers from Linux side.
4> Open a terminal type " dmesg | grep tty " ( connect only the ECR to the PC for rs-232 ports ). it will return something like ttyS or ttyUSB etc , however u just concentrate on ttyS if u have connected only through rs-232 cable .
5> Once u are sure of the ttyS device from the dmesg use minicom (its easy to use ) to communicate with the device.
regards,
Zubraj

Resources