I am looking for something to test my app. The app is a weight logger, built in .net 3.5 - it is connected by rs232 to an electronic weight, but the problem is that I don't have it at home.
I wanted to emulate the traffic and data with my app, but I have a problem: I can't get 2 apps on 1 port.
Please help.
These are the tools you need:
com0com: Creates two virtual COM Ports which are connected to each other
Just connect your receiver application with the first one and your mock weight application with the second one.
Serial Port Monitor: If you need to sniff into some serial port connection to find out how another application communicates with some serial device.
Update
The storing and filtering is just to specific to your concrete project, so that you wouldn't find anything "out of the box". But you have two possibilities to store the data.
Within your application implement some kind of wrapper class for your serial port. Every read and write access to the serial connection goes through this class. Then this class sees everything and can dump the whole traffic into a file or somewhere else. Additionally you could also implement some kind of filter mechanism.
Instead of putting the dump and filter logic into your program, write it as an application. This application connects to two COM ports. The first is the real serial port. The other is a virtual from the com0com driver. Your application that normally communicates with your serial device will now be connected to the second com0com driver. So you're able to dump and filter anything that flows through your serial port.
Related
I'm developing a weather site, with several weather stations. Ever station uses a different method to post data to the server. They all work, except one. It's a brand new station, but uses a serial port. The company that installed the station connected the station to a Moxa Serial converter. Witch essentially sends the serial data over a specific TCP port to my remote server. Using Pccomm Terminal Emilator I can receive the data on my server. But how should I get my app to listen to this port for serial data. I tried Tcplistener, but it doesn't receive any data. Data is in NMEA format.
Thanks for the suggestions!
Without more specifics I can only give you some general hints, but here goes:
Many Serial-to-Ethernet converters include server-side software that will make the data appear on a virtual serial port. If that is the case, with the software installed you will see the virtual port listed along with the real ports in your system. You can simply open and read from that port as usual.
If that is not the case, but you are receiving data on a known TCP port and can view it using Telnet or something similar, then perhaps the Moxa converter is acting as a server and expects you to be the client. In that case you would want to use the TCPClient class rather than the TCPListener class.
The Moxa converter (you didn't give the model number) has a manual which may prove helpful.
If you need more help then you will need to post specifics about exactly how you are connecting with PComm and what you see, and exactly what you tried with TCPListener, and what happened.
gl
I've two problem when working with serial port (COM) which I cannot find any reason for it:
1-I've wrote a program in c# (wpf) to receive data from a micro-controller(micro sends some data continuously with an interval ,e.g every 100 ms) , when I run my program in visual studio it receives data but there are some delays in receiving the data; it receives the first three data then a delay and then some other data and continues this scenario without any discipline. I've tried both release mode and debug mode but no change. but when I go to Debug folder or Release folder and run the .exe from there every thing is ok and receives data continuously), I'm really confused!!
2-for connecting to micro I used usb-to-COM converter(cable with one side usb and other side COM port) . sometimes between the running of the program I disconnect the connection by pulling out the usb from my laptop(yet micro is sending) and when I connect it again to my laptop, mouse , app windows,... all move and I cannot control anything!
A USB serial port cable is actually a device (usually classified as a USB to UART bridge device, there's actually a UART in one of the cable connectors). By pulling the USB cable from your laptop, you're effectively removing the serial port device from your system, meaning your COM port no longer exists. If you do this while your program is running, I'd expect the program to crash. A connection over a serial port is a file stream connected to \\.\COM#
'#' is just a placeholder, it could be COM4, COM5, etc. depending on how many other serial port devices are active on the system. What you're effectively doing is similar to disconnecting a harddrive while your program has a file open on that drive. I would not expect it to end gracefully.
As for the data reception, serial ports are very slow by today's standards while computer programs are very fast by serial port standards. Also, while serial port input can be implemented as a blocking call, it will eventually time out. When it times out you're probably reading a 0-byte if you don't check for a time-out condition.
All I can provide you with without knowing more detail of what it is exactly you're attempting to accomplish and how you're attempting to accomplish it.
I only briefly started working in C# and I'm currently using RS-485 to communicate with some other devices but I don't seem being able to actually get the other devices to respond.
I was wondering if there were any way to write to a specific device using serial communication since it's all connected through COM Port 4.
I already know serial.Write(); but as far as I know it doesn't give you the option to choose which address you wish to send to.
Is there anyone who might know a answar to this question?
Best Regards
Cvr
Thanks for the responses. They helped alot :)
Kristof is correct, but to elaborate a little more:
When communicating with RS232 you simply have two endpoints, your PC and external device. You communicate with the device by sending it commands, or it may even send them regardless. It may be simple ASCII text or binary/hex codes. The way it communicates between the two devices is known as the protocol - and your application must implement this protocol to be able to 'talk' to the device.
RS485 is different than RS232, in that you can daisy chain multiple devices on the same serial port that is connected to your PC. Depending on your device it will have its own protocol that it understands which you will need to study and become familiar. This should be supplied with the devices you are connecting to.
Typically, the protocol will have (at least) the following information:
Device Address - it uses this to distinguish which device you wish to talk to, usually can be set by hardware toggle switches or the like
Command - the actual command that you wish to send to the unit
Data - Any extra data you may need to pass for specific commands
So, an example command you might send to the unit will look like (note this is only an example):
$01FF9A
Where:
01 is the module or devices unique address
FF is the command type
9A is the data
So here, the module with device address 01 will read the command and deduce 'hey you are talking to me' and then process the command information. All other devices will also receive the data, but will realise that it is not destined for itself.
Usually RS485 devices communicate using Hex data, so your application will need to send hex commands to the external devices, and handle the conversion to from for any relevant responses etc. You may need to look at Serial.Write(byte[], int,int) to send hex data to the devices.
For a more detailed explanation of .NET serial port class, refer to http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx
You can create an instance of the SerialPort class.
There you can define baudrate, portname etc.
After calling the Open() method you can read or write data to or from the port.
var port = new SerialPort();
port.PortName = "COM4";
port.Open();
I have an embedded system running a web server that will usually be connected to an Ethernet network so users can simply enter the IP address of the device to access it.
However, I also need to make some of the same website functionality avaiable to users of the serial port on the device. It would be nice if I could reuse some of the logic I've developed for the web forms for this.
I am currently using .NET for development on my desktop and my embedded device is Linux based. Is it possible to host website content via a serial port or is there some other means by which I can pull this off?
Just a wild guess: back in the days when you connected by modem to the internet, there was a SLIP protocol: IP over Serial Line. Could you use that to establish an "internet connection" to your device?
There are a few options:
If the server is to be in windows, and you have windows 7 then windows xp mode (1) (2) will allow you to use SLIP so that you can provision over serial as you would to any IP address by mapping the serial port to an IP address.
Alternatively there is a sourceforge project called Contiki which has source code to allow the same if you fancy coding your own (the class is called uIp TCP/IP Stack).
Let me know if this is roughly what you're looking for and I can focus in on your specific requirements if you like:)
Cheers.
The first thing that comes to mind is some sort of LYNX like browser (I don't even know if it exists anymore). Maybe easier would be to just do a simple command line interface? It's linux, so you should just be able to spin up a telnet session pretty easily, right?
I believe you should be able to configure your Linux distribution to point your serial port at a terminal, and have that terminal log in with lynx as the shell.
You might want to follow directions for a Linux serial console (tutorial here) and potentially create a user account with the shell set directly to run lynx. Instruct the login prompt (/etc/issue in the tutorial) with the username and password.
Edit: If you're just looking for some sort of data entry from the console, you could just write a shell script or other program and point that user's shell to that application instead.
You could build a TCP client application on your linux device that will talk to your linux web server and redirect data to serial port, and build a TCP server application for your users that will talk to their serial port and redirect data to some TCP port (like 12345). Then all your users need to do is to set their browser to http://localhost:12345 and connect their PC to linux device via serial port cross over cable.
I need to Determine the serial port name connected to other machine using c#.
This is just not the way serial ports work. It is not a bus, like USB or PCI, where you can plug something in and the operating system will do the ah-ha, new hardware! discovery automatically. Serial ports are very primitive, dating from the stone age of computer hardware.
It takes a human to plug a serial port device connector. With some luck, the connector will have a label which says what COM port number is assigned to the connector. Although that luck is hard to come by these days. She'll then tell a program to establish a connection on that particular COM port. Hyperterminal is the canonical implementation of such a program on Windows.
You cannot realistically open every COM port that might be available. That prevents another program from using another COM port. You'll prevent a modem from getting used for example. Part of the stone age legacy is that only one program can open a COM port, every other program will be locked out.
So, provide your program with a UI that lets the user select the COM port(s). Save the selection in your config data, it is very likely that the device is still connected to the same port when it starts back up. You can use WMI and the Win32_SerialPort class to provide a better description for the COM port (more than just the number). Some USB serial port emulators may set the Description property to something recognizable.
SerialPort.GetPortNames() enumerates the available COM port numbers. A basic sanity test is to check the SerialPort.DsrHolding property, it should be true when the serial port device is plugged in and powered-up.
A serial port doesn't report any connection state. You can open all available serial ports on your computer (if no other application already opened it) regardless if it is connected to something or not.
To find out if a serial port is connected to another machine, you have to open up all the available port, send your initialization data and listen if something correct comes back.
Imagine you have a good old serial modem connected to your pc. To find this out you have to open up all the available ports and send a 'AT' over the wire. If a 'OK' comes back you found a modem (maybe additional tasks are necessary to check if you found the right one [maybe there is more than one device connected to your pc]).
What i just missed out: Don't forget to configure the serial port! Don't set only baudrate and stop bits. Set all settings to the values you need (even if you use default settings). Cause these settings will be saved also if you close and reopen again. All settings are still valid unless you change them. Now imagine you have some other application on your pc that also opens up a serial port and changes the settings for some uncommon feature (e.g. XOnOff). If you don't set it back on your initialization phase
you'll never be able to get a working connection!
Update
Listening to all the available ports is quite easy:
First you need a list of all com ports.
Then you create for each one a own thread (or backgroundworker)
And each thread handles its given SerialPort
That's it.
Serial communication doesn't have anything compared to that of IP which has an address and port sent with every packet. The only data that is sent over a serial cable is the bytes you send yourself.
If you control both ends you can send the port number as a part of your own protocol.