Hello!
I'm running Visual Basic 2012
I'm having a certain amount of sucess controlling my serial port but now I've hit a wall. - Public com3 As New SerialPort("COM3", 9600, Parity.None, 8, StopBits.One)
-
-
Public Hexe As Integer = Hex(100)
-
-
Public Sub New()
-
InitializeComponent()
-
For Each sp As String In My.Computer.Ports.SerialPortNames
-
ListBox1.Items.Add(sp)
-
Next
-
If com3.IsOpen = False Then
-
com3.Open()
-
End If
-
-
Dim Absolut() As Byte = {1, 4, 0, 0, 0, 0, 0, Int in Hex (&H format), Int in Hex + 5 (control bit)}
-
com3.Write(Absolut, 0, Absolut.Length)
-
End Sub
-
As you can see I need either the whole byte in hex or just parts of it, problem is that Hex(Int) gives it as a string instead of the &H?? format I need. I can't find any solution on MSDN.
Am I just not seeing the obvious?
Best Regards
SciCat
EDIT: The code is incomplete, I didn't want to dump a 100+ line blob, the code works in its entirety.
1 3557
I have managed to solve the conversion problem using Bitshift in the byte itself using an integer: - Public Class Form1
-
Public com3 As New SerialPort("COM3", 9600, Parity.None, 8, StopBits.One)
-
-
Public Sub SendCMD(Adress As Byte, Command As Byte, Type As Byte, Motor As Byte, Value As Integer)
-
Dim TxBuffer() As Byte
-
Dim i As Integer
-
-
TxBuffer = {Adress, Command, Type, Motor, Value >> 24, Value >> 16, Value >> 8, Value & &HFF, 0}
-
For i = 0 To 7
-
TxBuffer(8) = TxBuffer(8) + TxBuffer(i)
-
Next
-
com3.Write(TxBuffer, 0, 9)
-
-
-
End Sub
-
-
-
Public Sub New()
-
InitializeComponent()
-
For Each sp As String In My.Computer.Ports.SerialPortNames
-
ListBox1.Items.Add(sp)
-
Next
-
If com3.IsOpen = False Then
-
com3.Open()
-
End If
-
SendCMD(1, 1, 0, 0, 1)
-
Tid.Enabled = True
-
-
End Sub
-
-
Private Sub Tid_Tick(sender As Object, e As EventArgs) Handles Tid.Tick
-
SendCMD(1, 3, 0, 0, 1)
-
End Sub
But when I run the code I get an arithmetic overflow, did i do something wrong?
EDIT: Everything works! Keeping it here for future reference.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dave |
last post by:
We are writing some code to interface to a DLL. The DLL
has a callback method that returns the address of a byte
buffer and the buffer length. I have defined the byte
pointer as an IntPtr.
...
|
by: kevinniu |
last post by:
Hi everyone,
In c#, what is the fastest way(include unsafe) to
convert a array of bytes(which really contains the
bytes of a double array) to a arry of double.
thanks
|
by: Ricardo Quintanilla |
last post by:
i have a code that sends data to a socket listening over as400 platform,
the socket responds to me as a "byte array".
then i need to convert the "byte array" into a string.
the problem is that...
|
by: Kueishiong Tu |
last post by:
How do I convert a Byte array (unsigned char managed) to a
char array(unmanaged) with wide character taken into
account?
|
by: antonio matos |
last post by:
hi people.
I have to acess a database, and there are some fields that
are binary. when i acess that field is read like an array
of bytes.
but in reality it's an array of doubles!!!
how can...
|
by: Jaime Stuardo |
last post by:
Hi all...
I'm trying to retrieve a SQLXML query using VB.NET. When I programmed in VB
6.0, I used Stream object to accomplish this which was trivial.
I cannot do the same thing in VB.NET. Here...
|
by: Jim Rasmussen |
last post by:
I need some help in converting a byte array to pdf. Could someone give me an example of how in C#? Here is what I have so far,
using System.IO;
string sFile = "c:\testpdf.pdf";
FileStream fs =...
|
by: Star |
last post by:
Hi all,
Let's suppose we have this:
byte buffer = new byte;
buffer = 0x04;
buffer = 0xF1;
buffer = 0xB4;
|
by: dpsairam |
last post by:
Hi,
How to convert a byte array to image....i mean i have to convert a Byte array into image format.....please hellp.........i need the java code...
Thanking You.
|
by: phpuser123 |
last post by:
I want to convert my object to byte array and then next to an object and run a method..The codes are below:
public class test_serialisation implements Serializable{
/**
*
*/
private...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |