Serial input through Parallel port - c#

Can any ony kindly explain that how we can take serial data as input from parallel port using c#.
Or the serial communication through parallel port.

I really wouldn't transmit your data this way as you are heading for a world of pain. Far better to use a serial to USB IC such as the excellent ones made by FTDI. In simple terms these take your TTL serial data send it via USB. Thanks to the FTDI drivers the data appears as a virtual serial port which your program can read from in the usual way.
Hope this helps.
Ian

It is not clear from your question if you are looking for a software or hardware solution. AN external serial to paralell converter (hardware) provides the simpliest solution.
If you are looking for a software only solution, you want to do "bit banging". Unfortunately this requires precise timing, something which may be extremely difficult in managed code. This sort of program is typically implimented in a lower level language such as assembler or C where one has direct access to the hardware. Here is another article specifically addressing the use of the paralell port for serial communications.

It sounds like you're doing something wrong. If you need serial input, why not use the serial port? I believe that the RS232 standard is widely supported. The parallel port is for parallel data transfers.

Related

Implement a Bluetooth 4 host/application with a COTS dongle?

I haven't found any very good resources in my search for answers to this question. At present I am using a TI CC2540 HCI over COM Port. I would like to move away from this solution for cost reasons. Commercial bluetooth low energy USB dongles can be had for very cheap. Let's use a CSR8510-based device for example.
I would like to implement the host and application with the CSR8510 dongle acting as the 'controller'. It does not use a serial port for HCI transport. How can I send/receive commands from this controller? CSR Support is not interested in discussing this because my quantities are too low (~10k)
I would like to specify certain low level options such as connection parameters, scan modes (limited discovery, general, etc.) so I need a relatively high level of control over the 'controller' dongle. Writing a kernel mode driver is not a route I can take.
Example dongle
The linux kernel will handle a lot of stuff for you if you open up an HCI socket. You can also open up L2CAP sockets to make connections to devices. Unfortunately the documentation is lacking (I've actually never found any), but the source code is fairly readable. Take a look at the Bluez gatttool to see how they access bluetooth dongles via sockets.
Note: there's a nasty bug in kernels <= 3.4 where multiple L2CAP connections get mixed together when using an L2CAP socket.
Here's a previous answer I gave to another question with some sample code: bluez with simultaneous classic and low energy devices

Most appropriate language to create a Windows application that can serially communicate with hardware via USB and Bluetooth?

So I need to create a PC application, that can serially communicate via USB and Bluetooth to a hardware device.
EDIT: This device is being made by the company I work for and I will be working hand in hand with embedded programmer who will take care of software on the device. My only real concern is creating an interface on the PC and sending that information serially by either means to this device.
The vast majority of the application will stay the same including the serial data, the only difference being the type of communication.
I have a fair amount of experience in Java, some C/C++ and significantly more experience in Android.
I was thinking C# for the ease of GUI and it's .NET capabilities.
Any suggestions based on knowledge or experience would be appreciated.
Thanks
PS. Any information on how Bluetooth protocols vary between different PCs would also be very helpful
There are various suppliers of Bluetooth software for Windows: Microsoft, Broadcom/Widcomm, BlueSoleil, etc. They can each generally use any USB dongle.
Another good reason to go with .NET is that you can use my Bluetooth library which supports all of those stacks and more. :-) http://32feet.codeplex.com/
Connect with BluetoothClient etc. e.g. 32feet.NET docs -- General Bluetooth Data Connections
I've done exactly this with Serial over Bluetooth using an Arduino microcontroller. I used C# for interfacing with the micro, and XNA for displaying information (3D graphing).
Couldn't recommend it more as an approach, C# is really easy to use for serial.
Take a look at Visualising Serial Data: Arduino, I2C and XNA for detailed instructions.

Serial data logging

