Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.NET Hex constants

Posted on 2014-12-03
10
Medium Priority
?
457 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 34

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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 400 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 83

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 1300 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 300 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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

722 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