Need a Switch component controlled via USB port - c#

I need device switch component which an be controlled by code(.net,C# Or vb) ON/OFF state is enough..
I have code knowledge in C#, .net window application, I need to make a switch that can be controlled using code via USB port ... so that using that switch I will turn on/off electrical devices (fan,light) for a specific time interval.. For my MINI Project
Note: I need the brief note regarding components needed and how to assemble it.
If you know any link which resembles this type of project pls refer me.
thanks.

You'll probably want to look into using an FTDI chip for this purpose. They do have a .NET interface available as well as traditional C DLLs.
FTDI offers two types of drivers - one emulates a simple COM port (Virtual COM Port, which is probably enough for you), and the other is more of a direct USB control (D2XX), although it still shows up as a COM port when the USB device is connected.
On the other hand, if you really only need on/off support, you could probably just use the .net serial port drivers for the most basic communication. Of course, the serial port drivers don't let you tie a serial port pin high or low, so you will need some method of reading the data coming from the PC. Many microcontrollers have freely available UART libraries exactly for this purpose, but you will need to also obtain an RS232 level shifting IC for this because the serial port from the PC outputs +/- 6V IIRC (might be +/- 12V), while most microcontrollers run off of and accept signals at 0/5V or 0/3.3V.

You could try something like the Arduino or one of its clones like the Sanguino. It's probably a bit overkill for your project, but they come pre-assembled and have a large support base.
You would also (for any low voltage switching circuit) need some form of relay board to switch electrical appliances that run on mains power. See here for some ideas.

Are you sure you have to do this with the USB port?
You'd need a device that implements a whole USB interface. This isn't as simple as using a line on the COM port (RTS/DSR etc...) or using the parallel port.
A quick search found this...

Related

C# interfacing between pc and Omron servopack sgdh

I need help to write code c# interfacing between PC and Omron Servopack by rs232 to USB connection enter image description hereto drive ac servomotor
Using RS232 (CN3) to control this servo is not the best practice as it is not immune to EMC interference and is a port for driver setup (you will not be able to take graphics, and adjust the servo tuning while controlling through this port).
Consider researching the driver model you have and, if you have a fieldbus (Mecatrolink, DeviceNet, Profibus...), you could check how to use these protocols in a software (which I'll warn you, it's not trivial).
It all depends on your purpose, which could have been better explained in the question, as there are countless other approaches we can take...

Arduino USB Driver

I want to make a program to interface with my Arduino through an USB port. I am already quite experienced with C# (which is the language I want to use), but I cannot find a way to install the Arduino USB driver without also installing the IDE. Can I download them somewhere? Or is there a better way to use USB (I do not need to upload any code to the board with the program)?
I know that there are a lot of tutorials on making the program, but they all seem to use the SerialPortclass which I assume is not the actual USB port but just a serial port made by the driver.
In short:
Q1: Where can I download the Arduino USB driver?
Q2: If I can't, what is the best way to do communicate using USB (maybe another driver or library)?
(Please tell me if my question does not make sense, this is the first time I am doing something with USB)
The "original" Arduinos that have build-in chip for serial communication are using FTDI's FT232RL chip. Here's the driver for these: http://www.ftdichip.com/Drivers/VCP.htm
The most cheap clones of those Arduino boards (from eBay, Aliexpress, etc) are using the CH340 chip for serial communication. Driver for these: http://www.wch.cn/download/CH341SER_EXE.html

Getting video with USB SPI from device with FTDI

I need to implement Device manager for some card with FTDI chip.
We are looking into JAVA or C#, and we need to use it for transferring vedio using SPI.
Do we need to use FTDI DLL for java or C#?
Can we encounter serious problems implementing this in java ?
I have used the direct connection with the FTDI DLL using both Java and C#. For Java I have used ftd2xxj, even contributed some extensions to that. Works very and seems actively being maintained. I switched to C# 2 years ago and I'm using the wrapper provided by FTDI FTDI C# Wrapper. This also works perfectly, and I would say using one of these libraries is the recommended way to connect to your device instead of using a serial port connection. You can tune a lot of things such as the latency on the USB port and packet buffer sizes and such. I can imagine this can come in handy with video.
The Java option is fully open-source and business friendly, the C# version is provided as is without any restrictions to redistribute etc.
I have an app that uses ftdi. The solution I selected is to use a C DLL and call the c routines with JNI.
There's also the libftdi/libusb approach if you want a more open source approach. I'm not to sure what interfaces to these exist for Java and c# though.
I have tested multiple FTDI chips in C and C# to do USB to SPI/I2C from Windows.
For Video generally SPI with an extra pin called D/C (data command ) is what is supported by displays devices.
Here is a video with an FT232H board + an OLED 128x64 display in SPI
I used the default ftdi windows C SPI library. The FT232H can deliver up to 3M byte/S in SPI in theory.
The device Nusbio (based on the FT232RL) also support I2C/SPI at a smaller transfer speed and works with the OLED 128x64 display in SPI.
Nusbio can deliver up to 20 K byte/S in SPI for display. The Nusbio library is written in C#.
I am currently experimenting with the FT4222 chip in I2C or SPI using the FTDI C library on top of which I wrote a C# library. The FT4222 can deliver up to 500 K byte/S.
In conclusion you have to pick your chip and if your OS target is Windows C + C#
would be my advice. FTDI does not provide a lot of support/samples for C#, but that is what I do.

How can I determine the speed of a USB port?

Is there an easy way to programmatically determine the speed (or version) of a USB port? I'm looking to control the speed of data sent to a usb port based its maximum bandwidth.
If you need a solution for Windows this should be a good start:
http://msdn.microsoft.com/en-us/library/ms793313.aspx
Basically you should try this:
Enumerate the USB devices and the symbolic names to their drivers
Open a handle to the USB device driver through its symbolic name via CreateFile
Perform a DeviceIoControl on the driver handle with the control code IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX. This will have you returned the structure USB_NODE_CONNECTION_INFORMATION_EX. There you have a member there called Speed of the type USB_DEVICE_SPEED.
(Close the driver handle)
This could also be interesting for you: CodeProject: Enumerate Properties of an Installed Device
To answer your question, I'm sure that there are ways of getting the information you need. I don't know the answer for windows, but Linux has files you can read within the sysfs directory structure.
Speed control is usually taken care of by the drivers and the hardware controlling the bus. Most modern USB controllers really have 2 controllers per port connected. 1 for the slower speed 12Mbps USB 1.0, and another for the higher pseed 480Mbps USB 2.0. There is a magic switch inside that connects it properly. The driver itself makes sure that everything is enumerated properly, controls the flow, etc. A higher level "user-space" application typically doesn't need to worry about these things.
Also, if you have a device that is capable of running at faster than 12Mbps, and you plug it into a 12Mbps port, it'll get dragged down to 12Mbps whether you like it or not. Is it that you want to know that is got dragged down?

Serial Communication

I have a Program that uses serial port communication to talk to some hardware. No problem.
Then I added two GSM Modens to the picture. In VB I opened the COM port to the modem with one protocol (8 data, none, 1) and when the communication between modems was open and running I closed the port and reopened it with a new protocol (7 data, even parity, 2 stop) to my hardware. The hardware is standardized to this speed several years ago so I can not change this and most modems do not support 7, e , 2 protocol.
I want to expand the support of modems and many of them break contact when the port is closed. I'm not using hardware handshaking.
So here is my question.
How can I best change between protocols with out closing the serial port?
Does anybody have another idea how this can be done without changing any hardware settings?
Make a virtual serial port? (how?)
Ideas?
To truly set all options of your serial connection you should use the Win32 API communication functions. As far as i know you don't need to close and re-open a port to get these settings active. The will work right after setting them (like in this example).
You just have to take care, if you want to change just one or two settings, that you have to prefill you structure with the corresponding GetX function, make your changes and call the SetX function.
Maybe in contrast to the sentence before, but don't rely on default settings on your first SetX call. I've seen a lot of programs just altering the popular settings (e.g baudrate, stopp bits, etc.) but not the rare ones (like XoffChar, etc). If you just do that and another program will change these settings you start wondering why your program is suddenly not able to communicate anymore with your serial device, because you use the settings which another program set to the serial port.
And before i forget, if you like to use Win32 API functions in C# take a look at PInvoke.net

Categories

Resources