MSComm input chararcter

John-Boy1

Member
Joined
Mar 6, 2006
Messages
14
Programming Experience
Beginner
Morning everyone,

Im trying to create a remote controlled thermostat programme. At present the server is sent the temperature using IP Sockets. This temperature is displayed in strData on the Server Form.

I think i want to create a select case statement to send a charater to the serial port using the VB Component MS Comm but at present i unsure how to create it without using multiple if statements. How do you code a select case statement?

At present the code in vb is the following

If strData = "#20#" Then
MSComm1.Output = "A"
End If

If strData = "#22#" Then
MSComm1.Output = "S"
End If

If strData = "#24#" Then
MSComm1.Output = "D"
End If

If strData = "#26#" Then
MSComm1.Output = "F"
End If

If strData = "#28#" Then
MSComm1.Output = "G"
End If

If strData = "#28#" Then
MSComm1.Output = "H"
End If

Secondly the device connected to the serial port will send back a "#!#" character when connected.

Im hoping to use images on the server to show whether they are connected or not to the device. A clear circle will be displayed if not connected and a green circle when the system is connect.

How should i do this? Should i use imported jpg's? What code will be needed? is it MSCOmm.input = "#!#"?

This must sound very trivial to some people but im very much a beginner and any assistance will be appreciated.
 
Last edited:
Not real sure on the COM issues, but the select case goes like this:

VB.NET:
        Select Case strData
            Case "#20#"
                MSCOmm1.Ouput = "A"
            Case "#22#"
                MSCOmm1.Ouput = "S"
            Case "#24#"
                MSCOmm1.Ouput = "D"
            Case "#26#"
                MSCOmm1.Ouput = "F"
            Case "#28#"
                MSCOmm1.Ouput = "G"
            Case "#30#"
                MSCOmm1.Ouput = "H"
            Case Else
                MSCOmm1.Ouput = "ERROR"
        End Select
 
Many Thanks David the code works excellent.

Does any one else on the forum know how to code for an MSComm input chararcter.

If MSComm1.Input = "*!*"
Then connectionimage1 = green.jpg
Else
connectionimage1 = clear.jpg
End If


Does this code make sense?

Unfortunately i have been unable to test the code at present so any opinions on the use of inputting characters using MSComm will be very helpful.

Many Thanks
 
Moved to appropriate forum Net/Sockets. Also please give discriptive thread titles. Changed title from "Simple coding issue" to "MSComm input chararcter".
 
Still dont' know about how to determine if you are connected. When you figure that part out you will set a boolean variable to true. You can load pictures like this.

VB.NET:
Dim connection As Boolean = False

'try the connection and determine if it works - set to true.

Dim ImageString As String
If connection = True Then
    ImageString = "C:\green.jpg"
Else
    ImageString = "C:\Red.jpg"
End If
PictureBox1.Image = Image.FromFile(ImageString)
You may want to update the path so your project can be distributed.
 
Back
Top