Click here to Skip to main content
12,820,038 members (25,414 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
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.
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 24-Aug-12 20:22pm
Updated 24-Aug-12 20:29pm
Mehdi Gholam333.7K
v3
Comments
   
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Your code (if you look at the commented out bits as well) is confused:
'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.
  Permalink  

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

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 25 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100