SerialPort open, but receive no response
-
Hello, I am trying to communicate with a Cognex data matrix scanner which is connected to the PC via USB, emulating a COM port. I can open the connection and send commands to the scanner (which is reacting on the commands), but I do not receive any data from the port. For getting started, I used an example from the MSDN (http://msdn.microsoft.com/de-de/library/system.io.ports.serialport.aspx[^]) which I simplified and adjusted for the device:
// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();//Set connection parameters
_serialPort.PortName = "COM4";
_serialPort.BaudRate = 115200;
_serialPort.Parity = Parity.None;
_serialPort.DataBits = 8;
_serialPort.StopBits = StopBits.One;
_serialPort.Handshake = Handshake.None;
_serialPort.NewLine = "\r\n";// Set the read/write timeouts
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;_serialPort.Open();
I also tried to use the DataReceived and the other events - but also no response. I wrote a small C++ app to use the Win32 api directly but no response either. I downloaded several example applications - but still no response. The scanner, however, works with the manufacturer application - I therefore downloaded the trial of "Advanced Serial Port Monitor" to see the communication. Interestingly, with this program I am able to communicate with the device and to receive data as expected - but I don't know what is different... Alex
-
Hello, I am trying to communicate with a Cognex data matrix scanner which is connected to the PC via USB, emulating a COM port. I can open the connection and send commands to the scanner (which is reacting on the commands), but I do not receive any data from the port. For getting started, I used an example from the MSDN (http://msdn.microsoft.com/de-de/library/system.io.ports.serialport.aspx[^]) which I simplified and adjusted for the device:
// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();//Set connection parameters
_serialPort.PortName = "COM4";
_serialPort.BaudRate = 115200;
_serialPort.Parity = Parity.None;
_serialPort.DataBits = 8;
_serialPort.StopBits = StopBits.One;
_serialPort.Handshake = Handshake.None;
_serialPort.NewLine = "\r\n";// Set the read/write timeouts
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;_serialPort.Open();
I also tried to use the DataReceived and the other events - but also no response. I wrote a small C++ app to use the Win32 api directly but no response either. I downloaded several example applications - but still no response. The scanner, however, works with the manufacturer application - I therefore downloaded the trial of "Advanced Serial Port Monitor" to see the communication. Interestingly, with this program I am able to communicate with the device and to receive data as expected - but I don't know what is different... Alex
Had exactly that problem send, but no receive of data with a spectrum analyzer. I found it was due to an incorrectly set HandShake property I had it as none it should have been 1. Much confusion all that had happen was a change from wired 9 way to USB. My advice is to play around with the HandShake, StopBits, Parity & NewLine just to see if that makes any difference. Try copying across the Advance Serial Port Monitor settings to see if that makes a difference. Glenn
-
Had exactly that problem send, but no receive of data with a spectrum analyzer. I found it was due to an incorrectly set HandShake property I had it as none it should have been 1. Much confusion all that had happen was a change from wired 9 way to USB. My advice is to play around with the HandShake, StopBits, Parity & NewLine just to see if that makes any difference. Try copying across the Advance Serial Port Monitor settings to see if that makes a difference. Glenn
Thank you for your answer. The settings are exactly the same as in Advance Serial Port Monitor as well as the manufacturer application. Indeed, it makes no difference if I change any of these settings except for the NewLine string (when I change this setting, the commands are not accepted any more). Perhaps the settings do not play any role because the COM port is only "virtual"? The device is connected to an USB slot, where the communication is handled by windows. However, still no response with SerialPort ... Alex
-
Thank you for your answer. The settings are exactly the same as in Advance Serial Port Monitor as well as the manufacturer application. Indeed, it makes no difference if I change any of these settings except for the NewLine string (when I change this setting, the commands are not accepted any more). Perhaps the settings do not play any role because the COM port is only "virtual"? The device is connected to an USB slot, where the communication is handled by windows. However, still no response with SerialPort ... Alex
There shouldn't be any problem with the device being virtual and interfacing to Visual Studio, my current project is using a Virtual Comm Port, and the FSH3 I referred to was virtual on the USB ( & used Handshaking.None the 9way Dtype used HandShaking.Even). Can I suggest using Jan Axelson's code at www.lvr.com as this I have found does it properly (not that your code is not proper it's just without seeing it...) . It is odd Advanced Serial Port Monitor can send and receive data if it was only the manufactures program I would start to wonder if they had done a trick to prevent others from writing software to interface to it! Glenn
-
There shouldn't be any problem with the device being virtual and interfacing to Visual Studio, my current project is using a Virtual Comm Port, and the FSH3 I referred to was virtual on the USB ( & used Handshaking.None the 9way Dtype used HandShaking.Even). Can I suggest using Jan Axelson's code at www.lvr.com as this I have found does it properly (not that your code is not proper it's just without seeing it...) . It is odd Advanced Serial Port Monitor can send and receive data if it was only the manufactures program I would start to wonder if they had done a trick to prevent others from writing software to interface to it! Glenn
-
I finally found the cause: I have to set
_serialPort.DtrEnable = true;
and it works - I receive the expected data. However, I am still wondering why this is not done in typical other examples? Alex
That's good, now have you done the Happy Dance! as in the "It works, Hurah!!" :-D DTR or Data Terminal Ready some times needs to be set high on RS232 to allow the port that there is data there. Not really used that much these days I have used the DTR & CTS lines to supply power to some (smallish) circuits you can also use them as signal lines as you can control the on / off states via the true / false property (I have used the to control LED's & Relays). Good on you for finding that can I suggest the book Serial Port Complete by Jan Axelson (ISBN 978-1-931448-06-2) as a good reference (her other books are good too!, if you want to start hanging stuff out of your PC!) -=-=-=-=-=-= Also just though if the piece of hardware is a 'modern' version of an older bit of hardware it could be that the software was designed to alter DTR & CTS to send and receive data on the go and when the USB version of the hardware came about it was easier to bodge some thing like setting a pin high on the port than rewrite the software. Glenn