Solved

VB.NET Hex constants

Posted on 2014-12-03
10
366 Views
Last Modified: 2014-12-05
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
Comment
Question by:Adam_930
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 32

Expert Comment

by:it_saige
ID: 40478955
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 40478957
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
 
LVL 11

Expert Comment

by:louisfr
ID: 40479026
The VB6 Integer datatype is 16 bits. The equivalent VB.NET datatype is Short.
0
 

Author Comment

by:Adam_930
ID: 40479196
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
 
LVL 15

Assisted Solution

by:ChloesDad
ChloesDad earned 100 total points
ID: 40479609
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 40479756
(&H1B) = 27 decimal (binary 11011) which is the escape key.
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 325 total points
ID: 40480160
>>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
 
LVL 11

Assisted Solution

by:louisfr
louisfr earned 75 total points
ID: 40480174
Is the ComPort variable's type System.IO.Ports.SerialPort ?
0
 

Author Comment

by:Adam_930
ID: 40480510
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
 

Author Closing Comment

by:Adam_930
ID: 40483249
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to go to Web page 2 51
Re-position sub-options beneath the TAB 7 41
Spell Check in VB6 13 45
Visual Studio editor? 1 16
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
The viewer will learn how to implement Singleton Design Pattern in Java.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now