Link to home
Start Free TrialLog in
Avatar of Adam_930
Adam_930

asked on

VB.NET Hex constants

I am converting a VB6 application to VB.NET 2013
I am sending data to a VideoJet 1620 printer and it uses control characters for it's setup.
My VB6 application has been working for years without any problems.
I ran the VB6 application through the converter to go fom VB6 to VB.NET.
I went through the VB6 => VB 2008 => VB 2010 => VB 2013 steps
I think what has happened is that the declared variables have changed data types.

ORIG VB6 FORMAT:
    Public Const VJ_Init_RS232 = &H0 '0
    Public Const VJ_Clear_Buffers = &H1 '1
    Public Const VJ_Enable_Reports = &H4 '4
    Public Const VJ_Disable_Reports = &H5 '5
    Public Const VJ_Config_Reprots = &H6 '6

The converter changed it to:
    Public Const VJ_Init_RS232 As Integer = &H0 '0
    Public Const VJ_Clear_Buffers As Integer = &H1 '1
    Public Const VJ_Enable_Reports As Integer = &H4 '4
    Public Const VJ_Disable_Reports As Integer = &H5 '5
    Public Const VJ_Config_Reprots As Integer = &H6 '6

How can I make sure these are declared properly and what is an example of proper way of declaring the constants?
Avatar of it_saige
it_saige
Flag of United States of America image

You could try changing Integer to Byte.


>>what is an example of proper way of declaring the constants?
If the above suggestion doesn't work then look up in the printer documentation what that suggests as the data type.
Avatar of louisfr
louisfr

The VB6 Integer datatype is 16 bits. The equivalent VB.NET datatype is Short.
Avatar of Adam_930

ASKER

I have tried inserting a breakpoint and checking the ASC value of the characters I am sending
I have tried it as Hex (&H), as decimal equivalent, and defining some variables as Short, As Integer, As Long, As Byte

        message = Chr(&H1B) & Chr(&H4) & Chr(&H3) ' Global command for 16 high
        '        message = Chr(27) & Chr(4) & Chr(3) ' Global command for 16 high
        '        message = Chr(VJ_Activate_Print_Delay) & Chr(VJ_5X7_Twin) & Chr(VJ_10X16_Single)
        ComPort.Write(message)

They return an ASC value of [27] [4] [3] in all three cases
Is there something maybe I should be doing different in the serial port command?
I am using the VB.NET serial port, instead of the VB6 MSComm
SOLUTION
Avatar of ChloesDad
ChloesDad
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
(&H1B) = 27 decimal (binary 11011) which is the escape key.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ChloesDad - Thanks I will download and see what it tells me.

David - This is the command that was in the original VB6. It is commands used in the InkJet printer as specified from the mfg.

Andy - Thanks, No I was not aware of this, I am new to .NET I will go down this avenue next.

Louis - yes it is type System.IO.Ports.SerialPort
Thanks for all your comments.
I found that VB.NET does not allow the extended char (Char > 127) to be transmitted as characters
So my string:      message = Chr(&H1B) & Chr(&H81) & Chr(&H7) & Chr(&H1B)  & Chr(&H85) & Chr(&H3C) & msgstr2D.....

the &H81 and &H85 were both actually being transmitted as &H3F (decimal 63 which is the "?")
found this by searching internet for "VB.NET ascii 127 rs232"

The solution to the portion that was giving me the trouble was to send the characters as Bytes

So I ended up with

Dim Buffer(99) As Byte

Buffer(10) = &H1B
Buffer(11) = &H81
Buffer(12) = &H7
Buffer(13) = &H1B
Buffer(14) = &H85
Buffer(15)  = &H3C
ComPort.Write(Buffer, 10, 6)

message = msgstr2D
ComPort.Write(message)