SerialPort object does not receive any data under Windows XP - c#

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.

Related

How to control a Bluetooth LE connection on Windows 10?

I need to develop an application which communicates with a device via bluetooth low energy. Once the application is connected to the device via bluetooth it receives and sends data by using a gatt service.
The application needs to run on a Windows 10 environment. So far I was able to develop and try the application by using the following UWP classes:
DeviceWatcher
BluetoothLEDevice
Once the device has been discovered and paired the communication starts. The main problem I have is that I am not able to control the connection/disconnection with the device, that is the connection starts automatically once the device has been properly and previously paired, but I haven't found any connect()/disconnect() method so far.
Is there a way to control the connection with a specific bluetooth LE device? Are there other APIs which allow to use the bluetooth without using the UWP framework and which offer more control over the bluetooth?
Once the device is paired, whenever it turns on close to the Windows 10 machine, it will try to connect. This is defined behavior in Bluetooth, as the peripheral will always send out a connection request when it is turned on.
There is a DeviceWatcher background task that you can register for to trigger your app when your Bluetooth device connects. You can find some sample code here.
Is there a way to control the connection with a specific bluetooth LE device?
Yes. To initiate a connection: when you create a BluetoothLEDevice via FromBluetoothAddressAsync or FromIdAsync the system will try to initiate a connection to that peripheral, if it does not already hold a connection.
// Connects to a Bluetooth device, given some string deviceId
BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync(deviceId);
To dispose of a connection, call the close method on BluetoothLEDevice. If your app is the only entity with a handle to the peripheral, this will cause the system to disconnect. However, if another app or system service has a handle to the peripheral, the connection will not be closed.
// Will disconnect from the BTLE device, if you hold the only handle
bleDevice.close()
These are taken from the BluetoothLEDevice documentation here.
Are there other APIs?
There are not any other APIs built in to Windows 10 that offer more control over Bluetooth. The UWP APIs offer the most control that Windows 10 currently provides. You could use an alternate Bluetooth stack, but these would have to be installed separately and likely break other Bluetooth behavior on Windows 10.

Sending string to another computer through serial port

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.

How data is sent to a serial port which is being connected by a program

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.

Serial port does not receive data

first of all sorry for my english :)
I have a PCI serial ports card with 2 COM ports. I am using it to receive data from another computer via serial cables. (That other computer will be named as "Sender" subsequently)
The problem is, when cables are plugged in to my computer and i reboot (Windows 7),(Sender is still running...), then my PC does not receive any data. But when i reboot and after that I connect the cables in my PC it starts to receive. I temporary solved it by firstly starting my PC and then the Sender PC, but it's really a terrible solution...
I tried to connect my PC with a different computer (different sender), and it works good.
So I think that the problem can be with my main Sender. Maybe it is waiting for some signal from my computer that the ports are ready? Or Windows 7 can block my serial ports card (standard COM1 which is not on that card works fine) during reboot? Maybe I have to manually send some signal to Sender that I'm ready? By the way, I cannot, in any way, make adjustments to the Sender PC; only turn it on or off.
I do not have any expertise on serial ports so I really don't know what to do, or what I'm currently doing wrong.
Any ideas? (my receiver application is programmed in C#)
UPDATE: I forgot to mention that when the cables are connected... reboot... then ports can't be even opened.
This is a problem caused by the handshake signals. The Sender's DSR (Data Set Ready) is wired to your DTR (Data Terminal Ready). It will see the signal turn off when you reboot, now it gets sulky about sending anything because it thinks that you are no longer connected. You can exacerbate this problem by not setting the SerialPort.DtrEnable to true in your program, that's very commonly overlooked.
Same story with the RTS and CTS signals, if you set the SerialPort.Handshake property to anything else than Handshake.RequestToSend (the recommended value) then it now becomes your job to control the signal. You must set the RtsEnable property to true explicitly in your code.
It tends to work by accident, you're apt to use another program to test the connection. Like HyperTerminal or Putty, they'll turn the signals on for you and your program will now operate correctly.
This kind of bug could of course also exist in Sender. If you can't fix that code then all you can do is rewire the cable. Connect RTS to DSR and CTS on the Sender side to it will always see the signals turned on.
Problem was in card... I changed for new one and now its working correctly. Looks like the card was too old for Windows 7.

C#.NET Serial port access from web application

I have a C#.NET web app that runs in IIS 7 on Server 2008 R2, .NET v4, MVC 3, SQL Server 2012. The app works on a bunch of machines already, but we've just got a new computer and the behaviour on this machine is slightly different.
In particular, when the app opens the System.IO.Ports.SerialPort and writes, no data is actually transmitted on COM1. No exception seems to be thrown either. The app goes on to wait for a response, and times out.
If I close my app, and use Termite (a terminal program) to check that the COM port is working, data comes out the serial port just fine. So the serial port, drivers, etc seem to be ok.
If I have Termite connected to COM1 when my app tries to open the port, I get an Access Denied exception (as I expect). So my application does seem to be trying to access the correct port.
But if there's nothing else using COM1, my application gets no exceptions - but nothing comes out the serial port.
Does anyone have any suggestions about how to debug this situation?
I had the same problem - C# SerialPort couldn't connect to my serial device but Termite could despite following the device manual.
I compared the SerialPort properties with my Termite settings and found that there's some terminology difference between the two. For example, Termite has an option for "DTR/DTS" (which I needed) while SerialPort doesn't have anything called "DTS". Setting these properties of the SerialPort object worked for me:
DtrEnable = true;
RtsEnable = true;

Categories

Resources