473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Sending a byte over the serial port

I'm trying to send numbers over the serial port as bytes, not strings.
What I mean is if I want to send a 255, that should be 1 byte, not a 2
followed by a 5 and a 5. I'm trying to convert a borland c++ app.

This is what the c++ app does
int8B = 255;
WriteFile(serialPort,&int8B,1,&bytesWritten,NULL);
int8 = gainSlider->Position;
WriteFile(serialPort,&int8,1,&bytesWritten,NULL);
int8 = offsetSlider->Position;
WriteFile(serialPort,&int8,1,&bytesWritten,NULL);
int8 = exposureSlider->Position;
WriteFile(serialPort,&int8,1,&bytesWritten,NULL);
Here is what I'm doing that does not work
int x = 255;
sp.WriteLine(String.Format("{0}", x));
sp.WriteLine(String.Format("{0}", trackBar_Gain.Value));
sp.WriteLine(String.Format("{0}", trackBar_Offset.Value));
sp.WriteLine(String.Format("{0}", trackBar_Exposure.Value));

How do I send the 255? I can't do sp.WriteLine(255) since it wants a
string.
any help will be greatly appreciated.
Ringo

Feb 6 '07 #1
1 4348

"Ringo" <ri*********@gmail.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
I'm trying to send numbers over the serial port as bytes, not strings.
What I mean is if I want to send a 255, that should be 1 byte, not a 2
followed by a 5 and a 5. I'm trying to convert a borland c++ app.

This is what the c++ app does
int8B = 255;
WriteFile(serialPort,&int8B,1,&bytesWritten,NULL);
int8 = gainSlider->Position;
WriteFile(serialPort,&int8,1,&bytesWritten,NULL);
int8 = offsetSlider->Position;
WriteFile(serialPort,&int8,1,&bytesWritten,NULL);
int8 = exposureSlider->Position;
WriteFile(serialPort,&int8,1,&bytesWritten,NULL);
Here is what I'm doing that does not work
int x = 255;
sp.WriteLine(String.Format("{0}", x));
sp.WriteLine(String.Format("{0}", trackBar_Gain.Value));
sp.WriteLine(String.Format("{0}", trackBar_Offset.Value));
sp.WriteLine(String.Format("{0}", trackBar_Exposure.Value));

How do I send the 255? I can't do sp.WriteLine(255) since it wants a
string.
any help will be greatly appreciated.
Isn't there a .Write method that accepts a byte array? That will avoid the
conversion to ASCII text.
Ringo

Feb 7 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Timothy Smith | last post by:
hello people. i've been trying to send an 8 byte string to my parallel port under freebsd. the purpose is it to control a relay board. the board simply responds to the output byte coming from...
19
by: ... | last post by:
Hi I need to send a chr(255) to a serial port. When I send it, through comm.write (chr(255)) it sends a chr(63) ... in Hex, I write chr(&FF) and it actually sends chr(&3F) ... why does this...
1
by: cvschie | last post by:
Hi, I have a LED Sign with standard software to control messages (via serial port). Because the limitations of the software I want my own VB.net program. With a serial analyzer program, I see...
23
by: cmdolcet69 | last post by:
How can i add a 5ms delay between bytes i send over to a controller? I have to send 6 bytes in total however in between each byte i need to have a 5ms delay.
1
by: Rich | last post by:
Hello, I am working on a python library for sending and receiving data from a Subaru's ECU (the fuel injection computer) via the OBD-II port and an OBD to USB cable, with the Subaru Select Monitor...
0
by: Gabriel Genellina | last post by:
En Fri, 02 May 2008 16:50:46 -0300, Rich <richietommy@yahoo.comescribió: No, chr works as it should. The same thing can be written as ser.write("\x80\x10\xF0\x01\xBF\x40") Are you sure you're...
0
by: Charles Crawford | last post by:
Hi, This apparently is a common problem and I've yet to read a solution that actually works for my specific situation. I have a Zebra RW220 printer that I connect to via Bluetooth connection...
0
by: =?Utf-8?B?Q2hhcmxpZQ==?= | last post by:
Hi, This apparently is a common problem and I've yet to read a solution that actually works for my specific situation. I have a Zebra RW220 printer that I connect to via Bluetooth connection...
4
by: ajorge | last post by:
Good Morning! I'm trying to send a few bytes through my serial port into a remote system, but i'm having a problem... Suposing that i'm trying to send the array of bytes: 68, 00, 00, 68, 00,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.