473,387 Members | 1,483 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,387 software developers and data experts.

sending binary data from serial port by visual c++

hello everyone, I am a new member. For my project I have to send binary data (like 10001110) to the db9 rs232 port. I use visual c++ 6.0. I found some codes but they could not work properly. Can anyone give me a c++ code for this problem? Thank you...
Feb 27 '07 #1
5 10977
horace1
1,510 Expert 1GB
hello everyone, I am a new member. For my project I have to send binary data (like 10001110) to the db9 rs232 port. I use visual c++ 6.0. I found some codes but they could not work properly. Can anyone give me a c++ code for this problem? Thank you...
what is the problem? do you have functions to read/write the serial ports? are they not working correctly? don't you get anything tranbsmitted when you send data?
have a look at
http://www.thescripts.com/forum/thread608179.html
Feb 27 '07 #2
Expand|Select|Wrap|Line Numbers
  1. #define STRICT
  2. #include <tchar.h>
  3. #include <windows.h>
  4. #include "Serial.h"
  5.  
  6. int WINAPI _tWinMain
  7.           (
  8.            HINSTANCE /*hInst*/, 
  9.            HINSTANCE /*hInstPrev*/, 
  10.            LPTSTR    /*lptszCmdLine*/, 
  11.            int       /*nCmdShow*/
  12.           )
  13. {
  14.     CSerial serial;
  15.  
  16.     // Attempt to open the serial port (COM1)
  17.     serial.Open(_T("COM1"));
  18.  
  19.     // Setup the serial port (9600,N81) using hardware handshaking
  20.     serial.Setup(CSerial::EBaud9600,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);
  21.     serial.SetupHandshaking(CSerial::EHandshakeHardware);
  22.  
  23.     // The serial port is now ready and we can send/receive data. If
  24.     // the following call blocks, then the other side doesn't support
  25.     // hardware handshaking.
  26.     serial.Write("Hello world");
  27.  
  28.     // Close the port again
  29.     serial.Close();
  30.     return 0;
  31. }

I have used this code and it says "Just call the Write method and supply a string. The Write routine will detect how long the string is and send these bytes across the cable."
But program give some errors while building the exe file.
Feb 27 '07 #3
horace1
1,510 Expert 1GB
the HelloWorld.cpp program from
http://www.codeproject.com/system/serial.asp
compiles and links OK for me - when you linked did you include the serial.cpp file?

to run it I switched off hardware handshaking then it transmitted "hello world" to a another PC via the serial port at 9600 baud
Feb 27 '07 #4
Expand|Select|Wrap|Line Numbers
  1. #define STRICT
  2. #include <tchar.h>
  3. #include <windows.h>
  4. #include "Serial.h"
  5.  
  6. int WINAPI _tWinMain
  7.           (
  8.            HINSTANCE /*hInst*/, 
  9.            HINSTANCE /*hInstPrev*/, 
  10.            LPTSTR    /*lptszCmdLine*/, 
  11.            int       /*nCmdShow*/
  12.           )
  13. {
  14.     CSerial serial;
  15.  
  16.     // Attempt to open the serial port (COM1)
  17.     serial.Open(_T("COM1"));
  18.  
  19.     // Setup the serial port (9600,N81) using hardware handshaking
  20.     serial.Setup(CSerial::EBaud9600,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);
  21.     serial.SetupHandshaking(CSerial::EHandshakeHardware);
  22.  
  23.     // The serial port is now ready and we can send/receive data. If
  24.     // the following call blocks, then the other side doesn't support
  25.     // hardware handshaking.
  26.     serial.Write("Hello world");
  27.  
  28.     // Close the port again
  29.     serial.Close();
  30.     return 0;
  31. }

I have used this code and it says "Just call the Write method and supply a string. The Write routine will detect how long the string is and send these bytes across the cable."
But program give some errors while building the exe file.

hello can you just send the serial.h code used in ur programming
Jun 28 '07 #5
hello i am writting the code in vc++ to send data to serial port,i am the begginer of this,can anybody help me to write code
Jun 28 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: coder_1024 | last post by:
I'm trying to send a packet of binary data to a UDP server. If I send a text string, it works fine. If I attempt to send binary data, it sends a UDP packet with 0 bytes of data (just the...
5
by: gof | last post by:
I'm pretty new to C++, and this seemingly simple thing is driving me crazy. I'm trying to write a CGI script to serve images on the fly. CGI requires the content to be sent through standard...
1
by: Pravin Prabhu | last post by:
Hi, How can i send binary data over a network using winsock. I dont want to use a char array as the binary data has a lot of 'NUL' characters in it which causes problems when i receive data using...
4
by: Schwarty | last post by:
I hope I posted this to the correct group. If not, please let me know and I will get it posted in the correct section. I have a web application developed in ASP.NET using C# for the code behind....
9
by: thorley | last post by:
Greetings, since there was no reponse to my previous post about an existing FastCGI server in python, I've taken to writing my own. (which of course I'll share--*if* there's something to share ;) ...
1
by: John Graham | last post by:
I'm using a transferText command on a Query that is joining several tables and pulling data off of a form.  However all the fields from the form are coming across as what I believe is Binary...
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...
5
by: jen786 | last post by:
Hello every one , This is my first message on fourm ....looking forward to reply This is regarding serial port in visual basic 2008. when i run the following VB program. After 2 minutes it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.