Click here to Skip to main content
15,885,936 members
Home / Discussions / C#
   

C#

 
AnswerRe: Determining the Data Type of a Generic Pin
kevinnicol21-Sep-10 7:16
kevinnicol21-Sep-10 7:16 
AnswerRe: Determining the Data Type of a Generic Pin
Ian Shlasko21-Sep-10 7:16
Ian Shlasko21-Sep-10 7:16 
AnswerRe: Determining the Data Type of a Generic Pin
AspDotNetDev21-Sep-10 11:34
protectorAspDotNetDev21-Sep-10 11:34 
AnswerRe: Determining the Data Type of a Generic Pin
phil.o22-Sep-10 3:44
professionalphil.o22-Sep-10 3:44 
QuestionHow to take data from USB-based device using C# ?? Pin
depressedguy21-Sep-10 6:51
depressedguy21-Sep-10 6:51 
AnswerRe: How to take data from USB-based device using C# ?? Pin
Richard Andrew x6421-Sep-10 15:53
professionalRichard Andrew x6421-Sep-10 15:53 
GeneralRe: How to take data from USB-based device using C# ?? Pin
depressedguy21-Sep-10 16:58
depressedguy21-Sep-10 16:58 
GeneralC# and Ring indicator Pin
MarkBng21-Sep-10 5:27
MarkBng21-Sep-10 5:27 
Hi,

For a project I am using System.IO.Ports.SerialPort for serial port communication. The serialport class can detect the status of DSR (serialPort.DsrHolding), CTS (serialPort.CtsHolding) and CD (serialPort.CDHolding), but it isn't possible to determine the status of the ring indicator (only RI change can be detected).
I made a work around, so you can still keep using the normal SerialPort functions, but you can also detect the RI status. I have only tested it on Vista x86 and VS2010.

Kind regards,
Mark

using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
using System.Reflection;

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern Boolean GetCommModemStatus(SafeFileHandle hFile, ref UInt32 Status);

        const UInt32 MS_CTS_ON = 0x0010;
        const UInt32 MS_DSR_ON = 0x0020;
        const UInt32 MS_RING_ON = 0x0040;
        const UInt32 MS_RLSD_ON = 0x0080;

        private void ShowPinStates(System.IO.Ports.SerialPort serialPort)
        {
            UInt32 Status = 0;
            Boolean CTS = false;
            Boolean DSR = false;
            Boolean DCD = false;
            Boolean RI  = false;

            if (serialPort == null) return;
            if (serialPort.IsOpen)
            {
                object baseStream = serialPort.BaseStream;
                Type baseStreamType = baseStream.GetType();

                // Get the Win32 file handle for the port
                SafeFileHandle portFileHandle = (SafeFileHandle)baseStreamType.GetField("_handle", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(baseStream);

                if (GetCommModemStatus(portFileHandle, ref Status))
                {
                    CTS = ((Status & MS_CTS_ON) == MS_CTS_ON);
                    DSR = ((Status & MS_DSR_ON) == MS_DSR_ON));
                    DCD = ((Status & MS_RLSD_ON) == MS_RLSD_ON));
                    RI  = ((Status & MS_RING_ON) == MS_RING_ON));
                    //Do something with the detected signals
                }
            }
        }

GeneralRe: C# and Ring indicator Pin
Luc Pattyn21-Sep-10 5:41
sitebuilderLuc Pattyn21-Sep-10 5:41 
QuestionUDP Packet Synchronization Pin
softwarejaeger21-Sep-10 3:42
softwarejaeger21-Sep-10 3:42 
AnswerRe: UDP Packet Synchronization Pin
Dave Kreskowiak21-Sep-10 6:41
mveDave Kreskowiak21-Sep-10 6:41 
Questionhow can i use diffrence neuron count in difference layer Pin
karayel_kara21-Sep-10 3:22
karayel_kara21-Sep-10 3:22 
AnswerRe: how can i use diffrence neuron count in difference layer Pin
Alan Balkany21-Sep-10 3:59
Alan Balkany21-Sep-10 3:59 
GeneralRe: how can i use diffrence neuron count in difference layer Pin
karayel_kara21-Sep-10 4:16
karayel_kara21-Sep-10 4:16 
GeneralRe: how can i use diffrence neuron count in difference layer Pin
Alan Balkany21-Sep-10 4:28
Alan Balkany21-Sep-10 4:28 
GeneralRe: how can i use diffrence neuron count in difference layer Pin
Alan Balkany21-Sep-10 4:32
Alan Balkany21-Sep-10 4:32 
AnswerRe: how can i use diffrence neuron count in difference layer Pin
Henry Minute21-Sep-10 4:31
Henry Minute21-Sep-10 4:31 
GeneralRe: how can i use diffrence neuron count in difference layer Pin
harold aptroot21-Sep-10 5:13
harold aptroot21-Sep-10 5:13 
QuestionExtensions Property Pin
reza assar21-Sep-10 3:22
reza assar21-Sep-10 3:22 
AnswerRe: Extensions Property Pin
Dave Kreskowiak21-Sep-10 3:33
mveDave Kreskowiak21-Sep-10 3:33 
GeneralRe: Extensions Property Pin
reza assar21-Sep-10 18:24
reza assar21-Sep-10 18:24 
GeneralRe: Extensions Property Pin
Dave Kreskowiak21-Sep-10 19:26
mveDave Kreskowiak21-Sep-10 19:26 
QuestionList view problem Pin
annie_bel21-Sep-10 3:16
annie_bel21-Sep-10 3:16 
AnswerMessage Closed Pin
21-Sep-10 3:36
stancrm21-Sep-10 3:36 
GeneralRe: List view problem Pin
annie_bel21-Sep-10 3:47
annie_bel21-Sep-10 3:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.