I'm trying to use a VB.Net Winform to send a string through the COM port to another computer. I have an RS232 COM port on the computer with the application. I then have a Serial to USB adapter that is plugged into the other computer's USB port.
I am using SerialPort from .NET and my application opens the COM port and initializes it. Then when I use mySerialPort.Write(string), the Rx light on the MOXA serial to usb adapter blinks, as if it is receiving the data.
However, if I have notepad open on the computer that's receiving the data, nothing prints out.
Essentially, what I'm trying to do is have the user push a button that will send a barcode (as a string) to the other computer. But I can't figure out how to get the other computer to read the string and print it to notepad or whatever textfield has focus.
I'm limited on what I can install on the receiving computer because it runs Unix.
Related
I'm currently writing a code in C# that would allow the user to read from the usb COM port (I currently have a microcontroller feeding it constant values to the usb port through serial print) and print it to the output of visual studio.
I've been reading up on a lot of documentation, specifically the MS's guide to conecting to USB:
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn312121.aspx#step1
but I'm now finding that the USB device isn't supported.
However, would it be possible to simply read from the Serial port instead of entirely connecting the USB device to the project?
Since it's a Store App, I can't use Serial.IO.Ports
I am wondering that since the serial port can't be used by two programs at the same time, how my barcode reader(hardware device) is able to send data to my computer via serial port, while the port is being opened by my program, and monitored for the newly coming data.
Sure, only one process can open the port. On the other end of it sits the device driver, it actually talks to the hardware.
That hardware is a chip called an UART, Universal Asynchronous Receiver Transmitter. It connects to the wire you use to hook up the device. Any data that comes in through the RxD pin on the connector gets converted to bytes by the UART. The device driver responds to the chip's interrupt and copies the byte(s) from the UART's receive buffer into the driver's receive buffer. Ready to be consumed by a program, it calls ReadFile() to empty the buffer. Today it is often a USB device driver that emulates a serial port.
Serial port communications are very primitive, there is no notion of a logical connection and no agreed-upon protocol to label received data to belong to a specific connection or consumer. Nothing similar to UDP or TCP, the protocols that allows a network connection to be shared. Serial ports site at the very bottom of the OSI model, the physical layer. The driver therefore does not allow more than one program to open the port. It is first-come, first serve.
I have a SerialPort object to control a gsm modem connected to a virtual com port. My problem is that i do not receive any data under Windows XP. The DataReceived Event is not triggered nor outputs port.ReadExisting() any data if called periodically. But when i shut down my program and connect with putty to this port, the response of the modem is displayed.
Under Windows 7 data is received correctly.
What could be the problem here?
Software handshake needs to be enabled.
this.serialPort.Handshake = System.IO.Ports.Handshake.XOnXOff;
I found this out by comparing the putty settings with the serial port settings in my program. So the problem was not the operating system itself, but the used flow control.
I have a device which sends data by com port on my computer.
I know how to simulate it, but the controller must be plugged in to simulate sending data (using Proteus)
Is it possible to simulate the com port sending data without having any external device plugged in?
For example: I want to write a C# program which opens the com port and waits for data, and another c# program which writes data on the same port.
The best way to do this is to use a software COM port emulator. I use com0com :
Null-modem emulator
This provides virtual NM COM port pairs on the system (ie: what is output to one is input to the other and vice-versa). The devices show up in Device Manager just like a real COM port so you interact with them in C# as though they were real hardware devices.
For simplicity's sake, get yourself a com port or null modem emulator. You'll get very far off track, and maybe waste a lot of time, trying to do this yourself.
See this post, too:
Faking an RS232 Serial Port
I have a micro-controller (Arduino) and wish to determine automatically to which port the micro-controller locks to. The idea is not to have to correct the COM port manually for every app on every computer. Can this be done ? Thanks !
Do you mean:
Micro-controller is an external hardware device
User plugs the device into a random serial port (COM port)
You want to know which COM port it's connected to
?
Also, you are talking about an old-style COM port, are you, not a USB?
Anyway if that is your question, the only way would be to:
Open each COM port on the machine and send data through it, to see (if the micro-controller sends back the expected resonse) whether it's talking to the expected device (e.g. if the device were a modem you might try sending "AT\r" and expect a modem to respond "OK", if there is a modem and if the modem is connected to that serial port).
And/or write a device driver or a service to do just this, instead of an application.