Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 496
  • Last Modified:

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?
0
Adam_930
Asked:
Adam_930
  • 3
  • 2
  • 2
  • +3
3 Solutions
 
it_saigeDeveloperCommented:
0
 
AndyAinscowCommented:
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.
0
 
louisfrCommented:
The VB6 Integer datatype is 16 bits. The equivalent VB.NET datatype is Short.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Adam_930Author Commented:
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
0
 
ChloesDadCommented:
In these cases I use a piece of softrware from Eltima called Serialportmonitor. It allows you to snoop on the serial port to see the traffic. This should help you verify what you are sending

http://www.eltima.com/products/serial-port-monitor/

The code that you have posted looks OK, the problem could be the setup of the serialport
0
 
David Johnson, CD, MVPOwnerCommented:
(&H1B) = 27 decimal (binary 11011) which is the escape key.
0
 
AndyAinscowCommented:
>>ComPort.Write(message)

What is message ?
If it is a string then I hope you are aware that strings in .net are unicode (wide characters - typically two bytes) whereas in VB6 I suspect they are ascii (narrow characters - one byte).  So something like
Chr(&H1B) & Chr(&H4) & Chr(&H3)
is very likely getting converted to something like
0 Chr(&H1B) 0 Chr(&H4) 0 Chr(&H3)  (I've removed the concatenation to leave a byte representation of the string)
0
 
louisfrCommented:
Is the ComPort variable's type System.IO.Ports.SerialPort ?
0
 
Adam_930Author Commented:
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
0
 
Adam_930Author Commented:
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)
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now