serial port communication
-
hi i am working on serial port communication,i have opened the port using CreateFile function ,wrote the data using WriteFile function,and Read data using ReadFile Function.Every thing is fine until here,Say for Example..the instrument is switched off..but connected to the port..how do detect whether the instrument is switched ON or OFF...? thanks in before James
-
hi i am working on serial port communication,i have opened the port using CreateFile function ,wrote the data using WriteFile function,and Read data using ReadFile Function.Every thing is fine until here,Say for Example..the instrument is switched off..but connected to the port..how do detect whether the instrument is switched ON or OFF...? thanks in before James
You should check the documentation of your instrument. Maybe when switched ON, there is one line that is set to high (I think it is the DTR - Data Terminal Ready). If this is the case, just check for the status of this line. Otherwise you can always send something to which the instrument is supposed to respond. If you don't get an answer, then the device is either not connected, either switched OFF. I don't think it is possible to make a difference between disconnected and switched off.
Cédric Moonen Software developer
Charting control [Updated - v1.1] -
You should check the documentation of your instrument. Maybe when switched ON, there is one line that is set to high (I think it is the DTR - Data Terminal Ready). If this is the case, just check for the status of this line. Otherwise you can always send something to which the instrument is supposed to respond. If you don't get an answer, then the device is either not connected, either switched OFF. I don't think it is possible to make a difference between disconnected and switched off.
Cédric Moonen Software developer
Charting control [Updated - v1.1]how to check DTR..is there any API fucntion for it..?
-
how to check DTR..is there any API fucntion for it..?
I think you can use GetCommModemStatus[^]. I think I was wrong, you have to check for the DSR (Data Set Ready) line, not the DSR (I always mix them).
Cédric Moonen Software developer
Charting control [Updated - v1.1] -
I think you can use GetCommModemStatus[^]. I think I was wrong, you have to check for the DSR (Data Set Ready) line, not the DSR (I always mix them).
Cédric Moonen Software developer
Charting control [Updated - v1.1]Is there any other alternative..?..i have tried used GetCommModemStatus function..its returning false..even if..the instrument is switched on..
-
Is there any other alternative..?..i have tried used GetCommModemStatus function..its returning false..even if..the instrument is switched on..
Did you pass the correct handle ? After the port has been opened ?
RockyJames wrote:
Is there any other alternative..?..
Yes, as I said previously: send something to which your device is supposed to answer. If you don't receive an answer, then the device is not connected or switched off.
Cédric Moonen Software developer
Charting control [Updated - v1.1] -
Did you pass the correct handle ? After the port has been opened ?
RockyJames wrote:
Is there any other alternative..?..
Yes, as I said previously: send something to which your device is supposed to answer. If you don't receive an answer, then the device is not connected or switched off.
Cédric Moonen Software developer
Charting control [Updated - v1.1]yeah i have sent..correct handle..i have opened port it in OVERLAPPED MODE..i am using WaitForSingleObject function..when i write data ..its able to write..when i start reading the data..it is getting stucked..at WaitForSingleObject function..
-
hi i am working on serial port communication,i have opened the port using CreateFile function ,wrote the data using WriteFile function,and Read data using ReadFile Function.Every thing is fine until here,Say for Example..the instrument is switched off..but connected to the port..how do detect whether the instrument is switched ON or OFF...? thanks in before James
As Cedric Moonen already said, you can check the DSR signal. In addition you should raise the RTS (Request To Send) signal and check for the reply from the device, CTS (Clear To Send). If you get a transition from Off to On in the CTS line, you can be pretty sure the device is powered on. For the serial communication, i suggest you use a serial commuinications library, the are some good ones here at CP.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
-
As Cedric Moonen already said, you can check the DSR signal. In addition you should raise the RTS (Request To Send) signal and check for the reply from the device, CTS (Clear To Send). If you get a transition from Off to On in the CTS line, you can be pretty sure the device is powered on. For the serial communication, i suggest you use a serial commuinications library, the are some good ones here at CP.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
hi friend ,can u be more clear.. before ReadFile..i want to know whether system is ON or OFF..can u pls suggest..me the function names to use.. thanks in before James
-
Did you pass the correct handle ? After the port has been opened ?
RockyJames wrote:
Is there any other alternative..?..
Yes, as I said previously: send something to which your device is supposed to answer. If you don't receive an answer, then the device is not connected or switched off.
Cédric Moonen Software developer
Charting control [Updated - v1.1]thank`s for u r support..issuse is closed..i have done..with the commtimeout....
-
As Cedric Moonen already said, you can check the DSR signal. In addition you should raise the RTS (Request To Send) signal and check for the reply from the device, CTS (Clear To Send). If you get a transition from Off to On in the CTS line, you can be pretty sure the device is powered on. For the serial communication, i suggest you use a serial commuinications library, the are some good ones here at CP.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
thank`s for u r support..issuse is closed..i have done..with the commtimeout....
-
hi friend ,can u be more clear.. before ReadFile..i want to know whether system is ON or OFF..can u pls suggest..me the function names to use.. thanks in before James
Hello. The problem with detecting serial devices is that the serial port very often can have a random status when the serial port is unconnected. I.e. the DSR signal can be in it's "On"-position even when the serial port isn't even connected! (It depends on the hardware). The only reliable way of detecting if: 1. There *is* a device conncted. 2. The device is powered on. is to catch a transition on one (or more) status lines. An easy way is to ask the device if the PC (Data Terminal) may send data to the DS (Data Set). If the DS raises it's Clear To Send signal, then the PC(DT) may send data to it. Check out MSDN for the documentation, http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/dcb_str.asp[^]
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson