Solved

VB.NET Hex constants

Posted on 2014-12-03
10
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 33

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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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
 
LVL 80

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches viewers about errors in exception handling.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

726 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