I have a device connected to my computer that sends serial data to the computer every 5 mins. I want to write a basic program to capture this serial data every 5 mins and put it into a database. I was hoping to use C# because I have used C# with databases before and found it quite easy.
Can anybody offer me any advice on how I might do this, I really have no idea where to start and I know in theory it sounds easy but when I started it I actually found it really hard.
Using C#, you can use the System.IO.Ports namespace to communicate over the serial ports - there's a nice article here.
Alternatively, you can use Python and the pySerial module. I've written an app to communicate over the serial port using pySerial - it's quite easy to use, and can run on many different operating systems including OSX and Windows (I'm assuming you're using Windows). Python also has built-in support for SQLite.
The problem with capturing data on a serial port is that serial ports aren't thread-safe, so if there is more than one listener, data will be corrupted.
If you are absolutely sure that you're the only one listening for data on this port, .NET has a built-in wrapper, System.IO.Ports.SerialPort, which you can use to connect to COM1, COM2, etc. You'll need to know the rate in bits/sec at which this device sends data (its baud rate), its error-checking (parity) protocol, and the format of the data it is sending (you'll get it as a byte array, which you must convert byte-by-byte into data you can work with). Then, your program should be able to open the port and listen for DataReceived events with a handler that will read and digest the data. Again, it's VERY important that you never have two threads trying to read at once; the easiest way is to set a volatile boolean indicating that a handler is reading data; if another handler is ever spawned while a previous one is still running, the first thing the new one should do is read that value, and since it's set, exit the new handler immediately.

Windows Monitoring a parallel or LPT port

Does anyone know a good library to allow us to programmatically monitor a parallel port (or LPT port) in windows. There are lots of good ones for Serial ports but I have had no luck yet for parallel ports. C# would be preferred but we're happy to do the Interop work if it's c / c++.
Thanks
You need a driver that gives access to the parallel port. The inpout32.dll solution is nearly universally used. It also lets you pinvoke helper routines to execute the INP and OUT cpu instructions. Everything you'd ever want to know about parallel ports, including coding samples for inpout32 is assembled at Jan Axelson's home page.
Are you looking for something like this? How to find available parallel ports and their I/O addresses using Delphi and WMI its in Delphi, but I think you can find WMI in C# too.

Serial Port Redirection or Splitting [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I am looking for a book and or a code sample of how to do serial port redirection or port splitting. I write a lot of com port applications and want to write a monitor application that will allow me to watch the serial port between the application and the device.
So I want to be able to redirect the serial port to another port so I can monitor the data flowing between ports.
I understand in some cases this must be accomplished at the kernel level. (in USB cases)
I have written the monitor application using system.IO.Ports in C#. If I have to call a C++/C assembly that is fine.
Thanks
Joe
You might find that PortMon by Mark Russinovich is helpful in your work, although it isn't provided with source code. It will log all system calls related to a port, and has extensive filtering capabilities to keep that log to a manageable size.
Edit: PortMon works by injecting a kernel mode device driver into the system when it runs. That driver hooks the ports that it wants to monitor by inserting a filter driver into the stack. That filter driver reports all IRPs that pass through it to the application. This is not an easy beast to implement by any stretch, and it really can't be done in user mode.
The Windows DDK does have sample code for a port filter driver, but it is a lot of work to go from the sample to something useful.
A pure user mode solution that might work out is to use two additional serial ports to eavesdrop on the wire. A pair of USB to serial adapters and a bit of wiring will do what you need. Then it is only a "small matter of programming" to monitor and correlate the send and receive lines. A single chip solution could be based on the FT2232H device from FTDI, which has an available evaluation module. Add a couple of RS232 level translators and some D connectors and you've got a serial eavesdropper on USB that looks like two COM ports to Windows.
Another outside the box approach is that many logic analyzers and mixed signal oscilloscopes can do serial protocol decoding, often as an optional component. One source of inexpensive USB+software solutions is Saelig. I've bought chips and modules from them myself, but don't have any direct experience with any of the USB-based logic analyzers they sell despite thinking that I should have one in my bag along with the Netbook...
I wrote one, many years ago. The DDK (device driver kit) included sample source code for a filter driver for (i.e. immediately above) the parallel port driver: I adapted this sample to work with the serial port driver, and then added functionality such as monitoring and splitting.
This was serial ports, not USBs.
I also implemented another driver, which was a 'virtual' serial port, i.e. it implemented a serial port API but then redirected the data I/O elsewhere.
It was a lot of work (many months) to implement.
As always it depends on what you're going to do. If you need to mess around with how the lines between two serial devices are connected or need some 'good' timing informations, the best you can get is an external break-out box like Anthony already told.
If you just need some kind of monitoring you can go with PortMon or Serial Port Monitor.
Maybe you write two applications which are going to communicate over a serial connection. To get this done on a single PC without a local loopback cable you can try Com0Com.
Purchase a RS232 DB9 Serial Data Tap. This is a hardware device that is connected between the two serial ports and listens passively to the "chatter" between the devices. I used the following device for two-and-a-half years and it saved me significant amounts of troubleshooting time and effort. (I use to take it home every night to keep support technicians from "borrowing" it.) It is easy to make this device, but the following data tap is flexible.
"Tap in on a serial data stream and transparently monitor data activity. The output can be feed into a monitor printer or other device. Dipswitches allow programming to monitor the main transmit and receive lines, individually or together. No external power required, easy install, transparent connection Ideal RS232/Serial software development aid."
Alternatively, make or purchase a Serial Tap Monitor Cable. See the NST documentation for one possible configuration.
I strongly recommend you do not use a software solution because the monitoring software may be affected by physical situations.

Categories

Resources