Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Respected sir,

I am trying to send hex command to comport cos of open barrier. My code execute successfully but barrier not open at open button. What can i do??
Following is my code.
VB
Imports MSCommLib
Public Class NewBarrier
    Dim MSComm1 As MSComm

    Private Sub NewBarrier_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MSComm1 = New MSComm
        MSComm1.CommPort = 1
        MSComm1.Settings = "9600,N,8,1"
        MSComm1.DTREnable = True
        MSComm1.RTSEnable = True
        MSComm1.RThreshold = 1
        MSComm1.SThreshold = 0
        MSComm1.PortOpen = True
    End Sub
    
    Public Sub open_barr()
        With MSComm1
            If .PortOpen = False Then .PortOpen = True
            'MSComm1.Output = "0x02";
            'MSComm1.Output = "0x00"
            'MSComm1.Output = "O"
            'MSComm1.Output = "0x00"
            'MSComm1.Output = "0x03"
            'MSComm1.Output = "0x54"

            MSComm1.Output = &H20
            MSComm1.Output = &H0
            MSComm1.Output = &H4F
            MSComm1.Output = &H0
            MSComm1.Output = &H54

            'MSComm1.Output = Chr(&H2)
            'MSComm1.Output = Chr(&H0)
            'MSComm1.Output = Chr(&H4F)
            'MSComm1.Output = Chr(&H0)
            'MSComm1.Output = Chr(&H3)
            'MSComm1.Output = Chr(&H54)

        End With
    End Sub

    End Sub

    Private Sub cmdOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOpen.Click
        Call open_barr()
    End Sub
Posted
Updated 24-Aug-12 19:29pm
v3
Comments
Sergey Alexandrovich Kryukov 25-Aug-12 1:30am    
What is hex command? What is the spec of what you need to send, exactly? Otherwise how one can understand what's wrong and what's correct?
--SA
Avi Mali 25-Aug-12 1:35am    
I want to send following commands to comport or serial port.

MSComm1.Output = &H20
MSComm1.Output = &H0
MSComm1.Output = &H4F
MSComm1.Output = &H0
MSComm1.Output = &H3
MSComm1.Output = &H54

1 solution

Your code (if you look at the commented out bits as well) is confused:
VB
'MSComm1.Output = "0x02";
'MSComm1.Output = "0x00"
'MSComm1.Output = "O"
'MSComm1.Output = "0x00"
'MSComm1.Output = "0x03"
'MSComm1.Output = "0x54"

MSComm1.Output = &H20
MSComm1.Output = &H0
MSComm1.Output = &H4F
MSComm1.Output = &H0
MSComm1.Output = &H54

'MSComm1.Output = Chr(&H2)
'MSComm1.Output = Chr(&H0)
'MSComm1.Output = Chr(&H4F)
'MSComm1.Output = Chr(&H0)
'MSComm1.Output = Chr(&H3)
'MSComm1.Output = Chr(&H54)
Implies that you are not sure what you should be sending: The first one implies a message structure
STX NUL ETX '6'
(the '6' character is probably a check character)
The second implies you just guessed and turned bits round:
SPC NUL 'O' NUL '6'

Your third that you tried throwing some more stuff in at random in the hope it would take pity on you!
STX NUL 'O' NUL ETX '6'


That approach won't work. You need to look at the manual and work out what data it is expecting. I am guessing it is a structured message, starting with STX, ending in ETX and with a check digit of some form (which must be right or the whole message will be ignored) but without knowing how the check digit should be calculated, or what the data in the middle should actually be, I can't help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900