Click here to Skip to main content
15,909,242 members
Home / Discussions / C#
   

C#

 
GeneralRe: Stack overflow problem. Pin
Luc Pattyn25-Apr-10 4:05
sitebuilderLuc Pattyn25-Apr-10 4:05 
GeneralRe: Stack overflow problem. Pin
Luc Pattyn25-Apr-10 4:02
sitebuilderLuc Pattyn25-Apr-10 4:02 
AnswerRe: Stack overflow problem. Pin
Luc Pattyn24-Apr-10 1:44
sitebuilderLuc Pattyn24-Apr-10 1:44 
GeneralRe: Stack overflow problem. Pin
spainchaud24-Apr-10 8:05
spainchaud24-Apr-10 8:05 
GeneralRe: Stack overflow problem. Pin
Luc Pattyn25-Apr-10 4:04
sitebuilderLuc Pattyn25-Apr-10 4:04 
GeneralRe: Stack overflow problem. Pin
spainchaud25-Apr-10 18:57
spainchaud25-Apr-10 18:57 
AnswerRe: Stack overflow problem. Pin
spainchaud26-Apr-10 4:42
spainchaud26-Apr-10 4:42 
QuestionGenerating array in foreach loop Pin
mprice21423-Apr-10 18:11
mprice21423-Apr-10 18:11 
Hi all,

Hope someone can point me in the right direction.

I have a foreach loop that is pinging each COM port for a valid device that may be connected. I will eventually put this in a try-catch, but for now I'm just trying to determine how to create an array based upon the loop and then return that array to be used for generating a collection in a list box. Please see the code below: Also, a generic question...can a function return different data types eg. string, double, etc.

private string[] GetSerialDevice()
        {

            // Get a list of serial port names.
            
           
            strPorts = SerialPort.GetPortNames();

                    
            foreach (string strPort in strPorts)
            {
                serialPort1 = new SerialPort(strPort, 115200, Parity.None, 8, StopBits.One);
                serialPort1.Handshake = Handshake.None;
                serialPort1.Close();
                serialPort1.ReadTimeout = 500;
                serialPort1.WriteTimeout = 500;
                serialPort1.Open();
                serialPort1.WriteLine("!001:USR1?\r");
                string strUSR1Return = serialPort1.ReadTo("\r");

                //Console.WriteLine(USR1Return);


                //Each unit will need to have 2.0 written to USR1 for this to work properly
                if (strUSR1Return == "+2.000000")
                {
                    serialPort1.WriteLine("!001:SERL?\r");
                    string strSerialLow = serialPort1.ReadTo("\r");
                    serialPort1.WriteLine("!001:SERH?\r");
                    string strSerialHigh = serialPort1.ReadTo("\r");
                    //SN coding per mfg
                    double dblSerialNumber = double.Parse(strSerialHigh) * 65536 + double.Parse(strSerialLow);
                    Console.WriteLine("On" + " " + strPort + " " + "there is a valid amplifier with S/N "
                        + dblSerialNumber.ToString());
                       
                }//End of if
                
            }//End of foreach

            serialPort1.Close();

            return strPorts;

AnswerRe: Generating array in foreach loop Pin
Khaniya23-Apr-10 18:25
professionalKhaniya23-Apr-10 18:25 
GeneralRe: Generating array in foreach loop Pin
mprice21423-Apr-10 18:52
mprice21423-Apr-10 18:52 
AnswerRe: Generating array in foreach loop Pin
dan!sh 23-Apr-10 18:42
professional dan!sh 23-Apr-10 18:42 
GeneralRe: Generating array in foreach loop Pin
mprice21423-Apr-10 18:53
mprice21423-Apr-10 18:53 
AnswerRe: Generating array in foreach loop Pin
PIEBALDconsult24-Apr-10 4:12
mvePIEBALDconsult24-Apr-10 4:12 
GeneralRe: Generating array in foreach loop Pin
mprice21424-Apr-10 13:27
mprice21424-Apr-10 13:27 
GeneralRe: Generating array in foreach loop Pin
PIEBALDconsult24-Apr-10 17:02
mvePIEBALDconsult24-Apr-10 17:02 
GeneralRe: Generating array in foreach loop Pin
mprice21426-Apr-10 3:41
mprice21426-Apr-10 3:41 
QuestionTrying to Watermark an Image using ffmpeg Pin
harsimranb23-Apr-10 17:05
harsimranb23-Apr-10 17:05 
AnswerRe: Trying to Watermark an Image using ffmpeg Pin
Alan N23-Apr-10 23:42
Alan N23-Apr-10 23:42 
GeneralRe: Trying to Watermark an Image using ffmpeg Pin
jymitra1-Mar-11 6:32
jymitra1-Mar-11 6:32 
Questionfuncions in C# Windows form Pin
joey_go23-Apr-10 15:48
joey_go23-Apr-10 15:48 
AnswerRe: funcions in C# Windows form Pin
AspDotNetDev23-Apr-10 15:57
protectorAspDotNetDev23-Apr-10 15:57 
GeneralRe: funcions in C# Windows form Pin
joey_go23-Apr-10 17:03
joey_go23-Apr-10 17:03 
GeneralRe: funcions in C# Windows form Pin
mprice21423-Apr-10 18:23
mprice21423-Apr-10 18:23 
AnswerRe: funcions in C# Windows form [modified] Pin
DaveyM6923-Apr-10 22:04
professionalDaveyM6923-Apr-10 22:04 
AnswerRe: funcions in C# Windows form Pin
#realJSOP24-Apr-10 0:50
professional#realJSOP24-Apr-10 0:50 

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.